如何用Greasemonkey改变这个JavaScript

如何用Greasemonkey改变这个JavaScript

本文介绍了如何用Greasemonkey改变这个JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是脚本:

 < script type =text / javascript> 
//<![CDATA [
$(document).ready(function(){
$('#file_upload')。uploadify({
'uploader': '/uploadify/uploadify.swf',
'script':'/upload2.php',
'cancelImg':'/uploadify/cancel.png',
'文件夹':'函数(event,ID,fileObj,errorObj){
alert(errorObj.type +'错误:
'auto':false,

' '+ errorObj.info);
},
'fileExt':'* .wma; *。mp3',
'fileDesc':'Audio Files',
'scriptData ':{' FILEID ':' 20541' , '哈希': '2e1177c09a6503d11b1a401177022de50409e96279a2dbb11c5aef5783d231c975da22e2ddfd480b5e050f4fb09d9b7caa47a71ab0150b7c462b06d06e61e664', 'hashit': 'fe458d423c6d1c18248b73dad776a9d4a6ff1ac9fc4b07674b3715b4992a80b9d2b4e3a340973642497d66ac8e8d57d7aa737f8911a784888b164e84961f177a'},
'的onComplete':功能(EVENTID,ID,FileObj文件,respons e,data){
window.location =http://www.messageshare.com/welcome/file_farm/20541/fe458d423c6d1c18248b73dad776a9d4a6ff1ac9fc4b07674b3715b4992a80b9d2b4e3a340973642497d66ac8e8d57d7aa737f8911a784888b164e84961f177a;
}
});
});
//]]>
< / script>

我需要将'auto'从 false to true 。

解决方案<由于所有这些 scriptData 值似乎都有可能从页面加载变为页面加载,所以你想要做的是截取 < script>< / code>节点,克隆它,只改变'auto'到 true

在Firefox Greasemonkey上,您可以使用。像这样:

$ p $ // == UserScript ==
// @name _Modify加载时的JS
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require https://gist.github.com/raw/2620135/checkForBadJavascripts.js
// @ run-在document-start
// @grant GM_addStyle
// == / UserScript ==
/ * - 需要@grant指令来解决设计变更
介绍GM 1.0。它恢复沙箱。
* /

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

addJS_Node(scriptSrc);

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


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.

解决方案

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]
] );

这篇关于如何用Greasemonkey改变这个JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:31