Youtube Music song-name helper

Make craftwar's obs plugin (https://craftwarblog.blogspot.com/2018/01/obs-plugin-playing-song.html) able to get song name.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @author craftwar
// @name Youtube Music song-name helper
// @description Make craftwar's obs plugin (https://craftwarblog.blogspot.com/2018/01/obs-plugin-playing-song.html) able to get song name.
// @copyright 2021, craftwar (https://craftwarblog.blogspot.com/)
// @license GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0.txt
// @homepageURL https://github.com/craftwar/userscript/tree/master/Youtube-Music-song-name-helper
// @version 0.1.20210120
// @namespace github.com.craftwar
// @match https://music.youtube.com/*
// @grant none
// @run-at document-end
// @inject-into content
// ==/UserScript==
// inject-into content for Violentmonkey, default mode page is not working
// ref: https://violentmonkey.github.io/2018/11/23/inject-into-context/
//make webhook wowrks
'use strict';
(() => {
	const suffixes = [" - YouTube Music"];
	const fake_suffix = " - YouTube";
	const fix_suffix = () => {
		if (!document.title.endsWith(fake_suffix)) {
			for (const suffix of suffixes) {
				if (document.title.endsWith(suffix)) {
					document.title = document.title.substring(0, document.title.length - suffix.length) + fake_suffix;
					break;
				}
			}
		}
	}

	const title_element = document.querySelector("title");
	const track_observer = new MutationObserver(fix_suffix);
	track_observer.observe(title_element, { childList: true });
	fix_suffix();
})();