Desidime Redirect Removal

Remove URL Tracking/Redirects from Desidime.com

当前为 2024-11-02 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Desidime Redirect Removal
// @version     5
// @run-at      document-start
// @description Remove URL Tracking/Redirects from Desidime.com
// @include     https://www.desidime.com/*
// @author      kunalagra
// @license     MIT
// @namespace   https://greasyfork.org/users/878597
// @supportURL  https://github.com/kunalagra/
// @run-at      document-end
// @icon        https://play-lh.googleusercontent.com/Xzge4MB_HwymEGmd0iz_6ZOR6tPGaJYqNa1wVwggioBH_JvVoURc5_O-itr3jctyig
// ==/UserScript==

(function() {
    'use strict';

    function fixDesiDimeLinks() {
        document.querySelectorAll("a[data-href*='links?ref']").forEach(link => {;
            try {
                const dataHrefValue = link.getAttribute('data-href');
                const targetURL = decodeURIComponent(new URL(dataHrefValue).searchParams.get('url')) || link.getAttribute('data-href-alt');

                if (targetURL) {
                    link.setAttribute('data-href', targetURL);
                    link.href = targetURL;
                    link.setAttribute('target', '_blank');
                    link.removeAttribute('data-href-alt');
                }
            } catch (error) {
                console.error('Error processing data-href URL:', error);
            }
        });

        // Handle standard 'href' attribute links
        document.querySelectorAll("a[href*='links?ref']").forEach(link => {
            try {
                const originalURL = new URL(link.href, window.location.origin).searchParams.get('url');

                if (originalURL) {
                    link.href = decodeURIComponent(originalURL);
                }
            } catch (error) {
                console.error('Error processing href URL:', error);
            }
        });
    }

    // Debounced handler to avoid excessive calls to fixDesiDimeLinks
    let mutationTimeout;
    function handleDOMChanges(mutationsList) {
        if (mutationTimeout) clearTimeout(mutationTimeout);
        mutationTimeout = setTimeout(() => {
            fixDesiDimeLinks();
        }, 100);
    }

    document.addEventListener('DOMContentLoaded', () => {
        const observer = new MutationObserver(handleDOMChanges);
        observer.observe(document.body, {
            attributes: true,
            childList: true,
            subtree: true
        });
    });
})();