52pojie-helper

1.填充验证码。2.填充评论。3.缩进右侧条。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         52pojie-helper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  1.填充验证码。2.填充评论。3.缩进右侧条。
// @author       nameldk
// @match        https://www.52pojie.cn/thread-*.html
// @match        https://www.52pojie.cn/forum.php?mod=viewthread*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    /**
     * 填充验证码
     */
    function inputAns() {
        function getInput(){
            return document.querySelector('#seccodeqS0 input[name="secanswer"]');
        }

        function fill() {
            var input = getInput();
            var ans = document.querySelector('#seccodeqS0_menu');
            if (input && ans) {
                input.value = ans.innerText.replace(/.+答案:/,"");
            } else {
                console.warn('empty', input, ans);
            }
        }
        function bind() {
            var input = getInput();
            var a = document.querySelector('#seccodeqS0 a');
            if(a) {
                a.addEventListener('click', function(){
                    setTimeout(function(){
                        var input = getInput();
                        bind();
                        fill();
                        input.blur();
                    }, 500);
                });
            } else {
                console.warn('no a click');
            }
        }
        fill();
        bind();
    }

    /**
     * 填充评论
     */
    function inputComment(){
        var commentInput = document.querySelector('#fastpostmessage');
        var commentList = [];
        var list = document.querySelectorAll('td[id^="postmessage"]');

        function getOne() {
            return commentList[Math.random()*commentList.length|0];
        }

        function change(){
            commentInput.value = getOne() + getOne();
            commentInput.focus();
            commentInput.blur();
        }

        if (list) {
            var a = document.querySelector('#secqaa_qS0');
            if (a && a.parentNode) {
                var c = document.createElement('a');
                c.text='换评论';
                c.href='javascrit:;';
                c.onclick = function(){
                    change();
                };
                a.parentNode.appendChild(c);
            }

            var i = 0;
            for (var o of list){
                if ((i++) == 0) continue;
                commentList[commentList.length] = o.innerText.replace(/.+? 发表于 .+? .+?:.+?/,'').replace(/\s+/,'');
            }
            change();
        }
    }

    /**
     * 缩进右侧条
     */
    function indentBar() {
        var jz52top = document.querySelector('#jz52top');

        if (jz52top){
            jz52top.style.right = '-30px';
            jz52top.addEventListener('mouseover', function(){
                this.style.right = '0px';
            });
            jz52top.addEventListener('mouseout', function(){
                this.style.right = '-30px';
            });
        }

    }


    setTimeout(function(){
        indentBar();
        inputAns();
        inputComment();
    }, 1000);
})();