Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Enable Script on Both Shifts
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description Run userscript on both Shift keys pressed
- // @author dsasmblr
- // @match https://*.reddit.com/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=reddit.com
- // @grant none
- // @run-at document-idle
- // ==/UserScript==
- (function() {
- 'use strict';
- window.keys = [];
- let keys = window.keys;
- window.runMyScript = () => {
- console.log('I did it!');
- }
- window.keysCheck = () => {
- keys.push(event.code);
- keys = [...new Set(keys)];
- setTimeout(() => { keys = []; }, 100);
- }
- document.querySelector('body').addEventListener("keydown", (event) => {
- const shiftKeyPressed = event.code === "ShiftLeft" || event.code === "ShiftRight";
- if (shiftKeyPressed) {
- window.keysCheck();
- }
- if (keys.length === 2) {
- window.runMyScript();
- keys = [];
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement