Spookify

Replaces one random link with a screamer

  1. // ==UserScript==
  2. // @name Spookify
  3. // @namespace ccn0
  4. // @version U1S1.03
  5. // @description Replaces one random link with a screamer
  6. // @author CCN0
  7. // @license GPL3
  8. // @match *://*/*
  9. // @icon https://ccn0.github.io/img/spooky/smilegirl32icon.png
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. const spookyList = [
  15. ["https://media1.tenor.com/m/So59sDcNM4wAAAAC/fnaf-chica.gif","https://ccn0.github.io/img/audio/plus/fnaf4jumpscare.mp3"],
  16. ["https://media1.tenor.com/m/ZO1_WS7f-4YAAAAC/fnaf-freddy.gif","https://ccn0.github.io/img/audio/plus/fnaf1jumpscare.mp3"],
  17. ["https://media.tenor.com/aHR1ThFfmE4AAAAi/fnaf.gif","https://ccn0.github.io/img/audio/plus/fnaf2jumpscare.mp3"],
  18. ["https://media.tenor.com/E_HSK33-xokAAAAi/fnaf-bunny.gif","https://ccn0.github.io/img/audio/plus/fnaf3jumpscare.mp3"],
  19. ["https://ccn0.github.io/img/spooky/smilegirl.png","https://ccn0.github.io/img/audio/plus/funandlaughing.mp3"],
  20. ["https://ccn0.github.io/img/spooky/spookyhillman.gif","https://ccn0.github.io/img/audio/plus/cardrivinghills.mp3"],
  21. ["https://ccn0.github.io/img/spooky/niceman24kbfile.png","https://ccn0.github.io/img/audio/plus/southparkbestofcousinelvin.mp3"],
  22. ];
  23. const chosenScare = spookyList[Math.floor(spookyList.length * Math.random())];
  24.  
  25. const spookySound = new Audio();
  26. spookySound.src = chosenScare[1];
  27. spookySound.preload = 'auto';
  28. const spookyPhoto = chosenScare[0];
  29.  
  30. const spookElem = document.createElement('img');
  31. spookElem.style.display = 'none';
  32. spookElem.src = spookyPhoto;
  33. spookElem.style.width = '100%';
  34. spookElem.style.height = '100vh';
  35. spookElem.style.position = 'fixed';
  36. spookElem.style.top = '0';
  37. spookElem.style.left = '0';
  38. document.body.appendChild(spookElem);
  39.  
  40. const links = document.querySelectorAll('a');
  41. if (links.length === 0) return;
  42. const chosenLink = Math.floor(links.length * Math.random());
  43. const originalDestination = links[chosenLink].href;
  44.  
  45. function scare() {
  46. return new Promise((resolve) => {
  47. spookySound.volume = 1;
  48. spookySound.play();
  49. spookElem.style.display = 'block';
  50. spookySound.addEventListener('ended', () => {
  51. spookElem.style.display = 'none';
  52. resolve();
  53. });
  54. });
  55. };
  56.  
  57. function finale() {
  58. spookElem.style.display = 'none';
  59. location.href = originalDestination;
  60. };
  61.  
  62. console.log(links[chosenLink].textContent);
  63. links[chosenLink].classList.add('spooky');
  64. links[chosenLink].setAttribute('title',links[chosenLink].href);
  65. links[chosenLink].removeAttribute('href');
  66. links[chosenLink].addEventListener('mousedown',(e)=>{
  67. console.log(e.button)
  68. switch (e.button) {
  69. case 0:
  70. scare().then(finale);
  71. break;
  72. case 1:
  73. e.preventDefault();
  74. scare();
  75. window.open(originalDestination, "_blank");
  76. break;
  77.  
  78. default:
  79. break;
  80. }
  81. });
  82.  
  83. const css = `
  84. @keyframes rapidColorChange {
  85. 0% { opacity: 1; }
  86. 10% { opacity: 0; }
  87. 14% { opacity: 1; }
  88. 19% { opacity: 0; }
  89. 28% { opacity: 1; }
  90. 36% { opacity: 0; }
  91. 43% { opacity: 1; }
  92. 52% { opacity: 0; }
  93. 57% { opacity: 1; }
  94. 62% { opacity: 0; }
  95. 64% { opacity: 1; }
  96. 69% { opacity: 0; }
  97. 78% { opacity: 1; }
  98. 81% { opacity: 0; }
  99. 89% { opacity: 1; }
  100. 94% { opacity: 0; }
  101. 97% { opacity: 1; }
  102. 99% { opacity: 0; }
  103. }
  104. .spooky {
  105. animation: rapidColorChange 10s infinite;
  106. cursor: grab;
  107. &:active {
  108. cursor: grabbing;
  109. }
  110. }
  111. `;
  112.  
  113. const style = document.createElement('style');
  114. style.innerHTML = css;
  115.  
  116. document.head.appendChild(style);
  117. })();