Wanikani Forums: 10chars

Inserts invisible text into any post not meeting the 10 character requirement

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Wanikani Forums: 10chars
// @namespace    http://tampermonkey.net/
// @version      1.1.4
// @description  Inserts invisible text into any post not meeting the 10 character requirement
// @author       Kumirei
// @include      https://community.wanikani.com/t/*
// @grant        none
// ==/UserScript==

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

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

    // Wrape the save function with our own function which fills out the post
    function inject(old_save) {
        const new_save = function (t) {
            let composer = document.querySelector('textarea.d-editor-input') // Reply box
            if (this.model.missingReplyCharacters > 0) {
                composer.value += ' <Lorem Ipsum>' // Modify message
                composer.dispatchEvent(new Event('change', { bubbles: true, cancelable: true })) // Let Discourse know
            }
            old_save.call(this, t) // Call regular save function
        }
        window.require('discourse/controllers/composer').default.prototype.save = new_save // Inject
    }
})()