LeetCode CN to LeetCode COM Redirector

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

Від 12.01.2024. Дивіться остання версія.

// ==UserScript==
// @name         LeetCode CN to LeetCode COM Redirector
// @namespace    http://tampermonkey.net/
// @version      2024-01-12#2
// @description  Redirect from leetcode.cn to leetcode.com with a loading animation.
// @author       Yuyang Wang
// @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
    }
})();