URL Decoder and Rewriter Tampermonkey Script

Decodes and rewrites URLs on the current webpage using Tampermonkey script

目前為 2023-08-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         URL Decoder and Rewriter Tampermonkey Script
// @namespace    http://your-namespace-here
// @version      0.1
// @description  Decodes and rewrites URLs on the current webpage using Tampermonkey script
// @author       Your Name
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function decodeAndRewriteUrl(url) {
        const regexMail = /https:\/\/deref-mail\.com\/mail\/client\/([a-zA-Z0-9-_]{11})\/dereferrer\/\?redirectUrl=(.+)/;
        const regexGMX = /https:\/\/deref-gmx\.net\/mail\/client\/([a-zA-Z0-9-_]{11})\/dereferrer\/\?redirectUrl=(.+)/;

        const matchMail = url.match(regexMail);
        const matchGMX = url.match(regexGMX);

        if (matchMail && matchMail[2]) {
            const strippedUrl = matchMail[2];
            const decodedUrl = decodeURIComponent(strippedUrl);
            return decodedUrl;
        }

        if (matchGMX && matchGMX[2]) {
            const strippedUrl = matchGMX[2];
            const decodedUrl = decodeURIComponent(strippedUrl);
            return decodedUrl;
        }

        return null;
    }

    function injectScript(frame) {
        const script = document.createElement('script');
        script.textContent = `
            (function() {
                const links = document.querySelectorAll('a');
                for (const link of links) {
                    const decodedUrl = decodeAndRewriteUrl(link.href);
                    if (decodedUrl) {
                        link.href = decodedUrl;
                    }
                }
            })();
        `;
        frame.contentDocument.head.appendChild(script);
    }

    function handleFrames() {
        const frames = document.querySelectorAll('iframe');
        for (const frame of frames) {
            injectScript(frame);
        }
    }

    // Handle the top-level document
    const links = document.querySelectorAll('a');
    for (const link of links) {
        const decodedUrl = decodeAndRewriteUrl(link.href);
        if (decodedUrl) {
            link.href = decodedUrl;
        }
    }

    // Handle frames
    handleFrames();
})();