LeetCode CN to COM Redirect with Loading Animation

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

As of 12.01.2024. See ბოლო ვერსია.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         LeetCode CN to COM Redirect with Loading Animation
// @namespace    http://tampermonkey.net/
// @version      2024-01-12
// @description  Redirect from leetcode.cn to leetcode.com with a loading animation.
// @author       You
// @match        *://leetcode.cn/*
// @match        *://leetcode.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Check if the current URL is from leetcode.cn
    if (window.location.host === 'leetcode.cn') {
        // Add a simple loading animation to the body
        document.body.innerHTML = '<div style="display: flex; justify-content: center; align-items: center; height: 100vh;"><div class="loader"></div></div>';

        GM_addStyle(`
            .loader {
                border: 16px solid #f3f3f3;
                border-top: 16px solid #3498db;
                border-radius: 50%;
                width: 120px;
                height: 120px;
                animation: spin 0.5s linear infinite;
            }
            @keyframes spin {
                0% { transform: rotate(0deg); }
                100% { transform: rotate(360deg); }
            }
        `);

        // Create the new URL by replacing 'leetcode.cn' with 'leetcode.com'
        var newUrl = window.location.href.replace('leetcode.cn', 'leetcode.com');

        // Redirect to the new URL after a short delay to show the animation
        setTimeout(function() {
            window.location.href = newUrl;
        }, 1); // Adjust the time as needed
    }
})();