导出问题
当前为
// ==UserScript==
// @name EQ
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 导出问题
// @author XB
// @match http://10.110.75.46/*
// @grant none
// @license MIT
// ==/UserScript==
const first = document;
let timer=null;
let firstframe=null;
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 download(href,name){
const link = document.creatieElement('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 refreshlist(){
const tmp = first.getElementsByTagName('iframe');
if(tmp.length>2){
const frame = tmp[length-1];
const imgs=frame.contentWindow.$("#questionDetail").find('img');
const files=frame.contentWindow.$("#fileList").find('a');
console.log(imgs);
console.log(files);
let i=1;
for(let img of imgs){
download(img.src,(length-1)+'.'+i+get_url_extension(img.src));
}
for(let file of files){
//download(file.href,(length-1)+'.'+i+get_url_extension(file.href));
}
$("#tabs").tabs('close',tmp.length-1);
}
}
function refresh(){
const tmp = first.getElementsByTagName('iframe');
if(tmp.length>1){
firstframe=tmp[1];
clearInterval(timer);
timer=setInterval(() => {
refreshlist();
}, 1000);
}else{
return;
}
sleep(1000);
const toolbar = firstframe.contentDocument.getElementsByClassName('toolbar')[0];
toolbar.lastElementChild.style="display:none;";
let obbtn = firstframe.contentDocument.createElement('button');
obbtn.className="btn btn-success";
obbtn.id="eqBtn";
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="导出EXCEL【新】";
obbtn.appendChild(obi);
obbtn.appendChild(obs);
obbtn.onclick=function(){eq()};
toolbar.appendChild(obbtn);
}
function eq(){
const list = firstframe.contentDocument.getElementsByClassName('href-pointer');
for(let i=0;i<list.length;i+=2){
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);
//});
}
}
(function() {
'use strict';
clearInterval(timer);
timer=setInterval(() => {
refresh();
}, 1000);
//toolbar.appendChild();
// Your code here...
})();