Advertisement
Guest User

Counter

a guest
Feb 9th, 2021
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Counter5
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       Peca
  7. // @match        SECRET!
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.     console.log("Start!");
  14.  
  15.     const delay = ms => new Promise(res => setTimeout(res, ms));
  16.     var counter = parseInt(localStorage.counter)||0;
  17.     const ENTER_KEY = 13;
  18.  
  19.     const test = async () => {
  20.         window.addEventListener("keydown", keyboardHandlerJQ, false);
  21.         var newHTML = document.createElement ('div');
  22.         newHTML.innerHTML = '<div id="gmSomeID"><p style="font-size:25px; text-align: center;">'.concat('\t', counter.toString(), '</p></div>');
  23.         document.getElementById("rootComponentDiv").appendChild(newHTML);
  24.  
  25.         console.log("Waiting for buttons!");
  26.         var buttons;
  27.         do {
  28.             console.log("Still no buttons!");
  29.             buttons = document.getElementsByClassName("v-btn v-btn--small theme--dark orange");
  30.             await delay(500);
  31.         } while(!(buttons.length == 2));
  32.         console.log("Found Buttons");
  33.  
  34.         var i;
  35.         for(i = 0;i < buttons.length;i++){
  36.             buttons[i].onclick = onClick;
  37.             console.log("Event added")
  38.         }
  39.  
  40.         console.log("Waiting for finished button!");
  41.         var finishButton;
  42.         do {
  43.             console.log("Still no button!");
  44.             finishButton = document.getElementById("btnFinished");
  45.             await delay(500);
  46.         } while(finishButton == null);
  47.         console.log("Found Button");
  48.         finishButton.onclick = onClick;
  49.     };
  50.  
  51.     function onClick(){
  52.         console.log("Button pressed.");
  53.         localStorage.counter = ++counter;
  54.         console.log(counter);
  55.     }
  56.  
  57.     function keyboardHandlerJQ(zEvent) {
  58.         var bBlockDefaultAction = false;
  59.         if (zEvent.altKey || zEvent.ctrlKey || zEvent.shiftKey) {
  60.             if(zEvent.ctrlKey){
  61.                 if (zEvent.which == ENTER_KEY) {
  62.                     console.log("Deleting Counter!");
  63.                     localStorage.removeItem("counter");
  64.                     counter = 0;
  65.                 }
  66.             }
  67.         }
  68.         if (bBlockDefaultAction) {
  69.             zEvent.preventDefault();
  70.             zEvent.stopPropagation();
  71.         }
  72.     }
  73.  
  74.     test();
  75. })();
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement