Greasemonkey is unable to find/modify/delete content? (on Twitch.tv)

╄→尐↘猪︶ㄣ 提交于 2019-12-02 07:07:47
Brock Adams

That site uses javascript (AJAX) to load the link you are looking for. This means that the link shows up long after your userscript finishes running -- even if you use @run-at document-end.

To get around this use AJAX-aware techniques such as with waitForKeyElements().

Here's a complete script showing how to do this the jQuery + waitForKeyElements way:

// ==UserScript==
// @name     Twitch Delete Test
// @match    *://*.twitch.tv/directory*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant    GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/
waitForKeyElements (
    ".game.item a[title='League of Legends']", deleteContainingNode
);

function deleteContainingNode (jNode) {
    jNode.parent ().parent ().remove ();
}

Tested on this page: http://www.twitch.tv/directory

See the linked answer for more information and more links.

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