Remove Yandex Turbo

Redirect directly to target page avoiding Yandex Turbo

当前为 2020-09-23 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Remove Yandex Turbo
// @description  Redirect directly to target page avoiding Yandex Turbo
// @author       A
// @version      0.0.1
// @run-at       document_start
// @include      https://yandex.ru/*
// @license      MIT
// @namespace https://greasyfork.org/users/689919
// ==/UserScript==

function getUrlVar() {
    var urlVar = window.location.search;
    var arrayVar = [];
    var valueAndKey = [];
    var resultArray = [];
    arrayVar = (urlVar.substr(1)).split('&');
    if (arrayVar[0] == "") return false;
    for (i = 0; i < arrayVar.length; i++) {
        valueAndKey = arrayVar[i].split('=');
        resultArray[valueAndKey[0]] = valueAndKey[1];
    }
    return resultArray;
}

var urlLandingPage = getUrlVar();
var urlPathname = window.location.pathname;
const domainNameRegex = /(?=.{0,253}$)(([a-z0-9_][a-z0-9_-]{0,61}[a-z0-9_]|[a-z0-9_])\.)+((?=.*[^0-9])([a-z0-9][a-z0-9-]{0,61}[a-z0-9]|[a-z0-9]))/g;

if (urlPathname == '/turbo') {
    top.location.replace(decodeURIComponent(urlLandingPage['text']));
} else if (/turbo\/.*\/s\//.test(window.location.pathname)) {
    const host = window.location.pathname.match(domainNameRegex)[0];
    const pathName = window.location.pathname.substr('/turbo/'.length + host.length + '/s'.length);
    top.location.replace('https://' + host + pathName);
} else if (urlPathname.indexOf('/turbo/s/') != -1) {
    top.location.replace('https://' + urlPathname.substr(urlPathname.indexOf('/turbo/s/') + 9));
} else if (urlPathname == '/search/touch/') {
    $('a[data-sc-host]').each(function() {
        var urlYaTurbo = $(this).attr('href');
        var dataCounter = JSON.parse($(this).attr('data-counter'));
        if ((urlYaTurbo.indexOf('https://yandex.ru/turbo/s/') != -1) || (urlYaTurbo.indexOf('https://yandex.ru/turbo?text=') != -1)) {
            $(this).attr('data-bem', '{"link":{}}');
            if (dataCounter[0] == 'b') {
                $(this).attr('href', dataCounter[1]);
            } else if (dataCounter[0] == 'w') {
                $(this).attr('href', dataCounter[3]);
            }
        }
    });
} else if (urlPathname == '/search/') {
    $('a.link').each(function() {
        var dataCounter = JSON.parse($(this).attr('data-counter'));
        if (dataCounter[0] == 'b') {
            $(this).attr('href', dataCounter[1]);
        } else if (dataCounter[0] == 'w') {
            if (typeof(dataCounter[3]) != 'undefined') {
                $(this).hide();
            }
        }
    });
} else if (urlPathname.substr(0, 12) == '/news/story/') {
    var YTsubtitle = document.querySelector('div.news-story__head > a.news-story__subtitle');
    if ((YTsubtitle.href.substr(0, 26) == 'https://yandex.ru/turbo/s/') || (YTsubtitle.href.substr(0, 26) == 'https://yandex.ru/turbo/h/')) {
        YTsubtitle.href = 'https://' + YTsubtitle.href.substring(26, YTsubtitle.href.length).split('?')[0];
    } else {
        YTsubtitle.href = YTsubtitle.href.split('?')[0];
    }
    var YT = document.querySelectorAll('a.news-snippet__url');
    for (var i = 0; i < YT.length; i++) {
        if ((YT[i].href.substr(0, 26) == 'https://yandex.ru/turbo/s/') || (YT[i].href.substr(0, 26) == 'https://yandex.ru/turbo/h/')) {
            YT[i].href = 'https://' + YT[i].href.substring(26, YT[i].href.length).split('?')[0];
        } else {
            YT[i].href = YT[i].href.split('?')[0];
        }
    }
    var YTicon = document.querySelectorAll('svg.news-snippet__turbo-icon');
    for (var i = 0; i < YTicon.length; i++) {
        YTicon[i].style.display = "none";
    }
};