Youtube: Show related videos if missing

On pages of age-restricted videos, related videos are missing. This script re-adds the related videos.

  1. // ==UserScript==
  2. // @name Youtube: Show related videos if missing
  3. // @name:de Youtube: Zeige Videovorschläge an, falls sie fehlen
  4. // @namespace tfr
  5. // @description On pages of age-restricted videos, related videos are missing. This script re-adds the related videos.
  6. // @description:de Auf Seiten altersbeschränkter Videos fehlen die Videovorschläge. Dieses Skript fügt sie wieder hinzu.
  7. // @author tfr (https://github.com/t-fr/)
  8. // @license CC0; https://creativecommons.org/publicdomain/zero/1.0/
  9. // @license MIT license; https://pastebin.com/raw.php?i=4TMeeUXC
  10. // @compatible firefox Works with Firefox and Greasemonkey
  11. // @incompatible chrome Does not work with Chrome and Tampermonkey
  12. // @compatible opera Works with Opera and Violent monkey, but not with Tampermonkey Beta
  13. // @oujs:author tfr
  14. // @include http://www.youtube.com/watch?*
  15. // @include https://www.youtube.com/watch?*
  16. // @version 4
  17. // @grant GM_xmlhttpRequest
  18. // ==/UserScript==
  19.  
  20. /* This script is dual-licensed under CC0 and the MIT license.
  21. * You can choose which one you want to use.
  22. * CC0 license: http://creativecommons.org/publicdomain/zero/1.0/deed.en
  23. * MIT license: https://pastebin.com/raw.php?i=4TMeeUXC
  24. *
  25. * Dieses Skript steht sowohl unter CC0 als auch unter der MIT-Lizenz.
  26. * Sie können sich aussuchen, welche Lizenz Sie nutzen.
  27. * CC0-Lizenz: http://creativecommons.org/publicdomain/zero/1.0/deed.de
  28. * MIT-Lizenz: https://pastebin.com/raw.php?i=4TMeeUXC
  29. */
  30.  
  31. /* Version 4: Do not write "by ..." in video title
  32. * Version 3: Update license information
  33. */
  34.  
  35. if (window.document.getElementById('watch7-sidebar-modules') && !window.document.getElementById('watch-related'))
  36. {
  37. var videoid = window.location.search.substr(window.location.search.indexOf('v=') + 2);
  38. if (videoid.indexOf('&') > - 1)
  39. {
  40. videoid = videoid.substr(0, videoid.indexOf('&'));
  41. }
  42. videoid = decodeURIComponent(videoid);
  43. GM_xmlhttpRequest({
  44. method: 'GET',
  45. url: '//www.youtube.com/get_video_info?asv=3&video_id=' + videoid,
  46. onload: function (response)
  47. {
  48. if (response.status == 200)
  49. {
  50. var relatedList = response.responseText.substr(response.responseText.indexOf('rvs=') + 4);
  51. if (relatedList.indexOf('&') > - 1)
  52. {
  53. relatedList = relatedList.substr(0, relatedList.indexOf('&'));
  54. }
  55. relatedList = decodeURIComponent(relatedList);
  56. relatedListS = relatedList.split(',');
  57. var sidebarModules = window.document.getElementById('watch7-sidebar-modules');
  58. var sidebarSection = window.document.createElement('div');
  59. sidebarSection.setAttribute('class', 'watch-sidebar-section');
  60. sidebarModules.appendChild(sidebarSection);
  61. var sidebarBody = window.document.createElement('div');
  62. sidebarBody.setAttribute('class', 'watch-sidebar-body');
  63. sidebarSection.appendChild(sidebarBody);
  64. var relatedVideoList = window.document.createElement('ul');
  65. relatedVideoList.setAttribute('id', 'watch-related');
  66. relatedVideoList.setAttribute('class', 'video-list');
  67. sidebarBody.appendChild(relatedVideoList);
  68. for (var i = 0; i < relatedListS.length; i++)
  69. {
  70. if (relatedListS[i].indexOf('id=') > - 1 && relatedListS[i].indexOf('title=') > - 1 && relatedListS[i].indexOf('author=') > - 1 && relatedListS[i].indexOf('length_seconds=') > - 1)
  71. {
  72. var relatedId = relatedListS[i].substr(relatedListS[i].indexOf('id=') + 3);
  73. if (relatedId.indexOf('&') > - 1)
  74. {
  75. relatedId = relatedId.substr(0, relatedId.indexOf('&'));
  76. }
  77. relatedId = relatedId.replace(/\+/g, ' ');
  78. relatedId = decodeURIComponent(relatedId);
  79. var relatedTitle = relatedListS[i].substr(relatedListS[i].indexOf('title=') + 6);
  80. if (relatedTitle.indexOf('&') > - 1)
  81. {
  82. relatedTitle = relatedTitle.substr(0, relatedTitle.indexOf('&'));
  83. }
  84. relatedTitle = relatedTitle.replace(/\+/g, ' ');
  85. relatedTitle = decodeURIComponent(relatedTitle);
  86. var relatedAuthor = relatedListS[i].substr(relatedListS[i].indexOf('author=') + 7);
  87. if (relatedAuthor.indexOf('&') > - 1)
  88. {
  89. relatedAuthor = relatedAuthor.substr(0, relatedAuthor.indexOf('&'));
  90. }
  91. relatedAuthor = relatedAuthor.replace(/\+/g, ' ');
  92. relatedAuthor = decodeURIComponent(relatedAuthor);
  93. var relatedLength = relatedListS[i].substr(relatedListS[i].indexOf('length_seconds=') + 15);
  94. if (relatedLength.indexOf('&') > - 1)
  95. {
  96. relatedLength = relatedLength.substr(0, relatedLength.indexOf('&'));
  97. }
  98. relatedLength = relatedLength.replace(/\+/g, ' ');
  99. relatedLength = decodeURIComponent(relatedLength);
  100. var relatedLengthRest = parseInt(relatedLength);
  101. var relatedLengthStr = ':' + ((relatedLengthRest % 60) < 10 ? '0' : '') + (relatedLengthRest % 60).toString();
  102. relatedLengthRest = Math.floor(relatedLengthRest / 60);
  103. relatedLengthStr = (relatedLengthRest >= 60 && (relatedLengthRest % 60) < 10 ? '0' : '') + (relatedLengthRest % 60).toString() + relatedLengthStr;
  104. relatedLengthRest = Math.floor(relatedLengthRest / 60);
  105. relatedLengthStr = (relatedLengthRest > 0 ? relatedLengthRest.toString() + ':' + relatedLengthStr : relatedLengthStr);
  106. var listElem = window.document.createElement('li');
  107. listElem.setAttribute('class', 'video-list-item related-list-item show-video-time related-list-item-compact-video');
  108. relatedVideoList.appendChild(listElem);
  109. var listElemCont = window.document.createElement('div');
  110. listElemCont.setAttribute('class', 'content-wrapper');
  111. listElem.appendChild(listElemCont);
  112. var listElemContLink = window.document.createElement('a');
  113. listElemContLink.setAttribute('class', 'yt-uix-sessionlink content-link');
  114. listElemContLink.setAttribute('title', relatedTitle);
  115. listElemContLink.setAttribute('href', 'https://www.youtube.com/watch?v=' + relatedId);
  116. listElemCont.appendChild(listElemContLink);
  117. var listElemContLinkSpan1 = window.document.createElement('span');
  118. listElemContLinkSpan1.setAttribute('class', 'title');
  119. listElemContLinkSpan1.setAttribute('aria-describedby', 'description-id-' + i);
  120. listElemContLinkSpan1.appendChild(window.document.createTextNode(relatedTitle));
  121. listElemContLink.appendChild(listElemContLinkSpan1);
  122. var listElemContLinkSpan2 = window.document.createElement('span');
  123. listElemContLinkSpan2.setAttribute('id', 'description-id-' + i);
  124. listElemContLinkSpan2.setAttribute('class', 'accessible-description');
  125. listElemContLinkSpan2.appendChild(window.document.createTextNode((navigator.language.toLowerCase().substr(0, 2) == 'de' ? '- Dauer: ' : '- Duration: ') + relatedLengthStr));
  126. listElemContLink.appendChild(listElemContLinkSpan2);
  127. var listElemContLinkSpan3 = window.document.createElement('span');
  128. listElemContLinkSpan3.setAttribute('class', 'stat attribution');
  129. listElemContLinkSpan3.appendChild(window.document.createTextNode((navigator.language.toLowerCase().substr(0, 2) == 'de' ? 'von ' : 'by ') + relatedAuthor));
  130. listElemContLink.appendChild(listElemContLinkSpan3);
  131. var listElemThum = window.document.createElement('div');
  132. listElemThum.setAttribute('class', 'thumb-wrapper');
  133. listElem.appendChild(listElemThum);
  134. var listElemThumLink = window.document.createElement('a');
  135. listElemThumLink.setAttribute('class', 'yt-uix-sessionlink thumb-link');
  136. listElemThumLink.setAttribute('aria-hidden', 'true');
  137. listElemThumLink.setAttribute('tabindex', '-1');
  138. listElemThumLink.setAttribute('href', 'https://www.youtube.com/watch?v=' + relatedId);
  139. listElemThum.appendChild(listElemThumLink);
  140. var listElemThumLinkSpan = window.document.createElement('span');
  141. listElemThumLinkSpan.setAttribute('class', 'yt-uix-simple-thumb-wrap yt-uix-simple-thumb-related');
  142. listElemThumLinkSpan.setAttribute('data-vid', relatedId);
  143. listElemThumLinkSpan.setAttribute('tabindex', '0');
  144. listElemThumLink.appendChild(listElemThumLinkSpan);
  145. var listElemThumImg = window.document.createElement('img');
  146. listElemThumImg.setAttribute('width', '120');
  147. listElemThumImg.setAttribute('height', '90');
  148. listElemThumImg.setAttribute('aria-hidden', 'true');
  149. listElemThumImg.setAttribute('alt', '');
  150. listElemThumImg.setAttribute('src', '//i.ytimg.com/vi/' + relatedId + '/default.jpg');
  151. listElemThumLinkSpan.appendChild(listElemThumImg);
  152. }
  153. }
  154. }
  155. }
  156. });
  157. }

QingJ © 2025

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