endonotifier

automatically notify others about new WA members from the past week on NationStates

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
"use strict";
// ==UserScript==
// @name         endonotifier
// @namespace    mailto:[email protected]
// @version      1.0
// @description  automatically notify others about new WA members from the past week on NationStates
// @author       [email protected]
// @match        https://www.nationstates.net/page=display_region_rmb/*
// @icon         https://i.ibb.co/H2wwHbX/bill.png
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js
// @run-at       context-menu
// ==/UserScript==
var __awaiter =
    (this && this.__awaiter) ||
    function (thisArg, _arguments, P, generator) {
        function adopt(value) {
            return value instanceof P
                ? value
                : new P(function (resolve) {
                      resolve(value)
                  })
        }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) {
                try {
                    step(generator.next(value))
                } catch (e) {
                    reject(e)
                }
            }
            function rejected(value) {
                try {
                    step(generator["throw"](value))
                } catch (e) {
                    reject(e)
                }
            }
            function step(result) {
                result.done
                    ? resolve(result.value)
                    : adopt(result.value).then(fulfilled, rejected)
            }
            step(
                (generator = generator.apply(thisArg, _arguments || [])).next()
            )
        })
    }
const ENDPOINTS = {
    world: "https://www.nationstates.net/cgi-bin/api.cgi",
}
;(function main() {
    return __awaiter(this, void 0, void 0, function* () {
        const scriptAlert = (message) => alert(`Endonotifier — ${message}`)
        const textarea = document.activeElement
        if (
            !(
                textarea instanceof HTMLTextAreaElement &&
                textarea.id == "editor"
            )
        )
            return scriptAlert("Please use the RMB text area!")
        const region = (() => {
            let match = window.location.pathname.match(/region=([^\\]+)/)
            return match ? match[1] : null
        })()
        if (!region) return scriptAlert("Region name not found in url...")
        const parser = new DOMParser()
        let admitted = new Set()
        let resigned = new Set()
        {
            let result = yield axios.default
                .get(ENDPOINTS.world, {
                    params: {
                        q: "happenings",
                        view: `region.${region}`,
                        filter: "member",
                    },
                })
                .then((response) => {
                    let log = parser.parseFromString(response.data, "text/xml")
                    for (const element of log.getElementsByTagName("TEXT")) {
                        let match
                        if (
                            (match = element.textContent.match(
                                /@@(.+)@@ was admitted to the World Assembly\./
                            )) &&
                            !resigned.has(match[1])
                        )
                            admitted.add(match[1])
                        else if (
                            (match = element.textContent.match(
                                /@@(.+)@@ resigned from the World Assembly\./
                            )) &&
                            !admitted.has(match[1])
                        )
                            resigned.add(match[1])
                    }
                    return response
                })
                .catch((err) => err)
            if (result instanceof Error) {
                return scriptAlert(result.message)
            }
        }
        let msg = ""
        if (admitted.size || resigned.size) {
            msg += "[list]\n"
            for (const nation of admitted)
                msg += `[*][nation]${nation}[/nation]\n`
            for (const nation of resigned)
                msg += `[*][strike][nation]${nation}[/nation][/strike]\n`
            msg += "[/list]\n"
        } else msg = "no new regions fo today :(\n"
        textarea.setRangeText(
            msg,
            textarea.selectionStart,
            textarea.selectionEnd,
            "end"
        )
    })
})()