Stop Nefarious Redirects

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

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

  1. // ==UserScript==
  2. // @name Stop Nefarious Redirects
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.71
  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. 'mail.google.com',
  81. 'medium.com',
  82. 'microsoft.com',
  83. 'mozilla.org',
  84. 'msn.com',
  85. 'netflix.com',
  86. 'nytimes.com',
  87. 'origin.com',
  88. 'paypal.com',
  89. 'pcgamer.com',
  90. 'pexels.com',
  91. 'pinterest.com',
  92. 'pixabay.com',
  93. 'pluralsight.com',
  94. 'polygon.com',
  95. 'quora.com',
  96. 'reddit.com',
  97. 'salesforce.com',
  98. 'samsung.com',
  99. 'shutterstock.com',
  100. 'sketch.com',
  101. 'skillshare.com',
  102. 'skype.com',
  103. 'slack.com',
  104. 'soundcloud.com',
  105. 'spotify.com',
  106. 'stackoverflow.com',
  107. 'steamcommunity.com',
  108. 'surveymonkey.com',
  109. 'target.com',
  110. 'techcrunch.com',
  111. 'theguardian.com',
  112. 'theverge.com',
  113. 'tiktok.com',
  114. 'trello.com',
  115. 'tripadvisor.com',
  116. 'tumblr.com',
  117. 'twitch.tv',
  118. 'twitter.com',
  119. 'udemy.com',
  120. 'unsplash.com',
  121. 'Vice.com',
  122. 'vimeo.com',
  123. 'vk.com',
  124. 'vox.com',
  125. 'walmart.com',
  126. 'washingtonpost.com',
  127. 'whatsapp.com',
  128. 'wikimedia.org',
  129. 'wikipedia.org',
  130. 'wired.com',
  131. 'wordpress.com',
  132. 'wsj.com',
  133. 'yahoo.com',
  134. 'yelp.com',
  135. 'youtube.com',
  136. 'zapier.com',
  137. 'zendesk.com',
  138. 'zeplin.io',
  139. 'zoom.us',
  140. 'google.com'
  141. // Add more trusted websites or domains here
  142. ];
  143.  
  144. // Store the current URL
  145. let currentUrl = window.location.href;
  146.  
  147. // Store the previous URL
  148. let previousUrl = currentUrl;
  149.  
  150. // Flag to track if the script has been activated
  151. let scriptActivated = false;
  152.  
  153. // Function to log actions
  154. function logAction(message) {
  155. console.log(message);
  156. }
  157.  
  158. // Function to check if a website is trusted
  159. function isTrustedWebsite(url) {
  160. return trustedWebsites.some(website => url.includes(website));
  161. }
  162.  
  163. // Function to handle redirection
  164. function handleRedirect(event) {
  165. // Check if the URL has changed
  166. if (window.location.href !== currentUrl && !scriptActivated) {
  167. // Check if the current website is trusted
  168. if (isTrustedWebsite(window.location.href)) {
  169. // Allow the redirect on trusted websites
  170. previousUrl = currentUrl;
  171. currentUrl = window.location.href;
  172. return;
  173. }
  174.  
  175. // Set the script activation flag
  176. scriptActivated = true;
  177.  
  178. // Stop the redirection
  179. event.preventDefault();
  180. event.stopPropagation();
  181.  
  182. // Push the previous URL into the browser history
  183. window.history.pushState(null, null, previousUrl);
  184.  
  185. // Replace the current URL with the previous URL
  186. window.history.replaceState(null, null, previousUrl);
  187.  
  188. // Log the action
  189. logAction('Nefarious redirection stopped. Previous URL loaded.');
  190. }
  191. }
  192.  
  193. // Function to handle forward navigation
  194. function handleForwardNavigation() {
  195. // Store the current URL before navigation
  196. previousUrl = currentUrl;
  197. currentUrl = window.location.href;
  198. }
  199.  
  200. // Function to handle back button navigation
  201. function handleBackNavigation(event) {
  202. // Check if the current URL is different from the previous URL
  203. if (window.location.href !== previousUrl) {
  204. // Set the script activation flag
  205. scriptActivated = true;
  206.  
  207. // Stop the back navigation
  208. event.preventDefault();
  209. event.stopPropagation();
  210.  
  211. // Replace the current URL with the previous URL
  212. window.history.replaceState(null, null, previousUrl);
  213.  
  214. // Reload the previous URL
  215. window.location.href = previousUrl;
  216.  
  217. // Log the action
  218. logAction('Back button navigation detected. Previous URL loaded.');
  219. }
  220. }
  221.  
  222. // Function to continuously check for URL changes
  223. function checkUrlChange() {
  224. if (window.location.href !== currentUrl && !scriptActivated) {
  225. // Check if the current website is trusted
  226. if (isTrustedWebsite(window.location.href)) {
  227. // Allow the redirect on trusted websites
  228. previousUrl = currentUrl;
  229. currentUrl = window.location.href;
  230. return;
  231. }
  232.  
  233. // Set the script activation flag
  234. scriptActivated = true;
  235.  
  236. // Push the previous URL into the browser history
  237. window.history.pushState(null, null, previousUrl);
  238.  
  239. // Replace the current URL with the previous URL
  240. window.history.replaceState(null, null, previousUrl);
  241.  
  242. // Log the action
  243. logAction('Nefarious redirection stopped. Previous URL loaded.');
  244. }
  245.  
  246. // Reset the script activation flag
  247. scriptActivated = false;
  248.  
  249. // Schedule the next check
  250. setTimeout(checkUrlChange, 100);
  251. }
  252.  
  253. // Listen for the beforeunload event (forward direction)
  254. window.addEventListener('beforeunload', handleRedirect);
  255.  
  256. // Listen for the popstate event (backward direction)
  257. window.addEventListener('popstate', handleBackNavigation);
  258.  
  259. // Listen for the click event on links
  260. document.addEventListener('click', handleForwardNavigation);
  261.  
  262. // Start checking for URL changes
  263. checkUrlChange();
  264. })();