Youtube Show Channel Name In Title

Show channel's name (username) in title page

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

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