Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Counter5
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author Peca
- // @match SECRET!
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- console.log("Start!");
- const delay = ms => new Promise(res => setTimeout(res, ms));
- var counter = parseInt(localStorage.counter)||0;
- const ENTER_KEY = 13;
- const test = async () => {
- window.addEventListener("keydown", keyboardHandlerJQ, false);
- var newHTML = document.createElement ('div');
- newHTML.innerHTML = '<div id="gmSomeID"><p style="font-size:25px; text-align: center;">'.concat('\t', counter.toString(), '</p></div>');
- document.getElementById("rootComponentDiv").appendChild(newHTML);
- console.log("Waiting for buttons!");
- var buttons;
- do {
- console.log("Still no buttons!");
- buttons = document.getElementsByClassName("v-btn v-btn--small theme--dark orange");
- await delay(500);
- } while(!(buttons.length == 2));
- console.log("Found Buttons");
- var i;
- for(i = 0;i < buttons.length;i++){
- buttons[i].onclick = onClick;
- console.log("Event added")
- }
- console.log("Waiting for finished button!");
- var finishButton;
- do {
- console.log("Still no button!");
- finishButton = document.getElementById("btnFinished");
- await delay(500);
- } while(finishButton == null);
- console.log("Found Button");
- finishButton.onclick = onClick;
- };
- function onClick(){
- console.log("Button pressed.");
- localStorage.counter = ++counter;
- console.log(counter);
- }
- function keyboardHandlerJQ(zEvent) {
- var bBlockDefaultAction = false;
- if (zEvent.altKey || zEvent.ctrlKey || zEvent.shiftKey) {
- if(zEvent.ctrlKey){
- if (zEvent.which == ENTER_KEY) {
- console.log("Deleting Counter!");
- localStorage.removeItem("counter");
- counter = 0;
- }
- }
- }
- if (bBlockDefaultAction) {
- zEvent.preventDefault();
- zEvent.stopPropagation();
- }
- }
- test();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement