我正在编写一个小用户脚本,以从服务器获取一些内容并将其添加到领带中。
该网站有 jQuery,我怎样才能只使用该网站的 jQuery 而不是 @require
(因为 Chrome 现在不支持此功能)?
最佳答案
使用现有 jQuery 副本,代码如下:
function main () {
/*--- Put all of your code here.
Use jquery with $ or however the target page uses it.
*/
}
function addJS_Node (text, s_URL, funcToRun) {
var D = document;
var scriptNode = D.createElement ('script');
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}
addJS_Node (null, null, main);
关于jquery - 访问目标页面上 jQuery 的现有副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9871019/