Greasy Fork

来自缓存

Greasy Fork is available in English.

恋爱游戏网+

验证码自动识别填写,Ctrl+Enter快捷键发表评论,短评实时字数统计

当前为 2020-12-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         恋爱游戏网+
// @namespace    http://tampermonkey.net/code_recongnize
// @version      2020.12.13.1
// @description  验证码自动识别填写,Ctrl+Enter快捷键发表评论,短评实时字数统计
// @author       PY-DNG
// @icon         https://www.lianaiyx.com/images/member/nopic.gif
// @include      https://www.lianaiyx.com/
// @include      https://www.lianaiyx.com/GalGame/*
// @include      https://www.lianaiyx.com/yangcheng/*
// @include      https://www.lianaiyx.com/monijingying/*
// @include      https://www.lianaiyx.com/celve/*
// @include      https://www.lianaiyx.com/jiemi/*
// @include      https://www.lianaiyx.com/ss/*
// @include      https://www.lianaiyx.com/yxzy/*
// @include      https://www.lianaiyx.com/gonglve/*
// @include      https://www.lianaiyx.com/e/pl/*
// @require      http://greasyfork.icu/scripts/408740-%E6%81%8B%E7%88%B1%E6%B8%B8%E6%88%8F%E7%BD%914%E4%BD%8D%E6%95%B0%E5%AD%97%E9%AA%8C%E8%AF%81%E7%A0%81%E8%AF%86%E5%88%AB/code/%E6%81%8B%E7%88%B1%E6%B8%B8%E6%88%8F%E7%BD%914%E4%BD%8D%E6%95%B0%E5%AD%97%E9%AA%8C%E8%AF%81%E7%A0%81%E8%AF%86%E5%88%AB.js?version=837246
// ==/UserScript==

(function() {
    'use strict';

    // 内置常量
    const TEXT_TEXTHINT_ORIGINAL = '短评最多字数:140字;超过字数请发表长评。';
    const TEXT_CHARACTERCOUNT = '短评字数统计:{CURCOUNT}/140字;超过140字请发布长评';

    // 获取DOM元素
    const input = document.getElementById('key');
    const focusEvent = new Event('focus');
    const codeImage = document.getElementById('KeyImgpl') ? document.getElementById('KeyImgpl') : document.getElementById('KeyImg');
    const saytext = document.querySelector('#saytext');

    // 自动识别填写验证码
    if (codeImage) {
        codeImage.addEventListener('load', function() {
            const code = rec_image(codeImage);
            if (code) {
                input.value = code;
            } else {
                input.dispatchEvent(focusEvent);
            }
        })
        input.dispatchEvent(focusEvent);
    }

    // Ctrl+Enter 发表评论
    if (saytext) {
        saytext.addEventListener('keydown', function() {
            let keycode = event.keyCode;
            if (keycode === 13 && event.ctrlKey && !event.altKey) {
                document.querySelector('#saypl').submit();
            }
        })
    }

    // 短评实时字数统计
    if (saytext) {
        const texthint = getTexthintElement();
        const refreshCount = function() {texthint.textContent = TEXT_CHARACTERCOUNT.replace('{CURCOUNT}', String(saytext.value.length));};

        // 首先统计一次字数
        refreshCount();

        // 当用户输入时,更新字数统计
        saytext.addEventListener('input', refreshCount);

        // 用户使用输入设备交互时,更新字数统计/*_*毕竟有些时候用户不输入字符,内容也会被JS动态修改,对吧?*_*/
        saytext.addEventListener('focus', refreshCount);
        saytext.addEventListener('mousedown', refreshCount);
        saytext.addEventListener('keydown', refreshCount);
        saytext.addEventListener('keyup', refreshCount);

        function getTexthintElement() {
            const allChilds = document.querySelector('#texthint').parentElement.childNodes;
            for (let i = 0; i < allChilds.length; i++) {
                if (allChilds[i].textContent.indexOf(TEXT_TEXTHINT_ORIGINAL) !== -1) {
                    return allChilds[i];
                }
            }
        }
    }

})();