Allow Right-Click with Tampermonkey Menu Option

Allows right-clicking on websites that prevent it by clicking the menu button in the Tampermonkey extension.

目前为 2025-04-10 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Allow Right-Click with Tampermonkey Menu Option
  3. // @namespace typpi.online
  4. // @version 1.9
  5. // @description Allows right-clicking on websites that prevent it by clicking the menu button in the Tampermonkey extension.
  6. // @author Nick2bad4u
  7. // @match *://*/*
  8. // @grant GM_registerMenuCommand
  9. // @icon https://i.gyazo.com/ba5b7116d7140e7a247e176c312b4bd5.png
  10. // @license UnLicense
  11. // @tag all
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. // Function to enable right-click
  18. function enableRightClick() {
  19. document.addEventListener(
  20. 'contextmenu',
  21. function (event) {
  22. event.stopPropagation();
  23. },
  24. true,
  25. );
  26.  
  27. document.addEventListener(
  28. 'mousedown',
  29. function (event) {
  30. if (event.button === 2) {
  31. event.stopPropagation();
  32. }
  33. },
  34. true,
  35. );
  36.  
  37. document.addEventListener(
  38. 'mouseup',
  39. function (event) {
  40. if (event.button === 2) {
  41. event.stopPropagation();
  42. }
  43. },
  44. true,
  45. );
  46.  
  47. // Create a non-blocking notification
  48. const notification = document.createElement('div');
  49. notification.textContent = 'Right-click has been enabled!';
  50. notification.style.position = 'fixed';
  51. notification.style.top = '10vh'; // Set to 10% of the viewport height for better consistency
  52. notification.style.left = '50%';
  53. notification.style.transform = 'translate(-50%, -50%)';
  54. notification.style.backgroundColor = '#4CAF50';
  55. notification.style.color = 'white';
  56. notification.style.padding = '20px';
  57. notification.style.fontSize = '18px';
  58. notification.style.borderRadius = '10px';
  59. notification.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.3)';
  60. notification.style.zIndex = '99999';
  61. notification.style.opacity = '0';
  62. notification.style.transition = 'opacity 0.5s ease, transform 0.5s ease, background-color 0.5s ease';
  63. notification.style.border = '2px solid black'; // Added black border
  64. notification.style.cursor = 'move'; // Indicate that the notification is draggable
  65.  
  66. // Add a tooltip for drag functionality
  67. notification.title = 'Drag to move this notification';
  68. document.body.appendChild(notification);
  69.  
  70. // Add an exit button
  71. const exitButton = document.createElement('button');
  72. exitButton.textContent = '×';
  73. exitButton.style.position = 'absolute';
  74. exitButton.style.top = '5px';
  75. exitButton.style.right = '10px';
  76. exitButton.style.background = 'transparent';
  77. exitButton.style.border = 'none';
  78. exitButton.style.color = 'white';
  79. exitButton.style.fontSize = '16px';
  80. exitButton.style.cursor = 'pointer';
  81. exitButton.addEventListener('click', () => {
  82. if (typeof colorInterval !== 'undefined') {
  83. clearInterval(colorInterval); // Clear the color interval
  84. }
  85. notification.style.opacity = '0';
  86. notification.style.transform = 'translate(-50%, -10%)';
  87. setTimeout(() => notification.remove(), 500);
  88. });
  89. notification.appendChild(exitButton);
  90.  
  91. // Make the notification draggable
  92. let isDragging = false;
  93. let offsetX = 0;
  94. let offsetY = 0;
  95.  
  96. notification.addEventListener('mousedown', (event) => {
  97. isDragging = true;
  98. offsetX = event.clientX - notification.getBoundingClientRect().left;
  99. offsetY = event.clientY - notification.getBoundingClientRect().top;
  100. notification.style.transition = 'none'; // Disable transition during drag
  101. });
  102.  
  103. document.addEventListener('mousemove', (event) => {
  104. if (isDragging) {
  105. notification.style.left = `${event.clientX - offsetX}px`;
  106. notification.style.top = `${event.clientY - offsetY}px`;
  107. notification.style.transform = 'none'; // Disable centering during drag
  108. }
  109. });
  110.  
  111. document.addEventListener('mouseup', () => {
  112. isDragging = false;
  113. notification.style.transition = 'opacity 0.5s ease, transform 0.5s ease, background-color 0.5s ease'; // Re-enable transition
  114. });
  115.  
  116. // Trigger the fade-in animation
  117. setTimeout(() => {
  118. notification.style.opacity = '1';
  119. }, 0);
  120.  
  121. // Change color every second
  122. let randomColors = Array.from({ length: 4 }, () => `hsl(${Math.floor(Math.random() * 360)}, 100%, 50%)`); // Generate random bright colors
  123. let colorIndex = 0;
  124.  
  125. let isNotificationActive = true; // Flag to track if the notification is active
  126.  
  127. let colorInterval = setInterval(() => {
  128. if (isNotificationActive && notification.style.opacity === '1') {
  129. // Only update color if visible and active
  130. colorIndex = (colorIndex + 1) % randomColors.length; // Cycle through colors
  131. notification.style.backgroundColor = randomColors[colorIndex];
  132. }
  133. }, 750); // Change color every 750ms
  134.  
  135. // Clear the interval when fading out
  136. setTimeout(() => {
  137. if (isNotificationActive) {
  138. clearInterval(colorInterval);
  139. isNotificationActive = false; // Mark as inactive
  140. if (notification.parentNode) { // Check if notification is still in the DOM
  141. notification.style.opacity = '0';
  142. notification.style.transform = 'translate(-50%, -10%)';
  143. setTimeout(() => notification.remove(), 500); // Remove after fade-out
  144. }
  145. }
  146. }, 3000); // Start fade-out after 3 seconds
  147. }
  148.  
  149. // Register the option in the Tampermonkey menu
  150. /* eslint-disable no-undef */
  151. GM_registerMenuCommand('Enable Right-Click', enableRightClick);
  152. /* eslint-enable no-undef */
  153. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址