Stop Nefarious Redirects

Detects and stops nefarious URL redirections, allows redirects on trusted websites, and logs the actions

当前为 2024-04-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Stop Nefarious Redirects
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.73
  5. // @description Detects and stops nefarious URL redirections, allows redirects on trusted websites, and logs the actions
  6. // @match http://*/*
  7. // @match https://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // List of trusted websites or domains where redirects are allowed
  16. const trustedWebsites = [
  17. '500px.com',
  18. 'adobe.com',
  19. 'amazon.com',
  20. 'apple.com',
  21. 'arstechnica.com',
  22. 'artstation.com',
  23. 'asana.com',
  24. 'atlassian.com',
  25. 'axios.com',
  26. 'battle.net',
  27. 'bbc.com',
  28. 'behance.net',
  29. 'bestbuy.com',
  30. 'blogger.com',
  31. 'booking.com',
  32. 'buzzfeed.com',
  33. 'canva.com',
  34. 'cnn.com',
  35. 'codecademy.com',
  36. 'constantcontact.com',
  37. 'coursera.org',
  38. 'deviantart.com',
  39. 'discord.com',
  40. 'docusign.com',
  41. 'dribbble.com',
  42. 'dropbox.com',
  43. 'duolingo.com',
  44. 'ebay.com',
  45. 'edx.org',
  46. 'engadget.com',
  47. 'epicgames.com',
  48. 'etsy.com',
  49. 'eurogamer.net',
  50. 'facebook.com',
  51. 'figma.com',
  52. 'flickr.com',
  53. 'forbes.com',
  54. 'framer.com',
  55. 'freecodecamp.org',
  56. 'gamespot.com',
  57. 'gettyimages.com',
  58. 'github.com',
  59. 'gizmodo.com',
  60. 'gog.com',
  61. 'hubspot.com',
  62. 'huffpost.com',
  63. 'humblebundle.com',
  64. 'ign.com',
  65. 'ikea.com',
  66. 'imdb.com',
  67. 'imgur.com',
  68. 'instagram.com',
  69. 'intuit.com',
  70. 'invisionapp.com',
  71. 'itch.io',
  72. 'khanacademy.org',
  73. 'kotaku.com',
  74. 'lifehacker.com',
  75. 'linkedin.com',
  76. 'lynda.com',
  77. 'mailchimp.com',
  78. 'mashable.com',
  79. 'masterclass.com',
  80. 'medium.com',
  81. 'microsoft.com',
  82. 'mozilla.org',
  83. 'msn.com',
  84. 'netflix.com',
  85. 'nytimes.com',
  86. 'origin.com',
  87. 'paypal.com',
  88. 'pcgamer.com',
  89. 'pexels.com',
  90. 'pinterest.com',
  91. 'pixabay.com',
  92. 'pluralsight.com',
  93. 'polygon.com',
  94. 'quora.com',
  95. 'reddit.com',
  96. 'salesforce.com',
  97. 'samsung.com',
  98. 'shutterstock.com',
  99. 'sketch.com',
  100. 'skillshare.com',
  101. 'skype.com',
  102. 'slack.com',
  103. 'soundcloud.com',
  104. 'spotify.com',
  105. 'stackoverflow.com',
  106. 'steamcommunity.com',
  107. 'surveymonkey.com',
  108. 'target.com',
  109. 'techcrunch.com',
  110. 'theguardian.com',
  111. 'theverge.com',
  112. 'tiktok.com',
  113. 'trello.com',
  114. 'tripadvisor.com',
  115. 'tumblr.com',
  116. 'twitch.tv',
  117. 'twitter.com',
  118. 'udemy.com',
  119. 'unsplash.com',
  120. 'Vice.com',
  121. 'vimeo.com',
  122. 'vk.com',
  123. 'vox.com',
  124. 'walmart.com',
  125. 'washingtonpost.com',
  126. 'whatsapp.com',
  127. 'wikimedia.org',
  128. 'wikipedia.org',
  129. 'wired.com',
  130. 'wordpress.com',
  131. 'wsj.com',
  132. 'yahoo.com',
  133. 'yelp.com',
  134. 'youtube.com',
  135. 'zapier.com',
  136. 'zendesk.com',
  137. 'zeplin.io',
  138. 'zoom.us',
  139. 'google.com'
  140. // Add more trusted websites or domains here
  141. ];
  142.  
  143. // Store the current URL
  144. let currentUrl = window.location.href;
  145.  
  146. // Store the previous URL
  147. let previousUrl = currentUrl;
  148.  
  149. // Flag to track if the script has been activated
  150. let scriptActivated = false;
  151.  
  152. // Function to log actions
  153. function logAction(message) {
  154. console.log(message);
  155. }
  156.  
  157. // Function to check if a website is trusted
  158. function isTrustedWebsite(url) {
  159. return trustedWebsites.some(website => url.includes(website));
  160. }
  161.  
  162. // Function to handle redirection
  163. function handleRedirect(event) {
  164. // Check if the URL has changed
  165. if (window.location.href !== currentUrl && !scriptActivated) {
  166. // Check if the current website is trusted
  167. if (isTrustedWebsite(window.location.href)) {
  168. // Allow the redirect on trusted websites
  169. previousUrl = currentUrl;
  170. currentUrl = window.location.href;
  171. return;
  172. }
  173.  
  174. // Set the script activation flag
  175. scriptActivated = true;
  176.  
  177. // Stop the redirection
  178. event.preventDefault();
  179. event.stopPropagation();
  180.  
  181. // Push the previous URL into the browser history
  182. window.history.pushState(null, null, previousUrl);
  183.  
  184. // Replace the current URL with the previous URL
  185. window.history.replaceState(null, null, previousUrl);
  186.  
  187. // Log the action
  188. logAction('Nefarious redirection stopped. Previous URL loaded.');
  189. }
  190. }
  191.  
  192. // Function to handle navigation
  193. function handleNavigation() {
  194. // Store the current URL before navigation
  195. previousUrl = currentUrl;
  196. currentUrl = window.location.href;
  197. }
  198.  
  199. // Function to continuously check for URL changes
  200. function checkUrlChange() {
  201. if (window.location.href !== currentUrl && !scriptActivated) {
  202. // Check if the current website is trusted
  203. if (isTrustedWebsite(window.location.href)) {
  204. // Allow the redirect on trusted websites
  205. previousUrl = currentUrl;
  206. currentUrl = window.location.href;
  207. } else {
  208. // Set the script activation flag
  209. scriptActivated = true;
  210.  
  211. // Push the previous URL into the browser history
  212. window.history.pushState(null, null, previousUrl);
  213.  
  214. // Replace the current URL with the previous URL
  215. window.history.replaceState(null, null, previousUrl);
  216.  
  217. // Log the action
  218. logAction('Nefarious redirection stopped. Previous URL loaded.');
  219. }
  220. }
  221.  
  222. // Reset the script activation flag
  223. scriptActivated = false;
  224.  
  225. // Schedule the next check
  226. setTimeout(checkUrlChange, 100);
  227. }
  228.  
  229. // Listen for the beforeunload event (forward direction)
  230. window.addEventListener('beforeunload', handleRedirect);
  231.  
  232. // Listen for the click event on links and navigation
  233. document.addEventListener('click', handleNavigation);
  234. window.addEventListener('popstate', handleNavigation);
  235.  
  236. // Start checking for URL changes
  237. checkUrlChange();
  238. })();