Youtube Show Channel Name In Title

Show channel's name (username) in title page

当前为 2018-06-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Show Channel Name In Title
  3. // @namespace https://github.com/tkhquang
  4. // @version 1.21
  5. // @description Show channel's name (username) in title page
  6. // @author Aleks
  7. // @license MIT; https://raw.githubusercontent.com/tkhquang/userscripts/master/LICENSE
  8. // @homepage https://greasyfork.org/en/scripts/368421-youtube-show-channel-name-in-title
  9. // @match http*://www.youtube.com/*
  10. // @run-at document-start
  11. // @grant none
  12. // @noframes
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. "use strict";
  17.  
  18. var channelName;
  19. function setTitle() {
  20. if (!document.getElementById("owner-name")) {
  21. setTimeout(function() {
  22. setTitle();
  23. }, 2000);
  24. return;
  25. }
  26. channelName = document.getElementById("owner-name").textContent.trim();
  27. if (document.title.startsWith(channelName + " | ")) {
  28. return;
  29. }
  30. document.title = channelName + " | " + document.title;
  31. }
  32.  
  33. var observer = new MutationObserver(setTitle);
  34. document.addEventListener("yt-navigate-finish", function () {
  35. if (/^\/watch?/.test(window.location.pathname)) {
  36. observer.observe(document.getElementsByTagName("title")[0], {
  37. childList: true,
  38. attributes: false,
  39. characterData: false,
  40. subtree: false
  41. });
  42. }
  43. else {
  44. observer.disconnect();
  45. if (document.title.startsWith(channelName + " | ")) {
  46. document.title = document.title.replace(channelName + " | ", "");
  47. }
  48. }
  49. }, true);
  50. }());