Youtube Show Channel Name In Title

Show channel's name (username) in title page

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