// ==UserScript==
// @name GDorder
// @namespace Violentmonkey Scripts1
// @include https://gdgpo.czt.gd.gov.cn/gpmall-web/index.html#/management/mytodo/agentGoodsList
// @grant none
// @version 2.1
// @author 小白
// @require https://code.jquery.com/jquery-3.1.1.min.js
// @description 2020/12/30 下午4:51:35
// @downloadURL none
// ==/UserScript==
(function(){
window.helloworld = function() {
alert('Hello world!');
}
window.setTimeout(helloworld());
console.log("--------------in---------test---------------");
var finalData;
//Write data
function writeData(toSave){
//Create
var eleLink = document.createElement('a');
eleLink.download = "flight.csv";
eleLink.style.display = 'none';
var strData = "\ufeff" + "订单详情,订单总价,订单状态,操作,\r" + toSave;
var objFile = new Blob([strData],{type: 'text/csv,charset=UTF-8'});
eleLink.href = (window.URL || window.webkitURL).createObjectURL(objFile);
//Append
document.body.appendChild(eleLink);
//Click
eleLink.click();
//Remove
document.body.removeChild(eleLink);
}
//Append button to main page
function appendButton(savecontent) {
//Prepare button
/*
var a = document.createElement("a");
var li = document.createElement("li");
var ul = document.getElementsByClassName("nav-bar-set")[0];
a.textContent = "下载";
a.setAttribute('id', "downloadFlight");
a.setAttribute('href', "javascript:void(0)");
li.setAttribute('class', "set-list");
li.appendChild(a);
// ul.appendChild(li);
*/
var btnHtml = '下载表格';
$(".sbtn_box").append(btnHtml);
}
//Download flights
function downloadFlight(){
var newWindow;
var nextPage;
var newURL;
//Collect 1st page data
finalData = GetData(this.document);
//Collect data of rest page(s)
nextPage = document.getElementsByClassName("schedule_down")[0];
if(nextPage){
//original nextPage.href is http, main page is https.
newURL = nextPage.href.replace(/http/, "https");
//New window
newWindow = window.open(newURL, "FilghtWindow", "directories=no,resizable=no, width=400, height=400");
newWindow.focus();
var winLoaded = function(){
//Collect rest
finalData = finalData + GetData(newWindow.document);
//Next
nextPage = newWindow.document.getElementsByClassName("schedule_down")[0];
if (nextPage){
newURL = nextPage.href.replace(/http/, "https");
newWindow.location.replace(newURL);
}else{
//Finish
console.log(finalData);
writeData(finalData);
newWindow.close();
}
}
var winUnloaded = function(){
setTimeout(function(){
newWindow.onload= winLoaded;
newWindow.onunload = winUnloaded;
},0);
}
//add handle
newWindow.onload= winLoaded;
newWindow.onunload = winUnloaded;
}
}
//Get data from page
function GetData(docData){
//Get table
var tblRows = $(".fltlist_table > tbody > tr",docData);
var lngRowLength;
if (!tblRows && typeof(tblRows)!="undefined" && tblRows!=0){
alert("Cannot find table: fltlist_table");
return;
}
lngRowLength = tblRows.length;
//console.log(lngRowLength);
//Traverse
var aryData = [lngRowLength];
var strTmp = "";
var strData = "";
for(var i=0; i {
//Append button and its click function
appendButton("");
// document.getElementById("downloadFlight").onclick = function () {
// downloadFlight();
// };
});
*/
//Impoartnt:select a element from aother window
//$("a.schedule_down",newWindow.document)[0].click();
//Impoartnt:select a element from aother window
})();