如何使用Greasemonkey绕过javascript函数? [英] How to bypass a javascript function using Greasemonkey?

查看:48
本文介绍了如何使用Greasemonkey绕过javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习如何在Greasemonkey中创建一个脚本来修改页面中的变量或绕过延迟函数。

I want to learn how to make a script in Greasemonkey to modify variables in a page or bypass a delaying function.

这是在中间找到的脚本页面:

Here is the script found in the middle of the page:

<script language="Javascript">
    x300=100;

    function countdown() {
        x300--;
        if (x300 == 0) {
            document.getElementById('countdown').innerHTML =
                '<strong>Proceed to URL - <a href="http://XXXX.com/11123324">click here</a>!</strong>';
        }
        if (x300 > 0) {
            document.getElementById('countdown').innerHTML =
                'You will be redirected in ' + x300 + ' seconds.';
            setTimeout('countdown()',100000);
        }
    }

    countdown();
</script>



当然我想做一个将我重定向到的脚本 http://XXXX.com/11123324
我还是菜鸟,所以我制作的最佳剧本是:


Of course I want to do a script that will redirect me to http://XXXX.com/11123324, I am still noob so the best script I made was:

// ==UserScript==
// @name        aaa
// @include     bbbb
// @grant       none
// ==/UserScript==

x300=1;
countdown()

但不起作用:(

推荐答案

更新:



基于原始问题(现已删除),以及明显的目标页面,变量 x300 和函数倒计时() 全局。但变量名 x300 实际上会在页面之间发生变化。这意味着它不是脚本编写的好选择。

Update:

Based on the original question (now deleted), and the apparent target page, the variable x300 and the function countdown() are global. But the variable name x300 actually changes from page to page. This means that it is not a good choice for scripting.

函数名称倒计时()似乎是不变的。所以,您可以使用正则表达式从函数源中提取所需的链接:

The function name countdown() appears to be constant though. So, you can extract the desired link from the function source using regex:

// ==UserScript==
// @name        aaa
// @include     bbbb
// @grant       none
// ==/UserScript==

var addrFound       = false;
var cntDwnFuncSrc   = window.countdown;  // Use unsafeWindow if grant is not none.
if (cntDwnFuncSrc) {
    cntDwnFuncSrc           = countdown.toString ();
    var payloadAddrMatch    = cntDwnFuncSrc.match (/href="([^"]+?)"/);
    if (payloadAddrMatch  &&  payloadAddrMatch.length > 1) {
        location.assign (payloadAddrMatch[1]);
        addrFound           = true;
    }
}

if ( ! addrFound) {
    alert ("Payload address not found.  Site probably changed");
}












鉴于您的示例页面,您的用户应该有效。它没有,表示您正在省略或更改问题中的关键细节!


  1. 什么你在错误控制台中得到错误( Ctrl Shift J )?

  1. What errors do you get in the error console (CtrlShiftJ)?

在Firefox或Firebug控制台中运行以下代码时会发生什么?

What happens when you run the following code in the Firefox or Firebug console?

console.log (x300);
console.log (countdown);


  • 什么是目标网页的网址,以便我们可以看到实际发生的情况?

  • What is the URL of the target page so that we can see what is really going on?

    这篇关于如何使用Greasemonkey绕过javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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