Desidime Redirect Removal

Desidime Remove Tracking

当前为 2023-10-09 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Desidime Redirect Removal
// @version       3
// @run-at        document-start
// @description   Desidime Remove Tracking
// @include       https://www.desidime.com/*
// @author        MaskedWarrior
// @license MIT
// @namespace https://greasyfork.org/users/878597
// @run-at       document-end

// ==/UserScript==
function fixDesiDimeLinks() {
    // Find and update links in anchor tags
    const anchorLinks = document.querySelectorAll("a[href*='links?ref']");
    anchorLinks.forEach((link) => {
        const originalURL = new URL(link.href).searchParams.get('url');
        if (originalURL) {
            link.href = decodeURIComponent(originalURL);
        }
    });

    // Find and update links in data-href attributes
    const dataHrefLinks = document.querySelectorAll("a[data-href*='links?ref']");
    dataHrefLinks.forEach((link) => {
        const originalURL = new URL(link.getAttribute('data-href')).searchParams.get('url');
        if (originalURL) {
            link.setAttribute('data-href', decodeURIComponent(originalURL));
            link.removeAttribute('target'); // Remove the 'target' attribute
        }
    });
}

// Function to handle DOM changes
function handleDOMChanges(mutationsList) {
    for (const mutation of mutationsList) {
        if (mutation.type === 'attributes' && mutation.attributeName === 'href') {
            // Handle attribute changes (e.g., href attribute)
            fixDesiDimeLinks();
        } else if (mutation.type === 'childList') {
            // Handle changes in the DOM structure (e.g., added nodes)
            fixDesiDimeLinks();
        }
    }
}

// Wrap the MutationObserver setup inside a DOMContentLoaded event listener
document.addEventListener('DOMContentLoaded', () => {
    // Use MutationObserver to detect changes in the document
    const observer = new MutationObserver(handleDOMChanges);

    // Observe changes in the body and its subtree
    observer.observe(document.body, { attributes: true, childList: true, subtree: true });

    // Call fixDesiDimeLinks once when the DOM is ready
    fixDesiDimeLinks();
});