Calm Down YouTube

Converts titles on YouTube to be less obnoxious.

  1. // ==UserScript==
  2. // @name Calm Down YouTube
  3. // @version 1.3
  4. // @description Converts titles on YouTube to be less obnoxious.
  5. // @author Ryan Poole
  6. // @match *://www.youtube.com/*
  7. // @run-at document-start
  8. // @namespace https://greasyfork.org/users/48078
  9. // ==/UserScript==
  10.  
  11. var channels = ['Hat Films', 'YOGSCAST Lewis & Simon'];
  12.  
  13. var acronyms = ['GTA', 'TTT'];
  14.  
  15. function transformTitle (title) {
  16. var splitTitle = /(.*?)(\((.*)\))?$/.exec(title.trim());
  17. var gameName = splitTitle[3];
  18. var videoName = splitTitle[1];
  19. var newName = ((gameName ? gameName.trim() + " - " : "") + videoName.trim()).toLowerCase();
  20. acronyms.forEach(function(a) {
  21. newName = newName.replace(a.toLowerCase(), a.toUpperCase());
  22. });
  23. return newName;
  24. }
  25.  
  26. var observer = new MutationObserver(parsePage);
  27.  
  28. function onPageLoad () {
  29. setupObservers();
  30. parsePage();
  31. }
  32.  
  33. function setupObservers () {
  34. observer.disconnect();
  35. var elsToObserve = ['.section-list', '.branded-page-v2-body', '.channels-browse-content-grid', '#pl-load-more-destination', '#watch-more-related'];
  36. var el;
  37. elsToObserve.forEach(function(elName) {
  38. if ((el = document.querySelector(elName)) !== null) {
  39. observer.observe(el, {childList:true});
  40. }
  41. });
  42. }
  43.  
  44. function parsePage () {
  45. var titleEls = [];
  46.  
  47. var pageChannelNameEl = document.querySelector('.branded-page-header-title-link');
  48.  
  49. function parseDOMList (opts) {
  50. var listSelector = opts.list || null;
  51. var nameSelector = opts.name || null;
  52. var titleSelector = opts.title || null;
  53. var videos = document.querySelectorAll(listSelector);
  54. for (var i = 0; i < videos.length; i++) {
  55. var currentVideoEl = videos[i];
  56. var currentNameEl = currentVideoEl.querySelector(nameSelector);
  57. var channelName = (currentNameEl !== null ? currentNameEl.textContent : null) || (pageChannelNameEl !== null ? pageChannelNameEl.text : null) || null;
  58. if (channelName === null) {
  59. continue;
  60. }
  61. if (channels.includes(channelName)) {
  62. titleEls.push(currentVideoEl.querySelector(titleSelector));
  63. }
  64. }
  65. }
  66.  
  67. parseDOMList({
  68. list:'.yt-lockup-content',
  69. name:'.yt-lockup-byline>a',
  70. title:'.yt-lockup-title>a'
  71. });
  72.  
  73. parseDOMList({
  74. list:'.lohp-media-object-content',
  75. name:'.content-uploader>a',
  76. title:'.lohp-video-link'
  77. });
  78.  
  79. parseDOMList({
  80. list:'.pl-video',
  81. name:'.pl-video-owner>a',
  82. title:'.pl-video-title>a'
  83. });
  84.  
  85. parseDOMList({
  86. list:'.video-list-item',
  87. name:'.g-hovercard',
  88. title:'.title'
  89. });
  90.  
  91. parseDOMList({
  92. list:'.playlist-video',
  93. name:'.video-uploader-byline>span',
  94. title:'h4'
  95. });
  96.  
  97. parseDOMList({
  98. list:'.video-detail',
  99. title:'h3>a'
  100. });
  101.  
  102. parseDOMList({
  103. list:'.lohp-large-shelf-container',
  104. name:'.content-uploader>a',
  105. title:'.lohp-video-link'
  106. });
  107.  
  108. for (i = 0; i < titleEls.length; i++) {
  109. var titleEl = titleEls[i];
  110. if (titleEl.getAttribute("data-parsed" === "true")) {
  111. continue;
  112. }
  113. titleEl.style.textTransform = 'capitalize';
  114. titleEl.setAttribute("data-parsed", true);
  115. titleEl.textContent = transformTitle(titleEl.textContent);
  116. }
  117. }
  118.  
  119. (function() {
  120. 'use strict';
  121. document.addEventListener('spfdone', onPageLoad);
  122. window.addEventListener('DOMContentLoaded', onPageLoad);
  123. })();