Javascript 代码在浏览器控制台中工作,但不在tampermonkey中工作
我正在尝试在上运行以下代码块 var x=document.getElementsByTagName(“a”); 对于(变量i=0;iJavascript 代码在浏览器控制台中工作,但不在tampermonkey中工作,javascript,console,tampermonkey,Javascript,Console,Tampermonkey,我正在尝试在上运行以下代码块 var x=document.getElementsByTagName(“a”); 对于(变量i=0;i
有什么帮助吗?提前感谢。该页面的大部分是动态加载的(AJAX驱动),这意味着您的脚本通常会在您感兴趣的节点出现在页面中/页面上之前很长时间内完成运行 您必须使用AJAX感知技术,如
waitforkyelments
或MutationObserver
下面是一个完整的脚本,演示了该过程:
// ==UserScript==
// @name _Lichess.org, Glorify select users
// @match *://lichess.org/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// @grant GM.getValue
// ==/UserScript==
//- The @grant directives are needed to restore the proper sandbox.
waitForKeyElements ("a[href*='WaisKamal']", spiffifyLink);
function spiffifyLink (jNode) {
var oldHtml = jNode.html ();
var newHtml = '<span class="title" data-title="GM" title="Grandmaster">GM</span> ' + oldHtml;
jNode.html (newHtml);
}
/==UserScript==
//@name\u Lichess.org,荣耀精选用户
//@match*://lichess.org/*
//@需要https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
//@需要https://gist.github.com/raw/2625891/waitForKeyElements.js
//@grant GM_addStyle
//@grant GM.getValue
//==/UserScript==
//-需要@grant指令来恢复适当的沙箱。
WaitForkEyelments(“a[href*='WaisKamal']”,SpifffyLink);
函数spiffifyLink(jNode){
var oldHtml=jNode.html();
var newHtml='GM'+oldHtml;
jNode.html(newHtml);
}
请参阅。什么是
x
??对不起,我错过了,我会更新这个问题。黑板右侧的界面(你想让丢失的“GM”去的地方)不会出现在你发布的链接上,在任何浏览器上-它会显示一个移动列表,所以我无法重现问题。在添加类之前可能会有延迟?我使用的是最新版本的chrome,它运行良好。如果可能的话,我会投十几次票。谢谢!
// ==UserScript==
// @name _Lichess.org, Glorify select users
// @match *://lichess.org/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// @grant GM.getValue
// ==/UserScript==
//- The @grant directives are needed to restore the proper sandbox.
waitForKeyElements ("a[href*='WaisKamal']", spiffifyLink);
function spiffifyLink (jNode) {
var oldHtml = jNode.html ();
var newHtml = '<span class="title" data-title="GM" title="Grandmaster">GM</span> ' + oldHtml;
jNode.html (newHtml);
}