Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Tabs Title Fix
- // @namespace abu_pidor
- // @match *://*.youtube.com/*
- // @match *://*.spotify.com/*
- // @run-at document-start
- // ==/UserScript==
- "use strict";
- let regex;
- const origDesc = Object.getOwnPropertyDescriptor(unsafeWindow.Document.prototype, "title");
- switch (location.hostname.match(/[^.]+\.[^.]+$/)[0]) {
- case "youtube.com":
- regex = / - YouTube$/;
- break;
- case "spotify.com":
- regex = /^Spotify – /;
- break;
- }
- Object.defineProperty(unsafeWindow.Document.prototype, "title", {
- get: origDesc.get,
- set(title) {
- origDesc.set.call(this, cleanTitle(title, regex));
- }
- });
- document.addEventListener("DOMContentLoaded", () => {
- document.title = cleanTitle(document.title, regex);
- });
- function cleanTitle(title, regex) {
- return title.replace(regex, "");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement