I am using this amazing script, waitForKeyElements() (wfke), which helps dealing with dynamically loaded content in userscripts.
It does a perfect job, but I am having a lot of trouble pre-calculating some variables, and then using that when wfke executes.
Basically, It is correctly running hundreds of times for a list of nodes, that all get loaded right away (after the page is loaded). But I cannot be creating expensive variables and doing expensive calculations for every single item in this list. So I try to do these outside of the wfke function.
As you can see in the following example, I have tried two different ways to pre-set the variable "icons", both do not work. I am guessing this is probably a feature of @require
scripts? Would copy-pasting the script into my main script fix the issue? Would that be the only way?
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
var icons = $('some stuff');
//Run for every BOX element that gets loaded by ajax
waitForKeyElements(".box", main);
function main(jqnode){
if (typeof icons === 'undefined') { //icons is undefined here, and will be again the next time this function is run.
var icons = $('some stuff');
}
jqnode.append(icons);
}
In Chrome, Tampermonkey (beta)