YouTube RSS Feed

Adds an RSS feed button to YouTube channels next to the subscribe button

当前为 2015-04-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube RSS Feed
  3. // @namespace http://greasyfork.org/users/2240-doodles
  4. // @author Doodles
  5. // @version 11
  6. // @description Adds an RSS feed button to YouTube channels next to the subscribe button
  7. // @icon http://i.imgur.com/Ty5HNbT.png
  8. // @icon64 http://i.imgur.com/1FfVvNr.png
  9. // @include *://*youtube.*/*
  10. // @grant none
  11. // @run-at document-end
  12. // @updateVersion 11
  13. // ==/UserScript==
  14.  
  15. // Using a work-around to use jQuery, and be compatible with Chrome
  16. // Found here: http://stackoverflow.com/a/3550261
  17.  
  18. (function() {
  19. function addJQuery(callback){
  20. var script = document.createElement("script");
  21. script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js");
  22. script.addEventListener('load', function(){
  23. var script = document.createElement("script");
  24. script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
  25. document.body.appendChild(script);
  26. }, false);
  27. document.body.appendChild(script);
  28. }
  29. function RssFeedButton(){
  30. // YouTube page load fix, so script runs properly on every page
  31. jQ('a').click(function( event ) {
  32. event.preventDefault();
  33. window.location = jQ(this).attr("href");
  34. });
  35. // NOTE: this is a horrible solution, but everything else I tried didnt work 100% of the time
  36. // Discussion of this problem found here: http://stackoverflow.com/a/21146511
  37. var rssFeedNew = "feed://www.youtube.com/feeds/videos.xml?channel_id=";
  38. var rssFeed = "nope";
  39. if(document.URL.indexOf("/user/") != -1 || document.URL.indexOf("/channel/") != -1){
  40. var metaId = jQ("meta[itemprop='channelId']");
  41. if(metaId.length != 0){
  42. rssFeed = rssFeedNew + jQ(metaId[0]).attr("content");
  43. }else{
  44. var linkRss = jQ("link[title='RSS']");
  45. if(linkRss.length != 0){
  46. rssFeed = jQ(linkRss[0]).attr("href");
  47. if(rssFeed.startsWith("https")){
  48. rssFeed = "feed" + rssFeed.substring(5);
  49. }else if(rssFeed.startsWith("http")){
  50. rssFeed = "feed" + rssFeed.substring(4);
  51. }
  52. }
  53. }
  54. }else if(document.URL.indexOf("/watch") != -1 && document.URL.indexOf("v=") != -1){
  55. var metaId = jQ("meta[itemprop='channelId']");
  56. if(metaId.length != 0){
  57. rssFeed = rssFeedNew + jQ(metaId[0]).attr("content");
  58. }
  59. }
  60. if(rssFeed != "nope"){
  61. var button = document.createElement('button');
  62. button.setAttribute('class', 'yt-uix-button yt-uix-button-size-default yt-uix-button-subscribe-branded yt-uix-button-has-icon no-icon-markup yt-uix-subscription-button yt-can-buffer');
  63. button.setAttribute('onclick', "parent.location='" + rssFeed + "'");
  64. var outerSpan = document.createElement('span');
  65. outerSpan.setAttribute('class', 'yt-uix-button-content');
  66. var innerSpan = document.createElement('span');
  67. innerSpan.setAttribute('class', 'subscribe-label');
  68. innerSpan.appendChild(document.createTextNode('RSS Subscribe '));
  69. button.appendChild(outerSpan);
  70. outerSpan.appendChild(innerSpan);
  71. jQ(button).css("background", "linear-gradient(#fd9b12, #fe6702)");
  72. jQ(button).mouseover(function(){ jQ(this).css("background", "linear-gradient(#fe6702, #fd9b12)"); });
  73. jQ(button).mouseout(function(){ jQ(this).css("background", "linear-gradient(#fd9b12, #fe6702)"); });
  74. if(document.URL.indexOf("/user/") != -1 || document.URL.indexOf("/channel/") != -1){
  75. var header = document.getElementById('c4-primary-header-contents');
  76. if(header != null){
  77. var divs = header.getElementsByTagName('span');
  78. for(var i = 0; i < divs.length;i++){
  79. var cl = divs.item(i).getAttribute('class');
  80. if(cl.indexOf("channel-header-subscription-button-container") != -1){
  81. var firstButton = divs.item(i).getElementsByTagName('button')[0];
  82. divs.item(i).insertBefore(button, firstButton);
  83. var spacer = document.createTextNode(" ");
  84. divs.item(i).insertBefore(spacer, firstButton);
  85. }
  86. }
  87. }
  88. }else if(document.URL.indexOf("/watch") != -1 && document.URL.indexOf("v=") != -1){
  89. var header = document.getElementById('watch7-subscription-container');
  90. if(header != null){
  91. var properSpan = header.getElementsByTagName('span')[0];
  92. properSpan.insertBefore(document.createTextNode(" "), properSpan.firstChild);
  93. properSpan.insertBefore(button, properSpan.firstChild);
  94. }
  95. }
  96. }
  97. }
  98. addJQuery(RssFeedButton);
  99. })();