Greasy Fork

Greasy Fork is available in English.

NGA论坛AC娘表情包(明日方舟ver)

为 NGA 论坛添加额外的表情包发送功能

当前为 2022-07-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NGA论坛AC娘表情包(明日方舟ver)
// @namespace    http://kayanoruiko.cc
// @version      1.1.1
// @author       kayanouriko
// @description  为 NGA 论坛添加额外的表情包发送功能
// @homepage     https://bbs.nga.cn/read.php?tid=32772711
// @license      MIT
// @match        *://bbs.nga.cn/thread.php?*
// @match        *://bbs.nga.cn/read.php?*
// @match        *://bbs.nga.cn/post.php?*
// @match        *://ngabbs.com/thread.php?*
// @match        *://ngabbs.com/read.php?*
// @match        *://ngabbs.com/post.php?*
// @match        *://nga.178.com/thread.php?*
// @match        *://nga.178.com/read.php?*
// @match        *://nga.178.com/post.php?*
// @grant        GM.setValue
// @grant        GM.getValue
// ==/UserScript==

"use strict";
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());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var isValidkey = function (key, object) {
    return key in object;
};
var main = {
    stickersMap: {
        有何贵干: './mon_202207/22/-klbw3Q2q-jij8K5T8S2s-2s.gif',
        呆: './mon_202207/22/-klbw3Q2q-5mbmK5T8S2s-2s.gif',
        壁咚: './mon_202207/22/-klbw3Q2q-9iy2K5T8S2s-2s.gif',
        哼: './mon_202207/22/-klbw3Q2q-g6sjK6T8S2s-2s.gif',
        goodjob: './mon_202207/22/-klbw3Q2q-cbsqK7T8S2s-2s.gif',
        黑枪: './mon_202207/22/-klbw3Q2q-1odzK7T8S2s-2s.gif',
        笑哭: './mon_202207/22/-klbw3Q2q-fl71K6T8S2s-2s.gif',
        嘲笑: './mon_202207/22/-klbw3Q2q-90w2K6T8S2s-2s.gif',
        咦: './mon_202207/23/-klbw3Q2q-6vorK7T8S2s-2s.gif',
        闪光: './mon_202207/23/-klbw3Q2q-178sK6T8S28-2f.gif',
        威吓: './mon_202207/25/-klbw3Q2q-krugK6T8S2n-2n.gif',
        抢镜头: './mon_202207/25/-klbw3Q2q-9abvK5T8S2s-2s.gif' //阿米娅
    },
    init: function () {
        this.addObserver();
        this.onload();
    },
    addObserver: function () {
        var _this = this;
        var callback = function (mutationList) { return __awaiter(_this, void 0, void 0, function () {
            var isReplace, mutation;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, GM.getValue('acchan-stickers-replace', false)];
                    case 1:
                        isReplace = _a.sent();
                        if (isReplace) {
                            this.replaceAllMatchStickers();
                        }
                        mutation = mutationList.find(function (mutation) {
                            return mutation.type === 'childList' && mutation.addedNodes.length < 2;
                        });
                        mutation === null || mutation === void 0 ? void 0 : mutation.addedNodes.forEach(function (node) {
                            var element = node;
                            if (/^commonwindow\d+$/.test(element.id) &&
                                element.querySelector('.tip_title .title').innerText === '插入表情') {
                                _this.addButton(element.id);
                            }
                        });
                        return [2 /*return*/];
                }
            });
        }); };
        var observer = new MutationObserver(callback);
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    },
    addButton: function (boxId) {
        var _this = this;
        var _a;
        if (document.getElementById('acchan-arknights'))
            return;
        var lastButtonElement = document.querySelector("#".concat(boxId, " .div3 .block_txt_big:last-child"));
        lastButtonElement === null || lastButtonElement === void 0 ? void 0 : lastButtonElement.insertAdjacentHTML('afterend', "<button id=\"acchan-arknights\" class=\"block_txt_big\">AC\u5A18(\u660E\u65E5\u65B9\u821Fver)</button>");
        (_a = document.getElementById('acchan-arknights')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', function () {
            _this.buttonOnClickAction();
        });
        var lastDivElement = document.querySelector("#".concat(boxId, " .div3 > span > div:last-child"));
        lastDivElement === null || lastDivElement === void 0 ? void 0 : lastDivElement.insertAdjacentHTML('afterend', "<div id=\"acchan-arknights-stickers\" style=\"display: none;\">".concat(this.addStickers(), "</div>"));
    },
    addStickers: function () {
        var html = '';
        for (var key in this.stickersMap) {
            if (isValidkey(key, this.stickersMap)) {
                var sticker = this.stickersMap[key];
                html += "<img height=\"60px\" style=\"margin: 0px 2px;\" onclick=\"postfunc.addText('[img]".concat(sticker, "[/img]');postfunc.selectSmilesw._.hide();\" src=\"https://img.nga.178.com/attachments/").concat(sticker.slice(2), "\">");
            }
        }
        return html;
    },
    buttonOnClickAction: function () {
        var _a, _b, _c, _d;
        return __awaiter(this, void 0, void 0, function () {
            var boxElement, divs, spanElement, isReplace, element, checkboxElement;
            return __generator(this, function (_e) {
                switch (_e.label) {
                    case 0:
                        boxElement = document.getElementById('acchan-arknights-stickers');
                        if (!boxElement) return [3 /*break*/, 2];
                        if (boxElement.style.display === 'none') {
                            boxElement.style.display = '';
                            divs = (_b = (_a = boxElement.parentElement) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.querySelectorAll('span > div:not(#acchan-arknights-stickers)');
                            divs === null || divs === void 0 ? void 0 : divs.forEach(function (node) {
                                var element = node;
                                element.style.display = 'none';
                            });
                        }
                        spanElement = (_d = (_c = boxElement.parentElement) === null || _c === void 0 ? void 0 : _c.parentElement) === null || _d === void 0 ? void 0 : _d.querySelector('div > span');
                        if (!spanElement) return [3 /*break*/, 2];
                        return [4 /*yield*/, GM.getValue('acchan-stickers-replace', false)];
                    case 1:
                        isReplace = _e.sent();
                        element = spanElement;
                        element.innerHTML = "\n                <p>\n                    <input type=\"checkbox\" id=\"acchan-arknights-stickers-checkbox\" ".concat(isReplace ? 'checked="checked"' : '', ">\n                    <label for=\"acchan-arknights-stickers-checkbox\">\u66FF\u6362\u5E16\u5B50\u5185\u539F\u7248AC\u5A18\u8868\u60C5</label>\n                </p>\n                <a href=\"/read.php?tid=32772711\" target=\"_blank\" style=\"text-decoration: underline !important;color: rgb(189, 126, 109) !important;float:right !important;\">\u964D\u591C\u98DE\u971C@NGA\u5236\u4F5C</a>\n                ");
                        checkboxElement = document.getElementById('acchan-arknights-stickers-checkbox');
                        checkboxElement === null || checkboxElement === void 0 ? void 0 : checkboxElement.addEventListener('change', function (event) {
                            var isChecked = event.target.checked;
                            GM.setValue('acchan-stickers-replace', isChecked);
                        });
                        _e.label = 2;
                    case 2: return [2 /*return*/];
                }
            });
        });
    },
    onload: function () {
        return __awaiter(this, void 0, void 0, function () {
            var isReplace;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, GM.getValue('acchan-stickers-replace', false)];
                    case 1:
                        isReplace = _a.sent();
                        if (!isReplace)
                            return [2 /*return*/, ''];
                        window.onload = this.replaceAllMatchStickers();
                        return [2 /*return*/];
                }
            });
        });
    },
    replaceAllMatchStickers: function () {
        var _this = this;
        var images = document.querySelectorAll('img.smile_ac,img.smile_a2');
        images.forEach(function (image) {
            var _a;
            var element = image;
            var alt = (_a = element.getAttribute('alt')) !== null && _a !== void 0 ? _a : '';
            if (isValidkey(alt, _this.stickersMap)) {
                var sticker = _this.stickersMap[alt];
                element.setAttribute('src', "https://img.nga.178.com/attachments/".concat(sticker.slice(2)));
            }
        });
    }
};
main.init();