How to make the functions added by Tampermonkey available on the console after running the script?

I made a script that among other things there is a function in it:

function updateGUI(){
    document.getElementById("cursoft").value = getSoftware();
    document.getElementById("curver").value = getCurrentVersion();
    document.getElementById("rcycles").value = getResearchCycles();
    document.getElementById("rcycle").value = getCurrentCycle();
    document.getElementById("curproc").value = getCurrentProcess();
    document.getElementById("curact").value = getCurrentAction();
}

The script works on loading the page just fine, but when I try to run this function after the script finishes, it is "undefined".
How can I make it "stay" in the current area?

+4
source share
2 answers

Tampermonkey scripts run in a separate area. This means that in order to make the feature available around the world, you will need to do something as follows:

window.updateGUI = function () {...}

, . , .

var myFunctions = window.myFunctions = {};
myFunctions.updateGUI = function () {...};

myFunctions.updateGUI();.

+6

, . , - .

, script

var scriptElem = document.createElement('script');
scriptElem.innerHTML = 'function updateGui() { /* stuff */ }';
document.body.appendChild(scriptElem);
0

Source: https://habr.com/ru/post/1569229/


All Articles