0

i want to add an save button with a counter i wrote a script but its not work with greasemonkey

<button type="submit" id="save" value="Save">Save</button>

<p>The button was pressed <span id="displayCount">0</span> times.</p>

<script type="text/javascript">
var count = 0;
var button = document.getElementById("save");
var display = document.getElementById("displayCount");
function loadStats(){
if(window.localStorage.getItem('count')){
count = window.localStorage.getItem('count')
display.innerHTML = count;
} else {
window.localStorage.setItem('count', 0)
} //Checks if data has been saved before so Count value doesnt become null.
}
window.localStorage.setItem("on_load_counter", count);
button.onclick = function(){
count++;
window.localStorage.setItem("count", count)
display.innerHTML = count;
}
</script>

1 Answers1

0

You have to add html elements with javascript since Greasemonkey is intended to run scripts over web pages.

See Basic method to Add html content to the page with Greasemonkey?

Community
  • 1
  • 1
hayj
  • 1,159
  • 13
  • 21