Avoid Yandex Turbo

Redirect directly to target page avoiding Yandex Turbo

当前为 2020-11-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Avoid Yandex Turbo
  3. // @name:ru Обход Яндекс Турбо
  4. // @description Redirect directly to target page avoiding Yandex Turbo
  5. // @description:ru Переадресация на целевую страницу в обход Яндекс Турбо
  6. // @author Autapomorph
  7. // @version 2.0.0
  8. // @run-at document_start
  9. // @match *://yandex.ru/*
  10. // @match *://*.turbopages.org/*
  11. // @supportURL https://github.com/Autapomorph/userscripts/issues
  12. // @license MIT
  13. // @namespace https://greasyfork.org/users/689919
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. function redirectWithTurboOverlay() {
  18. var titleHostActive = $('.turbo-overlay__title-host_active');
  19. if (!titleHostActive || !titleHostActive.length) {
  20. return;
  21. }
  22.  
  23. var titleHostActiveText = titleHostActive[0].textContent;
  24. if (!titleHostActiveText.length) {
  25. return;
  26. }
  27.  
  28. var hostLinks = $('a[data-sc-host]');
  29. for (var i = 0; i < hostLinks.length; i += 1) {
  30. var hostLink = $(hostLinks[i]);
  31. var dataCounter;
  32. try {
  33. dataCounter = JSON.parse(hostLink.attr('data-counter'));
  34. } catch (error) {
  35. return;
  36. }
  37.  
  38. if (dataCounter.find(e => e.indexOf(titleHostActiveText) > -1)) {
  39. var redirect;
  40. if (dataCounter[0] === 'b') {
  41. redirect = dataCounter[1];
  42. } else if (dataCounter[0] === 'w') {
  43. redirect = dataCounter[3];
  44. } else {
  45. return;
  46. }
  47. top.location.replace(redirect);
  48. }
  49. }
  50.  
  51. $('a[data-sc-host]').each(function () {
  52. var dataCounterAttr = $(this).attr('data-counter');
  53. if (!dataCounterAttr) return;
  54.  
  55. var dataCounter = JSON.parse(dataCounterAttr);
  56. if (dataCounter.find(e => e.indexOf(titleHostActiveText) > -1)) {
  57. var redirect;
  58. if (dataCounter[0] === 'b') {
  59. redirect = dataCounter[1];
  60. } else if (dataCounter[0] === 'w') {
  61. redirect = dataCounter[3];
  62. }
  63. top.location.replace(redirect);
  64. }
  65. });
  66. }
  67.  
  68. function redirectWithURL() {
  69. var urlPathname = top.location.pathname;
  70. var turboIndex = urlPathname.indexOf('/turbo/');
  71. var delimeterIndex = urlPathname.search(/\/(s|h)/);
  72. var delimeterLength = 2;
  73.  
  74. if (delimeterIndex < 0) {
  75. return;
  76. }
  77. var host =
  78. turboIndex === -1
  79. ? urlPathname.substring(1, delimeterIndex)
  80. : urlPathname.substring(turboIndex + '/turbo/'.length, delimeterIndex);
  81. var pathName = urlPathname.substring(delimeterIndex + delimeterLength);
  82. top.location.replace('//' + host + pathName);
  83. }
  84.  
  85. var urlPathname = top.location.pathname;
  86. if (/\.*\/(s|h)\/.*/.test(urlPathname)) {
  87. redirectWithTurboOverlay();
  88. redirectWithURL();
  89. }
  90. })();