Greasy Fork 还支持 简体中文。

Youtube Show Channel Name In Title

Show channel's name (username) in title page

目前為 2018-06-06 提交的版本,檢視 最新版本

  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.231
  6. // @description Show channel's name (username) in title page
  7. // @author AleksT.
  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-name");
  22. if (!(/^\/watch?/).test(window.location.pathname)) {
  23. return;
  24. }
  25. if (!ownerName || ownerName.textContent.length === 0) {
  26. setTimeout(function () {
  27. setTitle();
  28. }, 1000);
  29. return;
  30. }
  31. channelName = ownerName.textContent.trim();
  32. if (document.title.startsWith(channelName + " | ")) {
  33. return;
  34. }
  35. document.title = channelName + " | " + document.title;
  36. }
  37. const observer = new MutationObserver(setTitle);
  38. document.addEventListener("yt-navigate-finish", function () {
  39. if (/^\/watch?/.test(window.location.pathname)) {
  40. observer.observe(document.getElementsByTagName("title")[0], {
  41. childList: true,
  42. attributes: false,
  43. characterData: false,
  44. subtree: false
  45. });
  46. } else {
  47. observer.disconnect();
  48. if (document.title.startsWith(channelName + " | ")) {
  49. document.title = document.title.replace(channelName + " | ", "");
  50. }
  51. }
  52. }, false);
  53. }());