Wanikani Forums: 10 Characters

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

当前为 2020-03-11 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Wanikani Forums: 10 Characters
// @namespace    http://tampermonkey.net/
// @version      0.1
// @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() {
    let body = document.getElementsByTagName('body')[0];
    body.addEventListener('keyup', e => {
        if (e.key == "Enter" && e.ctrlKey) post("enter");
    });
    body.addEventListener('mousedown', e => {
        let parent = e.target.parentElement;
        if (parent.className == "save-or-cancel" || parent.parentElement.className == "save-or-cancel") post("mousedown");
    });

    function post(msg){
        let elem = document.getElementsByClassName('d-editor-input')[0];
        let val = elem.value;
        if (val.length < 10) {
            elem.value = val + ' <!-- lorem ipsum -->';
            if (msg == "enter") {
                elem.focus();
                elem.blur();
                elem.focus();
                document.querySelector('.submit-panel .create').click();
            }
        }
    }
})();