Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Such a script must account for the GM sandbox, and also (usually) allow time for the library to load and initialize.   See <a href="http://commons.oreilly.com/wiki/index.php/Greasemonkey_Hacks/Getting_Started#Avoid_Common_Pitfalls" rel="nofollow">Avoid Common Pitfalls (in Greasemonkey)</a>.</p> <p>So, you would use this library like so:</p> <pre><code>//--- Load the library. var D = document; var appTarg = D.getElementsByTagName ('head')[0] || D.body || D.documentElement; var jsNode = D.createElement ('script'); jsNode.src = 'http://dict.bing.com.cn/cloudwidget/Scripts/Generated/BingTranslate_Selection_ShowIcon.js'; jsNode.addEventListener ("load", initBingTranslatorOnDelay, false); appTarg.appendChild (jsNode); //--- Allow some time for the library to initialize after loading. function initBingTranslatorOnDelay () { setTimeout (initBingTranslator, 666); } //--- Call the library's start-up function, if any. Note needed use of unsafeWindow. function initBingTranslator () { unsafeWindow.BingCW.Init ( { AppID: "GM Foo", MachineTranslation: true, WebDefinition: true } ); } </code></pre> <p><br><br> Issues, some specific to this question:</p> <ol> <li><p><code>onload</code> is not available; See the pitfalls. Event handlers cannot be set this way in GM. Also, <code>addEventListener()</code> is the best practice anyway.</p></li> <li><p>Accessing JS (including libraries we load) in the page scope, requires <code>unsafeWindow</code>.</p></li> <li><p>That app appears to want an <code>AppID</code>.</p></li> <li><p>Sometimes, libraries like this can be loaded in the GM scope instead of the page scope, using the <code>// @require</code> directive.<br> I did not try that with this library, but with others, it may be possible.   Do <strong>not</strong> try this with untrusted libraries, as they gain extra abilities to infect your machine, once inside the GM scope.</p></li> <li><p>Don't use reserved words, like "script", for variable names.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload