One of my main uses of GreaseMonkey is a simple script to override a "Java 
detection" function embedded in an old device's firmware:
// ==UserScript==
// @name        Fix KVM Java detection
// @namespace   example.com
// @description Override Java plugin detection in APC (Avocent) IP KVMs
// @include     https://kvm1.example.com/*
// @include     https://kvm2.example.com/*
// @version     0.2
// @grant       none
// ==/UserScript==


// override the function defined in connectionslistiframe.js
function IsJavaInstalled() {
  /* unconditionally return "yes":
       The KVM viewer just downloads a JNLP file which is opened with Java 
Web Start.
       Leave having a working 'javaws' up to the user.
  */
  return 1;
}


addJS_Node(IsJavaInstalled);


// http://stackoverflow.com/a/21274652
function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
    var D                                   = document;
    var scriptNode                          = D.createElement ('script');
    if (runOnLoad) {
        scriptNode.addEventListener ("load", runOnLoad, false);
    }
    scriptNode.type                         = "text/javascript";
    if (text)       scriptNode.textContent  = text;
    if (s_URL)      scriptNode.src          = s_URL;
    if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + 
')()';


    var targ = D.getElementsByTagName ('head')[0] || D.body || D.
documentElement;
    targ.appendChild (scriptNode);
}



This script worked in GM 3.x (FF <= 56), and still works in ViolentMonkey 
(FF 57, Chrome) & TamperMonkey (Chrome, Edge). It simply doesn't run in GM 
4.x, and no script-related errors are logged in the console.  (There is one 
error generated by the function I'm attempting to override, thus I'm pretty 
sure the script is not being run.)

I'm not calling any GM_* API stuff, but is there something else here that 
needs changing?  In an older version, I had used @grant unsafeWindow, which 
I know got renamed, but I discovered @grant none worked just as well, so I 
changed to that. (However, not having a @grant line at all did not work.)


Thanks,
Andrew

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to greasemonkey-users+unsubscr...@googlegroups.com.
To post to this group, send email to greasemonkey-users@googlegroups.com.
Visit this group at https://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to