Greasemonkey 注入 Adfly 广告

发布于 2024-11-30 03:51:39 字数 382 浏览 1 评论 0原文

有什么办法可以将其转换为 Greasemonkey 代码吗?

<script>
var adfly_id = 517450;
var adfly_advert = 'banner';
var frequency_cap = 5;
var frequency_delay = 5;
var init_delay = 3;
</script>
<script src="http://adf.ly/js/entry.js"></script>

这是 adf.ly 的网站入口脚本,添加到网站后会显示 adf.ly 广告。

我想制作一个脚本,在冲浪时在浏览器中加载 adf.ly 链接。

请帮忙! 谢谢 :)

Is there any way to convert this into Greasemonkey code?

<script>
var adfly_id = 517450;
var adfly_advert = 'banner';
var frequency_cap = 5;
var frequency_delay = 5;
var init_delay = 3;
</script>
<script src="http://adf.ly/js/entry.js"></script>

It's a website entry script for adf.ly which when added to a website brings up adf.ly ads.

I want to make a script that will load adf.ly links in the browser while surfing.

Please help!
Thank You :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀梦 2024-12-07 03:51:39

您需要将 JS 注入到页面中。 尽可能避免 unsafeWindow

以下是该脚本的完整 Greasemonkey 翻译:

// ==UserScript==
// @name            _adFly why?
// @include         http://YOUR_SITE/YOUR_PATH/*
// ==/UserScript==


function myCode () {
    //--- Set global variables for adFly.
    window.adfly_id         = 517450;
    window.adfly_advert     = 'banner';
    window.frequency_cap    = 5;
    window.frequency_delay  = 5;
    window.init_delay       = 3;
}

addJS_Node (null, null, myCode);
addJS_Node (null, "http://adf.ly/js/entry.js");

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    = document.getElementsByTagName('head')[0] || D.body || D.documentElement;
    targ.appendChild (scriptNode);
}

You'll need to inject the JS into the page. Avoid unsafeWindow if you can.

Here's a complete Greasemonkey translation of that script:

// ==UserScript==
// @name            _adFly why?
// @include         http://YOUR_SITE/YOUR_PATH/*
// ==/UserScript==


function myCode () {
    //--- Set global variables for adFly.
    window.adfly_id         = 517450;
    window.adfly_advert     = 'banner';
    window.frequency_cap    = 5;
    window.frequency_delay  = 5;
    window.init_delay       = 3;
}

addJS_Node (null, null, myCode);
addJS_Node (null, "http://adf.ly/js/entry.js");

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    = document.getElementsByTagName('head')[0] || D.body || D.documentElement;
    targ.appendChild (scriptNode);
}
无法回应 2024-12-07 03:51:39

是的,理论上。你只需要将这些写到头部即可。如果您在页面方向加载它们,它们将在greasemonkey范围之外进行评估。您甚至可以在创建脚本标记后执行 document.body.appendChild 。因此,

var sc = document.createElement('script');
sc.src = "http://adf.ly/js/entry.js"
document.body.appendChild(sc);

对于另一个,执行 unsafeWindow.varname 赋值可能会更容易,例如

unsafeWindow.adfly_id = 517450;
unsafeWindow.adfly_advert = 'banner';
unsafeWindow.frequency_cap = 5;
unsafeWindow.frequency_delay = 5;
unsafeWindow.init_delay = 3;

虽然您不想在脚本中使用这些值,因为可以通过以下方式更改这些值:网站本身。使用它们可以让网站更好地控制用户浏览器,并让他们执行原本无法执行的操作(例如,通过 XSS ajax 访问其他网站的信息)。只写入 unsafeWindow 中的值,不要读取其中的值。

Yes, in theory. You'd just need to write these to the head. They will evaluate outside of the greasemonkey scope if you load them on the page direction. you can even just do a document.body.appendChild after creating script tags. So,

var sc = document.createElement('script');
sc.src = "http://adf.ly/js/entry.js"
document.body.appendChild(sc);

For the other one, it'd probably just be easier to do an unsafeWindow.varname assignment like

unsafeWindow.adfly_id = 517450;
unsafeWindow.adfly_advert = 'banner';
unsafeWindow.frequency_cap = 5;
unsafeWindow.frequency_delay = 5;
unsafeWindow.init_delay = 3;

Though you don't ever want to use these values in your script, as these can be changed by the website itself. Using them gives websites access to more control over a users browser and lets them do things that they would not otherwise be able to do (for example, accessing information from other websites via XSS ajax). Only write to values in unsafeWindow, don't read from them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文