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