xaojoe126.com / 考试页面

// ==UserScript==
// @name         考试页面
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  quick answer questions for train.lnsafety.com!
// @author       You
// @license      MIT
// @updateURL    https://openuserjs.org/meta/xaojoe126.com/My_Script.meta.js
// @connect      cube123.cn
// @match        http://train.lnsafety.com/*
// @require      http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// @run-at       document-start

// ==/UserScript==

(function() {
    $(document).ready(function(){
        $("#mainFrame1").load(function(o){
            try{
                console.log("开始运行");
                alert("如果此工具不好使,或者漏题,请独立答题吧,没招儿!");
                alert("脚本使用后记得删除,黑色图标,右键删除!");
                h = $("#mainFrame1")[0].contentDocument;
                hh = $(h).find("#RightExam ul li");
                var old = 0;
                var li = new Array();
                for(i=0;i<hh.length;i++){
                    li.push(hh[i]);
                }
                as = $(h).find('a');
                console.log(as);


                for(var i=0;i<li.length;i++){
                    //timu = li[i].innerText.replace(/ /g,'').replace(/	/g,'').split('\n').slice(0,4).join('').replace('√×','');
                    //timu = timu.replace(/A、.*/,'');
                    timu = li[i].innerText.split('\n')[0];
                    timu = timu.replace(/^[\d ]*、/,'');
                    //timu = timu.split('、').slice(1).join('');
                    timu = timu.substr(3,15);

                    GM_xmlhttpRequest({
                        method:'Get',
                        url:"http://cube123.cn/kaoshi/dbpostget.asp?" + i + '=' + timu,
                        onload:function(r){
                            old++;
                            if(old==100){console.log('完成');alert('完成');}
                            try{
                                s = JSON.parse(r.responseText);
                                tid = s.id;
                                s = s.answer;
                                if(/对/.test(s)){
                                    $($(li[tid]).find("input")[0]).attr("checked",true);
                                    //console.log($(as[tid]));
                                }else if (/错/.test(s))
                                    $($(li[tid]).find("input")[1]).attr("checked",true);
                                else if (/A/.test(s))
                                    $($(li[tid]).find("input")[0]).attr("checked",true);
                                else if (/B/.test(s))
                                    $($(li[tid]).find("input")[1]).attr("checked",true);
                                else if (/C/.test(s))
                                    $($(li[tid]).find("input")[2]).attr("checked",true);
                                else if (/D/.test(s))
                                    $($(li[tid]).find("input")[3]).attr("checked",true);
                                else
                                    console.log(li[tid].innerText.split('\n')[0],JSON.parse(r.responseText).question);
                            }catch(e){
                                console.log(tid,"网络错误,或者返回错误,或者题目提取错误",r.responseText);
                            }
                        }
                    });
                }
            }catch(e){
                console.log(123);
            }
        });


        /*
        var fileref=document.createElement('script');
        fileref.setAttribute("type","text/javascript");
        fileref.setAttribute("src", 'http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js');
        document.getElementsByTagName("head")[0].appendChild(fileref);
        li = $(window.parent.frames["mainFrame1"].document).find("#RightExam ul li");
        */
    });
})();