Letterpress image flip

Flips all images horizontally when both shift keys are pressed simultaneously. Useful for shopping for letterpress cuts.

  1. // ==UserScript==
  2. // @name Letterpress image flip
  3. // @namespace SSSSLLLL
  4. // @author SSSSLLLL
  5. // @description Flips all images horizontally when both shift keys are pressed simultaneously. Useful for shopping for letterpress cuts.
  6. // @match *://*/*
  7. // @icon https://upload.wikimedia.org/wikipedia/commons/e/e9/Metal_type.svg
  8. // @version 0.2
  9. // @license GPLv3
  10. // ==/UserScript==
  11.  
  12. function addStyle(styleText){
  13. let s = document.createElement('style')
  14. s.appendChild(document.createTextNode(styleText))
  15. document.getElementsByTagName('head')[0].appendChild(s)
  16. }
  17.  
  18.  
  19.  
  20. (function() {
  21. 'use strict';
  22.  
  23. window.keys = [];
  24. let keys = window.keys;
  25.  
  26. window.runMyScript = () => {
  27. console.log('Flipped image');
  28. }
  29.  
  30. window.keysCheck = () => {
  31. keys.push(event.code);
  32. keys = [...new Set(keys)];
  33. setTimeout(() => { keys = []; }, 600);
  34. }
  35.  
  36. document.querySelector('body').addEventListener("keydown", (event) => {
  37. const shiftKeyPressed = event.code === "ShiftLeft" || event.code === "ShiftRight";
  38.  
  39. if (shiftKeyPressed) {
  40. window.keysCheck();
  41. }
  42.  
  43. if (keys.length === 2) {
  44. addStyle(`
  45. img{
  46. transform:scaleX(-1);
  47. }
  48. `)
  49.  
  50. keys = [];
  51. }
  52. });
  53. })();