52pojie-helper

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);
})();