用于替换目标网页中的代码的脚本

时间:2012-11-26 11:44:39

标签: javascript html greasemonkey

我需要一些Greasemonkey脚本的帮助。我正在尝试替换HTML文档中的某些文本,并从该网站删除javascript函数。

我要重写的表达式是 needCaptcha: trueneedCaptcha: false。我也想删除这部分HTML:

checkConfig = {
    empty : "Enter the characters in the image",
    error : "Type the characters you see"           
},

我使用了这个脚本,但它不起作用:

{
    document.body.innerHTML = document.body.innerHTML.replace('needCaptcha:  true  ', 'needCaptcha:  false');

    document.body.innerHTML = document.body.innerHTML.replace('checkConfig = { 
        empty : "Enter the characters in the image"/, 
        error : "Type the characters you see"'
    },)
}

有什么想法吗?

好的,非常感谢你的回答我更了解我们想要做的事情。但是你的脚本没有用,你可以在这里找到它的网页,只要你可以到达地点订单网页就不容易了。

我认为验证码是在本地检查的,因此我们应该能够使用javascript绕过它。

无论如何,在这里您可以将网站的部分代码作为参考:

script type="text/javascript">
    var placeOrderConfig = {
        rate : "0.95",
        userType : "cnfm",
        editAddressUrl : "mailing_address.htm",
        editAddressUrlNoMember : "mailing_address_no_member.htm" ,
        changeAddressUrl : "change_mailing_address.htm",
        quickZoneUrl : "quickLoginRegister.htm?loginReturn=",
        editAddressWinTitle : "Edit Shipping Address",
        changeAddressWinTitle : "Change Shipping Address",
        addAddressWinTitle : "Add New Shipping Address",
        defaultMessage : "Please enter your message to the supplier here",
        remoteCheckEmailUrl : "$usMyalibabaServer/user/join/CheckEmail.htm",
        noMemberAction : "noMemberResult.htm" ,
        needCheckCode:  true        },
    productData = [[602092306,"wholesaleProduct","promotion_gaga","US","",1,"CPAM","14%3A173%23blue%3B5%3A100014064",200282334]],
    quantityConfig = {
        minErrorText : 'Please enter a Min. Order quantity that is <span id="min"></span> or more.',
        maxErrorText : 'Please enter a number that is <span id="max"></span> or less.' 
    },
    checkConfig = {
        emptyErorText : "Enter the characters you see in the image",
        errorText : "Type the characters you see in the picture"            
    },
    backHistoryUrl = "";
</script>

1 个答案:

答案 0 :(得分:2)

有几件事:

  1. 您要替换的不是HTML,而是javascript变量。

  2. 不要使用innerHTML(几乎没有)。它会破坏许多网页,特别是如果你在document.body上使用它。

  3. 您尝试更改的脚本甚至可能不会设置在正文中,而是设置在<head>中,因此无论如何这种策略可能都没有效果。

  4. 替换javascript的文本,加载后通常无效,javascript已经被解析到内存中。

  5. 可能无法仅根据问题中的(当前)修复javascript。 JS变量可能在范围内无法实现。

  6. 当且仅当javascript变量为 global 时,此代码才有效:

    // ==UserScript==
    // @name     _YOUR_SCRIPT_NAME
    // @include  http://YOUR_SERVER.COM/YOUR_PATH/*
    // @grant    none
    // ==/UserScript==
    
    window.needCaptcha  =  false;
    window.checkConfig  = {};
    


    对于其他任何事情,我们需要查看更多(更多)目标页面的代码。链接到它。

相关问题