Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
849 views
in Technique[技术] by (71.8m points)

firefox - How to alter this javascript with Greasemonkey?

Here is the script:

<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
  $('#file_upload').uploadify({
    'uploader'  : '/uploadify/uploadify.swf',
    'script'    : '/upload2.php',
    'cancelImg' : '/uploadify/cancel.png',
    'folder'    : '/uploads',
    'auto'      : false,

    'onError'     : function (event,ID,fileObj,errorObj) {
      alert(errorObj.type + ' Error: ' + errorObj.info);
    },
    'fileExt'     : '*.wma;*.mp3',
    'fileDesc'    : 'Audio Files',
    'scriptData'  : {'fileID':'20541','hash':'2e1177c09a6503d11b1a401177022de50409e96279a2dbb11c5aef5783d231c975da22e2ddfd480b5e050f4fb09d9b7caa47a71ab0150b7c462b06d06e61e664','hashit':'fe458d423c6d1c18248b73dad776a9d4a6ff1ac9fc4b07674b3715b4992a80b9d2b4e3a340973642497d66ac8e8d57d7aa737f8911a784888b164e84961f177a'},
    'onComplete'  : function(eventID,ID,fileObj,response,data) {
        window.location = "http://www.messageshare.com/welcome/file_farm/20541/fe458d423c6d1c18248b73dad776a9d4a6ff1ac9fc4b07674b3715b4992a80b9d2b4e3a340973642497d66ac8e8d57d7aa737f8911a784888b164e84961f177a";
    }
  });
});
// ]]>
</script>

I need to change 'auto' from false to true.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since all those scriptData values seem liable to change from page load to page load, what you'd want to do is intercept that <script> node on the fly, clone it and only change 'auto' to true, using RegEx.

On Firefox Greasemonkey, you can do that with the stupefyingly brilliant (^_^) checkForBadJavascripts utility. Like so:

// ==UserScript==
// @name     _Modify JS as it's loaded
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  https://gist.github.com/raw/2620135/checkForBadJavascripts.js
// @run-at   document-start
// @grant    GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

function replaceTargetJavascript (scriptNode) {
    var scriptSrc   = scriptNode.textContent;
    scriptSrc       = scriptSrc.replace (
        /'auto's+:s+false/,
        "'auto'      : true"
    );

    addJS_Node (scriptSrc);
}

checkForBadJavascripts ( [
    [false, /'auto's+:s+false/, replaceTargetJavascript]
] );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...