LeetCode CN to LeetCode COM Redirector

Redirect from leetcode.cn to leetcode.com with a loading animation.

Versione datata 12/01/2024. Vedi la nuova versione l'ultima versione.

  1. // ==UserScript==
  2. // @name LeetCode CN to LeetCode COM Redirector
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-01-12#2
  5. // @description Redirect from leetcode.cn to leetcode.com with a loading animation.
  6. // @author Yuyang Wang
  7. // @match *://leetcode.cn/*
  8. // @match *://leetcode.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
  10. // @grant GM_addStyle
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Check if the current URL is from leetcode.cn
  18. if (window.location.host === 'leetcode.cn') {
  19. // Add a simple loading animation to the body
  20. document.body.innerHTML = '<div style="display: flex; justify-content: center; align-items: center; height: 100vh;"><div class="loader"></div></div>';
  21.  
  22. GM_addStyle(`
  23. .loader {
  24. border: 16px solid #f3f3f3;
  25. border-top: 16px solid #3498db;
  26. border-radius: 50%;
  27. width: 120px;
  28. height: 120px;
  29. animation: spin 0.5s linear infinite;
  30. }
  31. @keyframes spin {
  32. 0% { transform: rotate(0deg); }
  33. 100% { transform: rotate(360deg); }
  34. }
  35. `);
  36.  
  37. // Create the new URL by replacing 'leetcode.cn' with 'leetcode.com'
  38. var newUrl = window.location.href.replace('leetcode.cn', 'leetcode.com');
  39.  
  40. // Redirect to the new URL after a short delay to show the animation
  41. setTimeout(function() {
  42. window.location.href = newUrl;
  43. }, 1); // Adjust the time as needed
  44. }
  45. })();