Remove Yandex Redirect

Remove Yandex redirect in search, news and mail

目前為 2016-08-30 提交的版本,檢視 最新版本

// ==UserScript==
// @name            Remove Yandex Redirect
// @name:ru         Удаление редиректов на Яндексе
// @namespace       FIX
// @version         0.3
// @description     Remove Yandex redirect in search, news and mail
// @description:ru  Удаление редиректов на Яндексе в поисковой выдаче, новостях и почте
// @author          raletag
// @include         *://yandex.*/search/*
// @include         *://news.yandex.*/*
// @include         *://mail.yandex.*/*
// @grant           unsafeWindow
// ==/UserScript==

(function() {
    'use strict';
    var win = unsafeWindow || window, remove;
    if (win.top !== win.self) return;

    console.time('Remove Yandex Redirect load');

    function insearch (e) {
        var links = e.querySelectorAll('a[onmousedown*="/clck/jsredir"]');
        for (var i = links.length - 1; i >= 0; --i) {
            links[i].removeAttribute('onmousedown');
        }
    }

    function innews (e) {
        var links = e.querySelectorAll('a[data-counter]');
        for (var i = links.length - 1; i >= 0; --i) {
            links[i].removeAttribute('data-counter');
            links[i].removeAttribute('data-bem');
        }
    }

    function inmail (e) {
        var links = e.querySelectorAll('a[data-vdir-href]');
        for (var i = links.length - 1; i >= 0; --i) {
            links[i].removeAttribute('data-vdir-href');
            links[i].removeAttribute('data-orig-href');
        }
    }
    if (win.location.hostname.match(/^news\.yandex/i)) {
        remove = innews;
    } if (win.location.hostname.match(/^mail\.yandex/i)) {
        remove = inmail;
    } else {
        remove = insearch;
    }

    remove (document);

    var o = new MutationObserver(function(ms){
        ms.forEach(function(m){
            m.addedNodes.forEach(function(n){
                if (n.nodeType !== Node.ELEMENT_NODE) {
                    return;
                }
                remove(n);
            });
        });
    });
    o.observe(document.body, {childList: true, subtree: true});

    console.timeEnd('Remove Yandex Redirect load');
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址