Advertisement
Guest User

Untitled

a guest
Mar 25th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name Tabs Title Fix
  3. // @namespace abu_pidor
  4. // @match *://*.youtube.com/*
  5. // @match *://*.spotify.com/*
  6. // @run-at document-start
  7. // ==/UserScript==
  8.  
  9. "use strict";
  10. let regex;
  11. const origDesc = Object.getOwnPropertyDescriptor(unsafeWindow.Document.prototype, "title");
  12.  
  13. switch (location.hostname.match(/[^.]+\.[^.]+$/)[0]) {
  14.     case "youtube.com":
  15.         regex = / - YouTube$/;
  16.         break;
  17.     case "spotify.com":
  18.         regex = /^Spotify – /;
  19.         break;
  20. }
  21.  
  22. Object.defineProperty(unsafeWindow.Document.prototype, "title", {
  23.     get: origDesc.get,
  24.     set(title) {
  25.         origDesc.set.call(this, cleanTitle(title, regex));
  26.     }
  27. });
  28.  
  29. document.addEventListener("DOMContentLoaded", () => {
  30.     document.title = cleanTitle(document.title, regex);
  31. });
  32.  
  33. function cleanTitle(title, regex) {
  34.     return title.replace(regex, "");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement