YouTube Check Out Updated Channels

Open channels with updates in new tabs

目前为 2020-09-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Check Out Updated Channels
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Open channels with updates in new tabs
  6. // @author Nathaniel Wu
  7. // @include *www.youtube.com/*
  8. // @license Apache-2.0
  9. // @supportURL https://gist.github.com/Nathaniel-Wu/fabd62df2d6146121fa4b9cfcae08763
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @run-at document-idle
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. function is_channel_updated(channel) {
  19. return window.getComputedStyle(channel.querySelector('div#newness-dot')).display == "block";
  20. }
  21. function check_for_updates(subscriptions) {
  22. subscriptions.querySelectorAll('ytd-guide-entry-renderer').forEach(channel => {
  23. if (is_channel_updated(channel)) {
  24. let link = channel.querySelector('a').href;
  25. if (!Boolean(link.match(/\/videos($|\/$)/)))
  26. link += '/videos'
  27. window.open(link);
  28. }
  29. });
  30. }
  31. function checkout_updated_channels() {
  32. let subscriptions = document.querySelector('div#content > app-drawer#guide div#sections > ytd-guide-section-renderer:nth-of-type(2) > div#items');//subject to change
  33. if (subscriptions == null)
  34. return false;
  35. let channels = subscriptions.querySelectorAll(':scope > ytd-guide-entry-renderer');
  36. if (is_channel_updated(channels[channels.length - 1])) {
  37. let active_DOMNodeInsertion = 0;
  38. subscriptions.addEventListener("DOMNodeInserted", () => {
  39. active_DOMNodeInsertion++;
  40. setTimeout(() => {
  41. active_DOMNodeInsertion--;
  42. if (active_DOMNodeInsertion == 0)
  43. check_for_updates(subscriptions);
  44. }, 20);
  45. });
  46. subscriptions.querySelector('ytd-guide-collapsible-entry-renderer > ytd-guide-entry-renderer#expander-item').click();
  47. } else
  48. check_for_updates(subscriptions);
  49. return true;
  50. }
  51. function repeat_until_successful(function_ptr, interval) {
  52. if (!function_ptr())
  53. setTimeout(() => {
  54. repeat_until_successful(function_ptr, interval);
  55. }, interval);
  56. }
  57. function in_iframe() {
  58. try {
  59. return window.self !== window.top;
  60. } catch (e) {
  61. return true;
  62. }
  63. }
  64. if (!in_iframe()) {
  65. let timestamp_now = (new Date()).getTime();
  66. let timestamp_last_check = GM_getValue('timestampLastYouTubeUpdateCheck', Number.MIN_SAFE_INTEGER);
  67. if (timestamp_last_check < 0 || timestamp_now - timestamp_last_check > 600000/* 10 minutes */)
  68. GM_setValue('timestampLastYouTubeUpdateCheck', timestamp_now);
  69. else
  70. return;
  71. repeat_until_successful(checkout_updated_channels, 100);
  72. }
  73. })();