-1

如何更改代码中的 var 值。我已经尝试过但没有成功

<script type="text/javascript" charset="utf-8">
var i9 = '071c57';
var plusActive = false;
</script>

对此

<script type="text/javascript" charset="utf-8">
var i9 = '071c57';
var plusActive = true;
</script>

我尝试使用以下代码但不成功

// ==UserScript==
// @name          PLUS 
// @namespace     http://userstyles.org
// @description   PLUS 
// @author        md
// @homepage      http://userstyles.org/styles/43691
// @include       http://azet.sk/*
// @include       https://azet.sk/*
// @include       http://-azet.sk/*
// @include       https://-azet.sk/*
// @include       http://*.azet.sk/*
// @include       https://*.azet.sk/*
// @include       http://*-azet.sk/*
// @include       https://*-azet.sk/*
// ==/UserScript==

myInfo
{
"plusActive":true;
}
4

2 回答 2

0

如果我理解正确,这应该很容易解决。

您可以简单地覆盖变量:

所以更换

myInfo
{
"plusActive":true;
}

plusActive = true;

您不需要运行任何类型的函数,假设在加载页面之前不会读取相关变量(这远非确定)。

于 2013-06-27T23:48:53.990 回答
0

因为plusActive对于目标页面范围(不是脚本范围)是全局的......

适用于 Firefox ,这将起作用:

// ==UserScript==
// @name          PLUS 
// @namespace     http://userstyles.org
// @description   PLUS 
// @author        md
// @homepage      http://userstyles.org/styles/43691
// @include       http://azet.sk/*
// @include       https://azet.sk/*
// @include       http://-azet.sk/*
// @include       https://-azet.sk/*
// @include       http://*.azet.sk/*
// @include       https://*.azet.sk/*
// @include       http://*-azet.sk/*
// @include       https://*-azet.sk/*
// @grant         none
// ==/UserScript==

window.plusActive = true;

对于@grant none此脚本,对于确保始终预期的操作非常重要。


对于跨浏览器方法,使用脚本注入:

// ==UserScript==
// @name          PLUS 
// @namespace     http://userstyles.org
// @description   PLUS 
// @author        md
// @homepage      http://userstyles.org/styles/43691
// @include       http://azet.sk/*
// @include       https://azet.sk/*
// @include       http://-azet.sk/*
// @include       https://-azet.sk/*
// @include       http://*.azet.sk/*
// @include       https://*.azet.sk/*
// @include       http://*-azet.sk/*
// @include       https://*-azet.sk/*
// @grant         GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

addJS_Node ('plusActive = true;');

function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
    var D                                   = document;
    var scriptNode                          = D.createElement ('script');
    if (runOnLoad) {
        scriptNode.addEventListener ("load", runOnLoad, false);
    }
    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);
}
于 2013-06-27T23:51:26.620 回答