EQ

导出问题

当前为 2022-10-21 提交的版本,查看 最新版本

// ==UserScript==
// @name         EQ
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  导出问题
// @author       XB
// @match        http://10.110.75.46/*
// @match        http://100.19.5.34/*
// @grant        none
// @license      MIT
// ==/UserScript==
    const first = document;
    let timer=null;
let firstframe=null;
let startid=1;
let number=100;
function sleep(time){
 var timeStamp = new Date().getTime();
 var endTime = timeStamp + time;
 while(true){
 if (new Date().getTime() > endTime){
  return;
 }
 }
}
function get_url_extension( url ) {
    return url.split(/[#?]/)[0].split('.').pop().trim();
}
function get_url_name( url ) {
    const index = url.lastIndexOf('?');
    if(index===-1){
        return url.substring(url.lastIndexOf('/') + 1, url.length );
    }else{
        return url.substring(url.lastIndexOf('/') + 1, index );
    }
}
function download(href,name){
    let link = document.createElement('a');
    link.style.display="none";
    link.target="_blank";
    link.href=href;
    link.download=name;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}
function getBlob(href){
    return new Promise(resolve =>{
        const xhr = new XMLHttpRequest();
        xhr.open('GET',href,true);
        xhr.responseType='blob';
        xhr.onload=()=>{
            if(xhr.status === 200){
                resolve(xhr.response);
            }
        };
        xhr.send();
    });
}
function saveAs(blob,name){
    let link = document.createElement('a');
    link.href = window.URL.createObjectURL(blob);
    link.download = name;
    link.click();
}
function downloadFile(href,name){
    getBlob(href).then(
        blob =>{
            saveAs(blob,name);
        }
    );
}
function refreshlist(){
    const tmp = first.getElementsByTagName('iframe');
    if(tmp.length>2){
        const frame = tmp[length-1];
        let input="#questionDescribeInput";
        try{
            if(frame.contentWindow.$("#questionDescribeInput").text()===''){
                if(frame.contentWindow.$("#questionDetail").text()==='')
                    return;
                input="#questionDetail";
            }
            const imgs=frame.contentWindow.$(input).find('img');
            const files=frame.contentWindow.$("#fileList").find('a');
            console.log(imgs);
            console.log(files);
            let i=1;
            let id=tmp.length-3+startid;
            for(let img of imgs){
                download(img.src,id+'.'+i+'.'+get_url_extension(img.src));
                ++i;
            }
            for(let file of files){
                const fileid = file.getAttribute('onclick').match(/downloadFile\(\'(.*)\',(.*)\)/)[1];
                const link= "/ibms/file.do/downloadFile?fileId="+fileid;
                downloadFile(link,id+'.'+i+'.'+file.innerText);
                ++i;
            }
        }catch (e){
            return;
        }
        $("#tabs").tabs('close',tmp.length-1);
        if(first.getElementsByTagName('iframe').length<=2){
            clearInterval(timer);
        }
    }
}
function refresh(){
    const tmp = first.getElementsByTagName('iframe');
    let toolbar = null;
    if(tmp.length>1){
        firstframe=tmp[1];
        try{
            toolbar = firstframe.contentDocument.getElementsByClassName('toolbar')[0];
            firstframe.contentDocument.getElementById('checkFlowStepBtn').style="width:50px;margin-right:0px";
            firstframe.contentDocument.getElementById('selectBugBtn').style="width:50px;margin-right:0px";
            firstframe.contentDocument.getElementById('resetBtn').style="width:50px;margin-right:0px";
            firstframe.contentDocument.getElementById('redistributeBtn').style="width:90px;margin-right:0px";
            firstframe.contentDocument.getElementById('exportQuestionBtn').style="width:90px;margin-right:0px";
            let obbtn = firstframe.contentDocument.createElement('button');
            obbtn.className="btn btn-success";
            obbtn.id="eqBtn";
            obbtn.style="width:60px;margin-right:0px";
            let obi=firstframe.contentDocument.createElement('i');
            obi.className="fa fa-download";
            obi.style="padding-right:3px;";
            let obs=firstframe.contentDocument.createElement('span');
            //obs.setAttribute("data-locale","button_download_excel");
            obs.innerText="附件";
            obbtn.appendChild(obi);
            obbtn.appendChild(obs);
            obbtn.onclick=function(){eq()};

            let input=firstframe.contentDocument.createElement('input');
            input.type="text";
            input.placeholoder="输入起始编号";
            input.id="startid";
            input.className="bootstrap-table-head-params header-input";
            input.style="width: 60px;";
            let input1=firstframe.contentDocument.createElement('input');
            input1.type="text";
            input1.placeholoder="输入个数";
            input1.id="number";
            input1.className="bootstrap-table-head-params header-input";
            input1.style="width: 50px;";
            toolbar.appendChild(obbtn);
            toolbar.appendChild(input);
            toolbar.appendChild(input1);
        }catch (e){
            return;
        }
        clearInterval(timer);
    }else{
        return;
    }
}

function eq(){
    const list = firstframe.contentDocument.getElementsByClassName('href-pointer');
    startid=(firstframe.contentWindow.$('#startid').val())*1;
    number=(firstframe.contentWindow.$('#number').val())*1;
    for(let i=0;i<list.length&&i<number*3;i+=3){
        const questionId = list[i].getAttribute('onclick').match(/questionDetail\(\'(.*)\',\'(.*)\',\'(.*)\'\)/)[1];
        //const url = "bugManage/bugQuestionDetail2.html?questionId="+questionId;
        //parent.addTab(questionId,url);
        firstframe.contentWindow.questionDetail(questionId,questionId,'assign')
        const tmp = first.getElementsByTagName('iframe');
        //let secondframe = tmp[2+i/2];
        //secondframe.setAttribute('tab',2+i/2);
        //secondframe.id="i"+(2+i/2);
        //$(secondframe).ready(function(){
            //console.log(secondframe);
        //const imgs=secondframe.contentWindow.$('#questionDetail').find('img');
        //secondframe.contentWindow.$("#tabs").tabs('close',2);
        //});
    }
    clearInterval(timer);
    timer=setInterval(() => {
        refreshlist();
    }, 1000);
}

(function() {
    'use strict';
    clearInterval(timer);
    timer=setInterval(() => {
        refresh();
    }, 1000);
    //toolbar.appendChild();
    // Your code here...
})();