Youtube favorites channels

Highlights videos of the channels that you mark as favorite (only for Grid view). Tap the heart icon on the channel page to add it to your favorites.

目前为 2021-09-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube favorites channels
  3. // @name:ru Избранные каналы Youtube
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1
  6. // @description Highlights videos of the channels that you mark as favorite (only for Grid view). Tap the heart icon on the channel page to add it to your favorites.
  7. // @description:ru Выделяет видео избранных каналов среди остальных (только в режиме Сетки). Нажмите значок сердца на странице канала, чтобы добавить его в избранное.
  8. // @author dark1103
  9. // @include https://www.youtube.com/*
  10. // @icon https://www.google.com/s2/favicons?domain=youtube.com
  11. // @require http://code.jquery.com/jquery-3.4.1.min.js
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. var bg_color = 'lightgoldenrodyellow';
  19.  
  20.  
  21.  
  22. function getFav(){
  23. var fav = GM_getValue("fav1");
  24. if(fav === undefined){
  25. fav = [];
  26. }
  27. return fav;
  28. }
  29.  
  30. function onLoaded(){
  31. var name = $('#channel-name #text').eq(0).text();
  32. var isFav = getFav().includes(name);
  33. $('#fav-button').remove();
  34. var node = $('<div id="fav-button" class="style-scope ytd-c4-tabbed-header-renderer" style="line-height: 38px;font-size: large;cursor: pointer;">' + (isFav ? '💖' : '🤍') + '</div>');
  35. node.appendTo($('#inner-header-container #buttons'));
  36.  
  37. node.on('click', function(){
  38.  
  39. var fav = getFav();
  40.  
  41. if(isFav){
  42. fav = fav.filter(item => item !== name);
  43. isFav = false;
  44. }else{
  45. fav.push(name);
  46. isFav = true;
  47. }
  48.  
  49. $('#fav-button').html(isFav ? '💖' : '🤍');
  50. GM_setValue("fav1", fav);
  51. });
  52.  
  53. }
  54. function highlightFav(){
  55. if(location.href === 'https://www.youtube.com/feed/subscriptions'){
  56. var fav = getFav();
  57. $('ytd-grid-video-renderer').filter(function(){
  58. var name = $(this).find('#channel-name #text').text();
  59. return fav.includes(name);
  60. }).css('background-color', bg_color);
  61. }
  62. }
  63.  
  64. function createMutationListener(){
  65. var target = document.querySelector('body')
  66.  
  67. // Create an observer instance linked to the callback function
  68. const observer2 = new MutationObserver(function(mutationsList, observer) {
  69. // Use traditional 'for loops' for IE 11
  70. for(const mutation of mutationsList) {
  71. if (mutation.type === 'childList') {
  72. var target = $(mutation.target);
  73. //console.log(target);
  74. if(target.prop("tagName") === 'ytd-thumbnail-overlay-time-status-renderer'.toUpperCase()){
  75. highlightFav();
  76. }
  77. }
  78. }
  79. });
  80.  
  81. // Start observing the target node for configured mutations
  82. observer2.observe(target, { attributes: true, childList: true, subtree: true });
  83. }
  84.  
  85. $(document).ready(function(){
  86. onLoaded();
  87. highlightFav();
  88. createMutationListener();
  89. });
  90.  
  91.  
  92. var oldHref = document.location.href;
  93. var bodyList = document.querySelector("body")
  94. ,observer = new MutationObserver(function(mutations) {
  95.  
  96. mutations.forEach(function(mutation) {
  97.  
  98. if (oldHref != document.location.href) {
  99. oldHref = document.location.href;
  100. onLoaded();
  101. highlightFav();
  102. }
  103.  
  104. });
  105.  
  106. });
  107.  
  108. observer.observe(bodyList, {
  109. childList: true,
  110. subtree: true
  111. });
  112.  
  113. })();

QingJ © 2025

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