吾爱破解论坛回帖自动填写验证问题答案

吾爱破解论坛点击回帖内容输入框后,自动填写验证问题答案

// ==UserScript==
// @name         吾爱破解论坛回帖自动填写验证问题答案
// @namespace    http://bmqy.net/
// @version      1.0
// @description  吾爱破解论坛点击回帖内容输入框后,自动填写验证问题答案
// @author       bmqy
// @match        http://*.52pojie.cn/*
// @match        https://*.52pojie.cn/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getSpecialTextByElement(obj){
        var sAnswerText = '';
        var reg = /(?<=答案:)(.*)/g;
        if(reg.test(obj.innerText)){
            sAnswerText = RegExp.$1;
        }
        return sAnswerText;
    }

    document.addEventListener('DOMNodeInserted', function(e){
        var oInput = document.querySelector('input[name=secanswer]');
        if(oInput){
            var oAnswer = oInput.parentNode.parentNode.querySelector('.p_pop.p_opt');
            var sAnswer = getSpecialTextByElement(oAnswer);
            document.querySelector('input[name=secanswer]').value = sAnswer;
        }
    });
})();