52pojie-helper

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();