Do not redirect to China Version Website

try to take over the world!

  1. // ==UserScript==
  2. // @name Do not redirect to China Version Website
  3. // @namespace ATGT
  4. // @version 0.6
  5. // @description try to take over the world!
  6. // @author You
  7. // @match *://*.leetcode-cn.com/*
  8. // @match *://*.leetcode.com/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. console.log(`=== do not direct to china version web size ${location.host} ===`);
  15. 'use strict';
  16. if (/leetcode-cn.com$/.test(location.host) || /utm_\w+/.test(location.search)) {
  17. console.log('redirect to leetcode.com');
  18. let enUrl = new URL(location.href);
  19. enUrl.host = enUrl.host.replace(/leetcode-cn.com$/, 'leetcode.com');
  20. enUrl.search = enUrl.search.replace(/utm_[^&]+&?/, '');
  21. enUrl.search = enUrl.search.replace(/\?$/, '');
  22. location.href = enUrl.href;
  23. }
  24. if (/leetcode.com$/.test(location.host)) {
  25. window.addEventListener('load',() => {
  26. setTimeout(() => {
  27. // close banner on main page
  28. let btn = document.querySelector('#region_switcher .close-btn');
  29. if (btn)
  30. btn.click();
  31.  
  32. }, 500);
  33. setTimeout(() => {
  34. // close banner on problems page
  35. let btn = document.querySelector('#CNbanner .cn_close_btn');
  36. if (btn)
  37. btn.click();
  38. }, 1500);
  39. });
  40. }
  41. console.log(`=== /do not direct to china version web size ${location.host} ===`);
  42. })();