Guest User

Untitled

a guest
Mar 25th, 2021
26
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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×