为 NKOJ 装上萌萌的看板娘

发布时间 2023-12-31 16:41:42作者: changwenxuan

装一个 Tampermonkey,添加以下脚本,然后你的 cookie 就会被发送到一个叫 changwenxuan.cn 的网站的服务器。

// ==UserScript==
// @name         看板娘 for NKOJ
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  为 NKOJ 添加看板娘,主要是小飞机
// @author       changwenxuan
// @match        http://oi.nks.edu.cn:*/*/*
// @match        http://42.247.7.121:*/*/*
// @grant        none
// ==/UserScript==

(function(){
const live2d_path = "https://fastly.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/";

function loadExternalResource(url, type) {
	return new Promise((resolve, reject) => {
		let tag;

		if (type === "css") {
			tag = document.createElement("link");
			tag.rel = "stylesheet";
			tag.href = url;
		}
		else if (type === "js") {
			tag = document.createElement("script");
			tag.src = url;
		}
		if (tag) {
			tag.onload = () => resolve(url);
			tag.onerror = () => reject(url);
			document.head.appendChild(tag);
		}
	});
}

if (screen.width >= 768) {
	Promise.all([
		loadExternalResource(live2d_path + "waifu.css", "css"),
		loadExternalResource(live2d_path + "live2d.min.js", "js"),
		loadExternalResource(live2d_path + "waifu-tips.js", "js")
	]).then(() => {
		initWidget({
			waifuPath: live2d_path + "waifu-tips.json",
			cdnPath: "https://fastly.jsdelivr.net/gh/fghrsh/live2d_api/",
			tools: ["hitokoto", "asteroids", "switch-model", "switch-texture", "photo", "info", "quit"]
		});
	});
}
})();