Greasemonkey无法找到/修改/删除内容? (在Twitch.tv上) [英] Greasemonkey is unable to find/modify/delete content? (on Twitch.tv)

查看:120
本文介绍了Greasemonkey无法找到/修改/删除内容? (在Twitch.tv上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从抽搐子页面游戏列表(twitch.tv/directory)中删除各种游戏,但我无处可去。

I'm trying to remove various games off the twitch sub-page "Game List" (twitch.tv/directory) but I'm getting nowhere.

我已经使用alert,timers和 @ run-at document-end 调试无效,脚本正确到达页面但是一旦我尝试操作内容就没有任何反应。

I've debugged with alert, timers and @run-at document-end to no avail, the script reaches the page correctly but once I try to manipulate content nothing happens.

这是我用来测试它的:

// ==UserScript==
// @name        TwitchDeleteTest
// @namespace   to.be.continued
// @include     http*://*twitch.tv/directory*
// @version     1
// @grant       none
// ==/UserScript==

var rmLoL = document.querySelector("a[title='League of Legends']");
var grandParent = rmLoL.parentNode.parentNode;
grandParent.parentNode.removeChild(grandParent);

为什么脚本不删除这些节点?

Why isn't the script removing those nodes?

推荐答案

该网站使用javascript(AJAX)加载您要查找的链接。这意味着在用户脚本完成运行后很长时间内链接会显示 - 即使您使用 @ run-at document-end

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.

要解决此问题,请使用 AJAX感知技术,例如 waitForKeyElements()

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

这是一个完整的脚本,展示了如何使用jQuery + 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 ();
}

在此页面上测试: http://www.twitch.tv/directory

查看链接的答案以获取更多信息还有更多链接。

See the linked answer for more information and more links.

这篇关于Greasemonkey无法找到/修改/删除内容? (在Twitch.tv上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆