1

I need some help with a Greasemonkey script. I'm trying to replace some text in an HTML document and to delete a javascript function from that website.

The expression I want to rewrite is needCaptcha: true into needCaptcha: false . I want to remove this portion of HTML too:

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

I used this script but it doesn't work:

{
    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"'
    },)
}

Any idea?

Ok, thank you very much for your answer I understand it better what we are trying to do. However your script didn't worked, here you have the webpage where you can find it, as long as you can get to the place order webpage and that isn't easy.

I think the captcha is checked in local and so we should be able to bypass that using javascript.

Anyway, here you have the partial code of the website as a reference:

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>
4
  • I just formatted the code you posted, and the second block is syntactically invalid. Are you sure that's the exact code you were using? Commented Nov 26, 2012 at 11:52
  • Don't pay too much attention to my userscript, it's a bad attempt to create a script that works (but of course, it doesn't). Commented Nov 26, 2012 at 12:29
  • We really need to see the target page to make sense of this. Link to it. Or use firefox to save the page and then paste the htm file to pastebin.com and link to that. Commented Nov 26, 2012 at 12:31
  • There was an error, sorry for that, I think now it's clear. The script only have to replace needCaptcha: true for needCaptcha: false in the html document and delete: checkConfig = { empty : "Enter the characters in the image", error : "Type the characters you see" And unfortunately I don't access right now to the website. Commented Nov 26, 2012 at 12:36

1 Answer 1

2

Several things:

  1. What you are trying to replace is not HTML, but javascript variables.

  2. Do not use innerHTML (pretty much ever). It will wreck many web pages, especially if you use it on the document.body.

  3. The script you are trying to change may not even be set in the body, but rather in the <head>, so that tactic may have no effect anyway.

  4. Replacing javascript's text, after it has been loaded will usually have no effect, the javascript has already been parsed into memory.

  5. It may not be possible to fix the javascript based solely on what is (currently) in the question. The JS variables maybe out of reach in a scope.

If, and only if, the javascript variables are global, then this code will work:

// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant    none
// ==/UserScript==

window.needCaptcha  =  false;
window.checkConfig  = {};


For anything else, we need to see more (much more) of the target page's code. Link to it.

Sign up to request clarification or add additional context in comments.

2 Comments

That's good, but we need the <script> that defines needCaptcha too.
The webpage is not active at the moment, so I will retake the question in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.