Youtube Show Channel Name In Title

Show channel's name (username) in title page

当前为 2018-05-24 提交的版本,查看 最新版本

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