Greasemonkey (using the waitForKeyElements utility) - how to call a function after a specific element has been displayed on screen

对着背影说爱祢 提交于 2019-12-19 11:20:05

问题


(In continuance to this question of mine).
I've been writing this userscript for the site metal-archives.com.
When opening a band page (example) you land to DISCOGRAPHY>COMPLETE DISCOGRAPHY.
My script applies to that DISCOGRAPHY tab
and it's sub-tabs (COMPLETE DISCOGRAPHY, MAIN, LIVES, DEMOS, MISC) :
it splits the column "Reviews" in two and makes the table sortable.

I want initially (using the waitForKeyElements utility in my script in greasemonkey)
a function (which adds a column to the table, based on it's contents, appendColumn(x) )
to be called after the table inside DISCOGRAPHY > COMPLETE DISCOGRAPHY has been completely displayed (I think this as: after the last header of the table has been displayed).
The id value of the last header of that table (MISC.) is already stored in this array position: myArray[end]


So, my failed tries so far (based on this answer that user Brock Adams kindly suggested in my initial question) are variants of:

function appendColumn(x){....}

function triggerCall(jNode) {   
       appendColumn(0);    or --> jNode.appendColumn(0);   
   }

waitForKeyElements (myArray[end], triggerCall);  // no parentheses after triggerCall

回答1:


Assuming the appendColumn function works, as is, on reloads; then you would rewrite it slightly and call it from waitForKeyElements().

You don't need most of that rigamorole, just use class names display and discog for the selector. Like so:

waitForKeyElements (".display.discog", appendColumn);

function appendColumn(jNode) {
    var tbl = jNode[0]; // table reference
    var i;
    var newCell, newText;    

    var tr = tbl.tHead.children[0],
    th = document.createElement('th');
    // THE REST OF THE FUNCTION IS THE SAME...
    //...


来源:https://stackoverflow.com/questions/26416049/greasemonkey-using-the-waitforkeyelements-utility-how-to-call-a-function-aft

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!