Mortal Exporter

Export about-metadata info to Google Sheets

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Mortal Exporter
// @namespace    https://misskey.io/@srn
// @version      1.0.0
// @author       strangerxxx
// @description  Export about-metadata info to Google Sheets
// @match        https://mjai.ekyu.moe/killerducky/*
// @license      MIT
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function () {
    "use strict";

    // 送信ボタン追加
    const timer = setInterval(() => {
        const controls = document.querySelector(".controls");
        if (controls && !document.getElementById("send-to-gas")) {
            clearInterval(timer);

            const btn = document.createElement("button");
            btn.textContent = "送信";
            btn.id = "send-to-gas";

            controls.appendChild(btn);

            // メニュークリックでデータ送信
            btn.addEventListener("click", async () => {
                btn.disabled = true;

                try {
                    const params = new URLSearchParams(location.search);
                    const dataPath = params.get("data");
                    if (!dataPath) {
                        alert("dataパラメータがありません");
                        return;
                    }

                    const jsonUrl = new URL(dataPath, location.origin).href;

                    const res = await fetch(jsonUrl);
                    if (!res.ok) throw new Error(`HTTP ${res.status}`);
                    const json = await res.json();

                    const scriptURL = GM_getValue("gas_url", "");
                    if (!scriptURL) {
                        alert("送信先URLを設定してください");
                        return;
                    }

                    await fetch(scriptURL, {
                        method: "POST",
                        mode: "no-cors",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        body: JSON.stringify({
                            url: location.href,
                            json,
                        }),
                    });

                    alert("送信しました");
                } catch (e) {
                    alert("送信に失敗しました: " + e);
                } finally {
                    btn.disabled = false;
                }
            });
        }
    }, 1000);
})();

GM_registerMenuCommand("GAS URL設定", () => {
    const current = GM_getValue("gas_url", "");
    const newUrl = prompt("GAS URLを入力", current);
    if (newUrl) {
        GM_setValue("gas_url", newUrl);
        alert("保存しました");
    }
});