Automatically query if this video has been in the arkrec wiki database on video loading
目前為
// ==UserScript==
// @name Arkrec Wiki Assistant
// @name:zh-CN 明日方舟少人WIKI辅助插件
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Automatically query if this video has been in the arkrec wiki database on video loading
// @description:zh-CN 在打开视频时自动判断是否已上传至少人WIKI数据库,并提供上传捷径链接
// @author philimao
// @match https://www.bilibili.com/video/BV*
// @icon https://www.google.com/s2/favicons?domain=arkrec.wiki
// @grant unsafeWindow
// ==/UserScript==
(async function () {
const wikiBtn = document.createElement("a");
async function playerReady() {
let counter = 0;
return new Promise((resolve, reject) => {
const id = setInterval(() => {
if (
unsafeWindow.player &&
unsafeWindow.player.isInitialized &&
unsafeWindow.player.isInitialized()
) {
resolve(clearInterval(id));
}
if (counter > 100) {
reject(clearInterval(id));
}
counter++;
}, 100);
});
}
async function injection() {
let host = "https://arkrec.wiki";
// host = "http://127.0.0.1:3001";
const resRaw = await fetch(host + "/api/query-url", {
method: "POST",
mode: "cors",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ url: window.location.href }),
});
if (resRaw.ok) return console.log("Abort injecting");
document.querySelector(".video-toolbar").appendChild(wikiBtn);
console.log("Wiki Icon Injecting", window.bvid);
}
function registerPlayerObserver() {
const observer = new MutationObserver(async (mutationList, observer) => {
injection();
});
observer.observe(document.querySelector(".bilibili-player-video"), {
attributes: true,
childList: true,
subtree: true,
});
}
const wikiSvg =
"data:image/svg+xml,%3Csvg%20id%3D%22svg%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20width%3D%22400%22%20height%3D%22176.24521072796932%22%20viewBox%3D%220%2C%200%2C%20400%2C176.24521072796932%22%20version%3D%221.1%22%3E%3Cg%20id%3D%22svgg%22%3E%3Cpath%20id%3D%22path0%22%20d%3D%22M0.000%2081.302%20C%200.000%20178.729%2C-0.539%20176.253%2C20.648%20176.239%20C%2035.296%20176.230%2C36.588%20174.889%2C57.999%20137.469%20C%2068.404%20119.283%2C77.715%20103.341%2C78.689%20102.042%20C%2080.149%20100.093%2C83.915%20105.722%2C100.158%20134.127%20C%20123.163%20174.358%2C124.902%20176.245%2C138.968%20176.245%20C%20148.294%20176.245%2C149.315%20175.895%2C154.176%20171.034%20L%20159.387%20165.824%20159.387%2082.912%20L%20159.387%200.000%20141.762%200.000%20L%20124.138%200.000%20124.138%2052.487%20L%20124.138%20104.974%20107.142%2075.475%20L%2090.146%2045.977%2080.303%2045.977%20L%2070.460%2045.977%2065.395%2054.023%20C%2062.610%2058.448%2C54.860%2071.635%2C48.173%2083.326%20L%2036.015%20104.583%2035.612%2052.292%20L%2035.209%200.000%2017.604%200.000%20L%200.000%200.000%200.000%2081.302%20M163.985%2088.123%20L%20163.985%20176.245%20180.843%20176.245%20L%20197.701%20176.245%20197.701%2088.123%20L%20197.701%200.000%20180.843%200.000%20L%20163.985%200.000%20163.985%2088.123%20M202.299%2088.123%20L%20202.299%20176.245%20213.374%20176.245%20L%20224.450%20176.245%20292.685%20108.065%20L%20360.920%2039.884%20361.424%2019.942%20L%20361.929%200.000%20344.183%200.000%20L%20326.437%200.000%20326.437%2012.654%20L%20326.437%2025.307%20281.992%2069.732%20L%20237.548%20114.156%20237.548%2057.078%20L%20237.548%200.000%20219.923%200.000%20L%20202.299%200.000%20202.299%2088.123%20M364.751%2088.123%20L%20364.751%20176.245%20382.375%20176.245%20L%20400.000%20176.245%20400.000%2088.123%20L%20400.000%200.000%20382.375%200.000%20L%20364.751%200.000%20364.751%2088.123%20M301.143%20102.688%20L%20288.948%20114.956%20307.692%20133.745%20L%20326.437%20152.535%20326.437%20164.390%20L%20326.437%20176.245%20344.061%20176.245%20L%20361.686%20176.245%20361.686%20159.487%20C%20361.686%20150.270%2C360.962%20140.787%2C360.078%20138.414%20C%20358.678%20134.659%2C316.353%2090.421%2C314.160%2090.421%20C%20313.708%2090.421%2C307.850%2095.942%2C301.143%20102.688%20%22%20stroke%3D%22none%22%20fill%3D%22%23000000%22%20fill-rule%3D%22evenodd%22%3E%3C%2Fpath%3E%3C%2Fg%3E%3C%2Fsvg%3E";
wikiBtn.href = "https://arkrec.wiki/submit?url=" + window.location.href;
wikiBtn.target = "_blank";
wikiBtn.rel = "noopener noreferrer";
wikiBtn.style.width = "5rem";
wikiBtn.style.height = "1.8rem";
wikiBtn.style.marginRight = "2rem";
wikiBtn.style.float = "right";
wikiBtn.style.backgroundImage = `url(${wikiSvg})`;
wikiBtn.style.backgroundSize = "contain";
wikiBtn.style.backgroundRepeat = "no-repeat";
wikiBtn.style.backgroundPosition = "center";
wikiBtn.style.filter = "invert(0.4)";
wikiBtn.style.transform = "translateY(2px)";
wikiBtn.addEventListener("mouseenter", () => {
wikiBtn.style.filter =
"invert(1) brightness(0.5) sepia(1) hue-rotate(-194deg) saturate(3)";
});
wikiBtn.addEventListener("mouseleave", () => {
wikiBtn.style.filter = "invert(0.4)";
});
await playerReady();
await injection();
//registerPlayerObserver();
})();