Followy back/close button

Inserts a back + close button that approaches your mouse pointer as you move it.

  1. // ==UserScript==
  2. // @name Followy back/close button
  3. // @namespace https://greasyfork.org/en/users/1148791-vuccala
  4. // @author Vuccala
  5. // @icon https://archive.org/download/backX/backX.png
  6. // @version 1.0
  7. // @description Inserts a back + close button that approaches your mouse pointer as you move it.
  8. // @match *://*/*
  9. // @grant window.close
  10. // @license MIT
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. const backButton = document.createElement('button');
  16. backButton.innerHTML = '🔙';
  17. backButton.style.position = 'fixed';
  18. backButton.style.zIndex = '9999';
  19. backButton.style.border = 'none';
  20. backButton.style.backgroundColor = 'transparent';
  21. backButton.style.fontSize = '24px';
  22. backButton.style.cursor = 'pointer';
  23.  
  24. const closeButton = document.createElement('button');
  25. closeButton.innerHTML = '✖️';
  26. closeButton.style.position = 'fixed';
  27. closeButton.style.zIndex = '9999';
  28. closeButton.style.border = 'none';
  29. closeButton.style.backgroundColor = 'transparent';
  30. closeButton.style.fontSize = '24px';
  31. closeButton.style.cursor = 'pointer';
  32.  
  33. document.body.appendChild(backButton);
  34. document.body.appendChild(closeButton);
  35.  
  36. // Hides Back button if no history or if about:newtab
  37. function updateEmoji() {
  38. if (window.history.length <= 1 || document.referrer === '') {
  39. backButton.innerHTML = '';
  40. }
  41. }
  42.  
  43. backButton.addEventListener('click', () => {
  44. history.back();
  45. });
  46.  
  47. closeButton.addEventListener('click', () => {
  48. window.close();
  49. });
  50.  
  51. const chasingSpeed = 0.05;
  52. let emojiX = window.innerWidth / 2;
  53. let emojiY = window.innerHeight / 2;
  54.  
  55. function updateEmojiPosition(event) {
  56. const emojiSize = 24;
  57. const targetX = event.clientX - emojiSize / 2;
  58. const targetY = event.clientY - emojiSize / 2;
  59.  
  60. emojiX += (targetX - emojiX) * chasingSpeed;
  61. emojiY += (targetY - emojiY) * chasingSpeed;
  62.  
  63. backButton.style.left = emojiX + -10 + 'px';
  64. backButton.style.top = emojiY + 'px';
  65. closeButton.style.left = emojiX + 20 + 'px';
  66. closeButton.style.top = emojiY + 'px';
  67.  
  68. }
  69.  
  70. window.addEventListener('popstate', updateEmoji);
  71. document.addEventListener('mousemove', updateEmojiPosition);
  72.  
  73. // Initial emoji update
  74. updateEmoji();
  75. })();