ipod825 / EcolifeMonthCleannessCheck

// ==UserScript==
// @name        EcolifeMonthCleannessCheck
// @namespace   https://github.com/ipod825/userjs
// @include     http://ecolife.epa.gov.tw/judge/camec_judge/201150520
// @version     1
// @grant       none
// ==/UserScript==

$('<div/>').attr({id: "allTable"}).appendTo($(".main_theme_content"));
$('<input/>').attr({
    type: 'button',
    id: 'field',
    class: 'btn btn-success',
    value: 'Show',
}).click(function () {
    
    var year = $("#ctl00_ctl00_cphMain_cphMain_ddlYearS").val();
    var month = $("#ctl00_ctl00_cphMain_cphMain_ddlMonthS").val();
    $("#ctl00_ctl00_cphMain_cphMain_ucArea_cboDistrict >option").each(function(){
        if (this.index==0)
            return;
        var district=this.value;
        $.ajax({
            type: 'POST',
            url: location.href,
            async:false,
            data: getFormContent({'ctl00$ctl00$cphMain$cphMain$btnWebSearch': '',
                                  'ctl00$ctl00$cphMain$cphMain$ucArea$cboDistrict': district,
                                  'ctl00$ctl00$cphMain$cphMain$ucArea$cddDistrict_ClientState': district,}),
            success: function (res) {                
                var t=$(res).find("#ctl00_ctl00_cphMain_cphMain_ucCamecJudge1_GridView2");
                t.css({'display': null, 'margin':'0 0 0 0'}).find("tr:last-child").remove();
                $('#allTable').append(t);
            }
        });
    });
}).prependTo($('.main_theme_content'));

/*
function getFormContent(redifine){
    return $("input").map(function(){
        var v=this.value;
        if (this.name in redifine)
            v=redifine[this.name];
        return this.name.replace(/\$/g,"%24")+"="+v.replace(/\//g,"%2F").replace(/\+/g,"%2B").replace(/=/g,"%3D");
    }).get().join("&");
}
*/

function getFormContent(redifine){
    var a=getFormParStr($("input:enabled"),redifine);
    var b=getFormParStr($("select:enabled"),redifine);
    return a+"&"+b;
}

function getFormParStr(inputs,redifine){
    return inputs.map(function(){
    	var v=this.value;
        if (this.name in redifine)
            v=redifine[this.name];
        v=encodeURI(v);
        return this.name.replace(/\$/g,"%24")+"="+v.replace(/\//g,"%2F").replace(/\+/g,"%2B").replace(/=/g,"%3D");
    }).get().join("&");
}