Open in the current tab for Yandex

Force to open Yandex search result linx in the same tab. Default behaviour is to open in the new tab.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            Open in the current tab for Yandex
// @name:ru         Открывать в текущей вклакде для Яндекс
// @namespace       FIX
// @version         0.2
// @description     Force to open Yandex search result linx in the same tab. Default behaviour is to open in the new tab.
// @description:ru  Заставляет открывать ссылки в поиске Янедкса в текущей вкладке при нажатии на них. По умолчанию Яндекс открывает их в новой вкладке.
// @author          toverna
// @include         *://yandex.*/*
// @include         *://*.yandex.*/*
// @grant           unsafeWindow
// ==/UserScript==

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

    console.time('Remove Yandex load');

    function removeAttrs (scope) {
        var links = scope.querySelectorAll('a[target="_blank"]');
      	var i;
        for (i = links.length - 1; i >= 0; --i) {
            links[i].removeAttribute('target');
        }
    }

    removeAttrs (document.body);

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

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