Remove Yandex Turbo

Redirect directly to target page avoiding Yandex Turbo

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Remove Yandex Turbo
// @name:ru-RU Удалить Яндекс Турбо
// @description Redirect directly to target page avoiding Yandex Turbo
// @description:ru-RU Переадресация на целевую страницу в обход Яндекс Турбо
// @author Autapomorph
// @version 1.0.3
// @run-at document_start
// @match https://yandex.ru/*
// @supportURL https://github.com/Autapomorph/yandex-turbo-remover/issues
// @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;

if (urlPathname === '/turbo') {
  top.location.replace(decodeURIComponent(urlLandingPage['text']));
} else if (/\/turbo\/.*\/s\/.*/.test(urlPathname)) {
  var turboIndex = urlPathname.indexOf('/turbo/');
  var sIndex = urlPathname.indexOf('/s/');
  var host = urlPathname.substring(turboIndex + '/turbo/'.length, sIndex);
  var pathName = urlPathname.substring(sIndex + '/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';
  }
};