Advertisement
Guest User

Untitled

a guest
Oct 13th, 2023
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Enable Script on Both Shifts
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Run userscript on both Shift keys pressed
  6. // @author       dsasmblr
  7. // @match        https://*.reddit.com/*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
  9. // @grant        none
  10. // @run-at       document-idle
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.     'use strict';
  15.  
  16.     window.keys = [];
  17.     let keys = window.keys;
  18.  
  19.     window.runMyScript = () => {
  20.         console.log('I did it!');
  21.     }
  22.  
  23.     window.keysCheck = () => {
  24.         keys.push(event.code);
  25.         keys = [...new Set(keys)];
  26.         setTimeout(() => { keys = []; }, 100);
  27.     }
  28.  
  29.     document.querySelector('body').addEventListener("keydown", (event) => {
  30.         const shiftKeyPressed = event.code === "ShiftLeft" || event.code === "ShiftRight";
  31.        
  32.         if (shiftKeyPressed) {
  33.             window.keysCheck();
  34.         }
  35.  
  36.         if (keys.length === 2) {
  37.             window.runMyScript();
  38.             keys = [];
  39.         }
  40.     });
  41. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement