Greasemonkey change value by 5

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
8,675
Reaction score
10,228
I need Greasemonkey to change a value by 5 in some code. I'm not sure if it's possible, but I think it is.

We have this code:

<input id="some" name="asd" data-bv-notempty="" data-bv-notempty-message="bla bla bla bla" placeholder="e.g. 20" data-bv-greaterthan="true" data-bv-greaterthan-value="10" data-bv-lessthan="true" data-bv-lessthan-value="51" data-bv-lessthan-message="bla bla" class="form-control" value="40" type="hidden">

Where it says Value="40"

I want when the page loads for Greasemonkey to turn that into Value="45"

But if it says Value="10", I want it to become Value="15"

And so on and so forth...

Can it be done? @TomTheCat @Gogol
 
JavaScript:
window.addEventListener('load', (event) => {
    document.getElementById("some").value = parseInt(document.getElementById("some").value) + 5;
});
 
JavaScript:
document.getElementById("some").value = document.getElementById("some").value + 5;

Oh wow, okay you're onto something. Unfortunately instead of turning 40 into 45, it turns 40 into 405 :/

So it adds a 5 instead of "editing" the number there and increasing it by 5.
 
It is, but there are a few other IDs that start with the same word.

id="some"
id="someasd"
id="some-wqer"

It shouldn't be the issue. Is an exact match.

Try this code:

window. on load

JavaScript:
 = function () {
    document.getElementById("some").value = parseInt(document.getElementById("some").value) + 5;
}
 
Cmon it’s not stupid hahah. It IS supposed to be a string, not an integer :p
But to add to this… It is a bit stupid to allow an integer to be concatenated to a string. This is what typescript fixes, and I love typescript for the same. :)

Could the problem be that this code is "invisible"?

type="hidden"
Nopes. That should not be a problem. The problem is the event listener I think. Try console logging inside the listener and see whether it indeed fires like you expect it to.
 
Back
Top