To SiIvaGunner Wiki

View a rip on the SiIvaGunner Wiki in one click!

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         To SiIvaGunner Wiki
// @namespace    https://greasyfork.org/users/1201646
// @version      1.0.2
// @description  View a rip on the SiIvaGunner Wiki in one click!
// @author       lemocha
// @match        https://www.youtube.com/*
// @icon         https://static.wikia.nocookie.net/siivagunner/images/4/4a/Site-favicon.ico
// @grant        GM_registerMenuCommand
// @run-at       document-idle
// @license      MIT
// ==/UserScript==


(() =>
{
	"use strict";
	// register menu command
	GM_registerMenuCommand("To SiIva Wiki", () => redirect("https://siivagunner.fandom.com/wiki/"));

	function redirect(url)
	{
		// get rip title based on youtube document title
		let title = document.title.split(" - YouTube")[0];

		// remove notification count in document title if present
		if (title.charAt(0) === "(" && /[0-9]/.test(title.charAt(1)))
		{
			title = title.slice(title.indexOf(") ") + 2);
		}

		// replace certain characters so link is URL safe
		title = title.replaceAll("?", "%3F");
		title = title.replaceAll(" ", "_");
		title = title.replaceAll("[", "(");
		title = title.replaceAll("]", ")");
		title = title.replaceAll("#", "");

		// open wiki page in new tab
		const a = document.createElement("a");
		a.href = url + title;
		a.target = "_blank";
		a.click();
	}
})();