Greasy Fork

Greasy Fork is available in English.

恋爱游戏网+

验证码自动识别填写,Ctrl+Enter快捷键发表评论,短评实时字数统计,资源页简介区百度网盘链接识别、补全、激活,点击度盘链接自动复制提取码

当前为 2021-04-16 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         恋爱游戏网+
// @namespace    http://tampermonkey.net/code_recongnize
// @version      2021.04.16.4
// @description  验证码自动识别填写,Ctrl+Enter快捷键发表评论,短评实时字数统计,资源页简介区百度网盘链接识别、补全、激活,点击度盘链接自动复制提取码
// @author       PY-DNG
// @icon         https://www.lianaiyx.com/e/data/images/info.jpg
// @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/*
// @include      https://pan.baidu.com/s/*
// @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_CHINESEINLINKS = '删除汉字文字去除我盘点百度杠复制链接和谐河蟹防止抽风度娘网盘';

    // 开发者模式开关
    const developer = false;

    // 内置常量
    const CSS_DOWNLOADPAGE = '#actvgui {color:rgba(0,200,0,0.8); cursor:pointer; font-weight:bold;} #actvgui:hover {color:rgb(0, 120, 0);}';
    const REGEXP_PSWDCODE = /(?:提取码|密码|神秘代码) *[::] *(\w{4})/g;
    const REGEXP_DUPANSHARE = new RegExp('^(/s/|s/|/)', 'g');
    const REGEXP_LINKRCGNZER = new RegExp('(/s/|s/|/)?[\\w_\\-{CHINESE}]{7,}'.replaceAll('{CHINESE}', TEXT_CHINESEINLINKS.replaceAll('\\', '\\\\')), 'g');
    const REGEXP_CHNSRCGNZER = new RegExp('[{CHINESE}]+'.replaceAll('{CHINESE}', TEXT_CHINESEINLINKS.replaceAll('\\', '\\\\')), 'g');
    const REGEXP_CHNSRCGNZER_TOOLONG = new RegExp('[{CHINESE}]{5,}'.replaceAll('{CHINESE}', TEXT_CHINESEINLINKS.replaceAll('\\', '\\\\')), 'g');
    const URL_API_DOWNLOAD = 'https://www.lianaiyx.com/e/DownSys/GetDown/?classid=11&id={GAMEID}&pathid=0';
    const URL_HOST_BAIDUPAN = 'https://pan.baidu.com/s/';
    const TEXT_AUTOCOPY = '点击链接自动复制提取码({PSWDCODE})';
    const TEXT_PSWDCODE = '提取码:{PSWDCODE}';
    const TEXT_SHOWORIGINAL = '显示原文';
    const TEXT_ACTIVATE = '识别链接';
    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 copyText(text) {
        // Create a new textarea for copying
        const newInput = document.createElement('textarea');
        document.body.appendChild(newInput);
        newInput.value = text;
        newInput.select();
        document.execCommand('copy');
        document.body.removeChild(newInput);
    }

    function addStyle(css, styleId) {
        if (styleId && document.getElementById(styleId)){
            document.getElementById(styleId).remove();
        }
        const newStyleElement = document.createElement("style");
        newStyleElement.type = "text/css";
        if (styleId) {newStyleElement.id = styleId;};
        newStyleElement.innerText = css;
        //newStyleElement.appendChild(document.createTextNode(css));
        const headElement = document.getElementsByTagName("head")[0];
        headElement.appendChild(newStyleElement);
    }

    // 游戏资源页
    function pageDownload() {
        // 获取元素/信息
        const downloadLink = document.querySelector('.downpath').querySelector('a:nth-child(1)');
        const gameId = location.href.match(/(\d+?)\.html/)[1];
        const infoEle = document.querySelector('.downbox > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(2) > div:nth-child(1)');
        const subEles = infoEle.childNodes;

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

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

        // 简介区度盘链接相关功能
        // 添加GUI,以在识别/处理错误时让用户可以恢复、查看原内容
        let activateState = -1; // 记录当前是否已识别激活链接:1.激活(显示链接),-1.未激活(显示原文)
        let originalHTML; // 记录原文内容HTML
        let btnBaidupan;
        btnBDPinit();

        // 自动识别处理
        btnBDPonclick();

        function btnBDPinit() {
            const btnExist = infoEle.querySelector('#actvgui') ? true : false;
            btnBaidupan = btnExist ? infoEle.querySelector('#actvgui') : document.createElement('span');
            btnBaidupan.innerText = TEXT_ACTIVATE;
            btnBaidupan.id = 'actvgui';
            btnBaidupan.addEventListener('click', btnBDPonclick);
            if (!btnExist) {
                addStyle(CSS_DOWNLOADPAGE);
                if (subEles.length > 0) {
                    infoEle.insertBefore(btnBaidupan, subEles[0]);
                    infoEle.insertBefore(document.createElement('br'), subEles[1]);
                } else {
                    infoEle.appendChild(btnBaidupan);
                }
            }
        }

        function btnBDPonclick() {
            if (activateState > 0) {
                // 当前已激活,需要显示原文
                infoEle.innerHTML = originalHTML;
                // 注意!这里HTML重新解析,需要重新设置按钮
                btnBDPinit();
                btnBaidupan.innerText = TEXT_ACTIVATE; // 再次点击按钮,激活链接
            } else {
                // 当前原文状态,需要激活
                originalHTML = infoEle.innerHTML;
                baidupanActivate();
                btnBaidupan.innerText = TEXT_SHOWORIGINAL; // 再次点击按钮,显示原文
            }
            activateState = -activateState;
        }

        function baidupanActivate() {
            // 检查每一个子元素
            let pswdCode; // 储存识别到的提取码(假设只有一个提取码)
            const linkElemts = []; // 储存所有激活的span元素
            for (let i = 0; i < subEles.length; i++) {
                const thisEle = subEles[i];
                const HTMLRef = [null, undefined].includes(thisEle.innerHTML) ? 'nodeValue' : 'innerHTML';
                const dupanSuffixes = thisEle[HTMLRef].match(REGEXP_LINKRCGNZER);
                const pswdMatch = [...thisEle[HTMLRef].matchAll(REGEXP_PSWDCODE)];
                // 如果匹配到了提取码
                if (pswdMatch.length > 0 && pswdMatch[0][1]) {
                    pswdCode = pswdMatch[0][1];
                }
                // 如果匹配到了像是链接后缀的东西
                if (dupanSuffixes) {
                    const validSffxs = []; // 储存所有去除反和谐字符后的链接后缀
                    const dupanLinks = []; // 储存所有补全后的百度网盘链接
                    for (let j = 0; j < dupanSuffixes.length; j++) {
                        // 如果全部是数字,那么一定不是度盘后缀,有可能是QQ群号什么的
                        if (Number(dupanSuffixes[j])) {continue;};
                        // 如果其中有连续的反和谐字符长度过长(超过5个),那么多半也不是度盘后缀,毕竟谁会在同一个位置连续地插入那么多反和谐字符呢?
                        if (dupanSuffixes[j].match(REGEXP_CHNSRCGNZER_TOOLONG)) {continue;};
                        // 格式化链接
                        validSffxs[j] = dupanSuffixes[j].replace(REGEXP_CHNSRCGNZER, '').replace(REGEXP_DUPANSHARE, '');
                        dupanLinks[j] = URL_HOST_BAIDUPAN + validSffxs[j];
                        // 创建元素以供点击
                        const span = document.createElement('span');
                        const a = document.createElement('a');
                        span.classList.add('downpath');
                        a.href = dupanLinks[j];
                        a.innerText = dupanLinks[j];
                        a.target = '_blank';
                        span.appendChild(a);
                        // 点击的同时复制提取码(如果能识别到的话)
                        span.addEventListener('click', function() {
                            if (pswdCode) {
                                copyText(pswdCode);
                            };
                        });
                        // 记录元素
                        linkElemts.push({span: span, a: a});
                        // 插入元素
                        if (i < subEles.length-1) {
                            // 当前元素不是最后一个,插入到下一个元素之前
                            infoEle.insertBefore(span, subEles[i+1]);
                            i++;
                        } else {
                            // 当前元素已经是最后一个了,直接加入到最后即可
                            infoEle.appendChild(span);
                            i++;
                        }
                        thisEle[HTMLRef] = thisEle[HTMLRef].replace(dupanSuffixes[j], '');
                    }
                    if (developer) {console.log(dupanSuffixes, validSffxs, dupanLinks);};
                }
            }
            if (developer) {console.log(linkElemts);};
            // 如果识别到了提取码,就在链接中显示出来吧
            if (pswdCode) {
                for (let i = 0; i < linkElemts.length; i++) {
                    const span = linkElemts[i].span;
                    const a = linkElemts[i].a;
                    a.title = TEXT_AUTOCOPY.replaceAll('{PSWDCODE}', pswdCode);
                    a.innerText = a.innerText + ' ' + TEXT_PSWDCODE.replaceAll('{PSWDCODE}', pswdCode);
                }
            }
        }
    }

})();