恋爱游戏网+

验证码自动识别填写,Ctrl+Enter快捷键发表评论,短评实时字数统计,解除[因政策原因,暂不提供下载]

目前为 2020-12-23 提交的版本。查看 最新版本

// ==UserScript==
// @name         恋爱游戏网+
// @namespace    http://tampermonkey.net/code_recongnize
// @version      2020.12.17.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      https://gf.qytechs.cn/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 URL_API_DOWNLOAD = 'https://www.lianaiyx.com/e/DownSys/GetDown/?classid=11&id={GAMEID}&pathid=0';
    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');

    // 获取标签页API(只要API第一部分,如: 'yxzy', 'GalGame')
    const API = window.location.href.replace(/https?:\/\/(.*?\.){1,2}.*?\//, '').replace(/\?.*/, '').replace(/\/.*/g, '');

    // 通用页面操作
    codeFill();
    hotkeySay();
    saytextCounting();

    // 根据不同API页面执行不同附加功能
    switch (API) {
        // Dwonload page
        case 'yxzy':
            pageDownload();
            break;
        // Other pages
        default:
            console.log(API);
    }

    // 自动识别填写验证码
    function codeFill() {
        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 发表评论
    function hotkeySay() {
        if (saytext) {
            saytext.addEventListener('keydown', function() {
                let keycode = event.keyCode;
                if (keycode === 13 && event.ctrlKey && !event.altKey) {
                    document.querySelector('#saypl').submit();
                }
            })
        }
    }

    // 短评实时字数统计
    function saytextCounting() {
        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];
                    }
                }
            }
        }
    }

    // 游戏资源页
    function pageDownload() {
        // 获取元素/信息
        const downloadLink = document.querySelector('.downpath').querySelector('a:nth-child(1)');
        const gameId = location.href.match(/(\d+?)\.html/)[1];

        // 检测是否允许下载
        const downloadEnabled = downloadLink.href !== '';

        // 如果不允许下载,就添加下载链接
        if (!downloadEnabled) {
            downloadLink.href = URL_API_DOWNLOAD.replace('{GAMEID}', gameId);
            downloadLink.target = '_blank';
            downloadLink.innerText = '[点击下载:)]';
        }
    }

})();

QingJ © 2025

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