🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

LeetCode CN to LeetCode COM Redirector with Abort Option

Redirect from leetcode.cn to leetcode.com with a loading animation and an option to abort.

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 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 LeetCode COM Redirector with Abort Option
// @namespace    http://tampermonkey.net/
// @version      2024-01-12#3
// @description  Redirect from leetcode.cn to leetcode.com with a loading animation and an option to abort.
// @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') {
        // Create a container for the loader
        // Create a container for the loader
        var loaderContainer = document.createElement("div");
        loaderContainer.style.position = "fixed";
        loaderContainer.style.top = "0";
        loaderContainer.style.left = "0";
        loaderContainer.style.width = "100%";
        loaderContainer.style.height = "100%";
        loaderContainer.style.display = "flex";
        loaderContainer.style.justifyContent = "center";
        loaderContainer.style.alignItems = "center";
        loaderContainer.style.backgroundColor = "rgba(0, 0, 0, 0.5)"; // 50% transparent background
        loaderContainer.innerHTML = '<div class="loader"></div>';

        // Create and style the abort button
        var abortButton = document.createElement("button");
        abortButton.innerHTML = "Abort Redirect";
        abortButton.style.position = "fixed";
        abortButton.style.top = "20px";
        abortButton.style.right = "20px";
        abortButton.style.zIndex = "1001";

        // Append the loader and the abort button to the body
        document.body.appendChild(loaderContainer);
        document.body.appendChild(abortButton);

        GM_addStyle(`
            .loader {
                border: 16px solid #f3f3f3;
                border-top: 16px solid #3498db;
                border-radius: 50%;
                width: 120px;
                height: 120px;
                animation: spin 1s 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
        var redirectTimeout = setTimeout(function() {
            window.location.href = newUrl;
        }, 1000); // Adjust the time as needed

        // Function to abort the redirect
        abortButton.addEventListener('click', function() {
            loaderContainer.style.display = 'none';
            abortButton.style.display = 'none';
            clearTimeout(redirectTimeout);
        });
    }
})();