Desidime Redirect Removal

Remove URL Tracking/Redirects from Desidime.com

当前为 2023-12-16 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴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     4
// @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://cdn0.desidime.com/logo/favicon.ico
// ==/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();
});