Redirect .org to .com

Automatically redirects .org websites to their .com version if available

  1. // ==UserScript==
  2. // @name Redirect .org to .com
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Automatically redirects .org websites to their .com version if available
  6. // @author Your Name
  7. // @match *://*.org/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // List of .org sites you don't want to redirect
  15. const exceptions = [
  16. 'wikipedia.org',
  17. 'archive.org',
  18. 'mozilla.org'
  19. ];
  20.  
  21. // Function to check if a site is an exception
  22. function isException(hostname) {
  23. return exceptions.some(exception => hostname.endsWith(exception));
  24. }
  25.  
  26. // Function to log redirection details
  27. function logRedirection(from, to) {
  28. console.log(`Redirecting from ${from} to ${to}`);
  29. }
  30.  
  31. // Get the current hostname (e.g., 'example.org')
  32. const currentHost = window.location.hostname;
  33.  
  34. // Check if it's an exception or already on .com
  35. if (currentHost.endsWith('.org') && !isException(currentHost)) {
  36. // Replace .org with .com
  37. const newHost = currentHost.replace('.org', '.com');
  38.  
  39. // Log redirection details
  40. logRedirection(currentHost, newHost);
  41.  
  42. // Redirect to the new .com domain
  43. window.location.href = window.location.href.replace(currentHost, newHost);
  44. } else {
  45. // Log when no redirection occurs
  46. console.log(`No redirection for ${currentHost}`);
  47. }
  48. })();