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.2
  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. // ==/UserScript==
  13.  
  14. (function() {
  15. "use strict";
  16.  
  17. var channelName;
  18. function setTitle() {
  19. if (!document.getElementById("owner-name")) {
  20. setTimeout(setTitle, 1000);
  21. return;
  22. }
  23. channelName = document.getElementById("owner-name").textContent.trim();
  24. if (document.title.startsWith(channelName + " | ")) {
  25. return;
  26. }
  27. document.title = channelName + " | " + document.title;
  28. }
  29.  
  30. var observer = new MutationObserver(setTitle);
  31. document.addEventListener("yt-navigate-finish", function () {
  32. if (/^\/watch?/.test(window.location.pathname)) {
  33. observer.observe(document.getElementsByTagName("title")[0], {
  34. childList: true,
  35. attributes: false,
  36. characterData: false,
  37. subtree: false
  38. });
  39. }
  40. else {
  41. observer.disconnect();
  42. if (document.title.startsWith(channelName + " | ")) {
  43. document.title = document.title.replace(channelName + " | ", "");
  44. }
  45. }
  46. }, true);
  47. }());