Wanikani Forums: Logograin emote

Adds logograin emote to the WaniKani forum

当前为 2023-09-02 提交的版本,查看 最新版本

// ==UserScript==
// @name         Wanikani Forums: Logograin emote
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Adds logograin emote to the WaniKani forum
// @author       latepotato
// @include      https://community.wanikani.com/*
// @grant        GM.xmlHttpRequest
// ==/UserScript==
// Just write :logograin:

;(function () {
    let rng_timestamp
    // Wait until the save function is defined
    const i = setInterval(tryInject, 100)

    // Inject if the save function is defined
    function tryInject() {
        const old_save = unsafeWindow.require('discourse/controllers/composer').default.prototype.save
        if (old_save) {
            clearInterval(i)
            inject(old_save)
        }
    }

    // Wrap the save function with our own function
    function inject(old_save) {
        const new_save = async function (t) {
            const composer = document.querySelector('textarea.d-editor-input') // Reply box
            composer.value = await replace_logograin_emotes(composer.value)
            composer.dispatchEvent(new Event('change', { bubbles: true, cancelable: true })) // Let Discourse know
            old_save.call(this, t) // Call regular save function
        }
        unsafeWindow.require('discourse/controllers/composer').default.prototype.save = new_save // Inject
    }
    // Grabs the text then returns the POLL
    async function replace_logograin_emotes(text) {
        return text.replace(/\:logograin\:/gis, ':ear_of_rice: :ship: :smiling_face_with_three_hearts:')
    }
})()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址