Reputation: 43
The Problem
I have the following function export called from the found inside the HTML page before
<input class="print" type="button" value="EXPORT" onclick="export()">
I want to modify the value 50000 to a greater value like 100000 and also the alert message with TamperMonkey, but can't figure out how to do it until now
<script>
function export() {
var ssrt=$('#minrng').val();
if(ssrt==''||ssrt==undefined){
alert("Please enter the minimum range");
return false;
}
var maxlength=$('#maxrng').val();
if(maxlength==''|| maxlength==undefined){
alert("Please enter the maximium range");
return false;
}
if(maxlength > 50000){
alert("The range should be less than 50000");
return false;
}
...
What I've done until now:
I have tried the following script to override the value 50000 with TamperMonkey, but the value is still the same And how to change the alert message if the value has been changed successfully?
(function() {
'use strict';
location.href="javascript:(function(){ window.maxlength = 100000; })()"
unsafeWindow.maxlength = 100000;
Window.maxlength = 100000;
})();
Thanks in advance!
Upvotes: 2
Views: 2692
Reputation: 808
If I understand you correct, you want to update the number 50000 in if(maxlength > 50000){…
, not maxlength
itself. So you shouldn't try to change maxlength
, but the number. You can change the script element with something like this:
document.getElementsByTagName('script')[0].innerHTML=document.getElementsByTagName('script')[0].innerHTML.replace(/50000/g,'100000');
You may have to write a loop before and search through all script elements to find the correct one to change.
Upvotes: 2