MCPcopy Index your code
hub / github.com/hoothin/UserScripts / downOnce

Function downOnce

DownloadAllContent/DownloadAllContent.user.js:1098–1389  ·  view source on GitHub ↗
(wait)

Source from the content-addressed store, hash-verified

1096 var insertSigns=[];
1097 // var j=0,rCats=[];
1098 var downIndex=0,downNum=0,downOnce=function(wait){
1099 if(downNum>=aEles.length)return;
1100 if(maxDlPerMin){
1101 if(dlCount===-1){
1102 setTimeout(() => {
1103 downOnce(wait);
1104 }, minute);
1105 return;
1106 }else if(dlCount>=maxDlPerMin){
1107 dlCount=-1;
1108 setTimeout(() => {
1109 dlCount=0;
1110 downOnce(wait);
1111 }, minute);
1112 return;
1113 }else dlCount++;
1114 }
1115 let curIndex=downIndex;
1116 let aTag=aEles[curIndex];
1117 let request=(aTag, curIndex)=>{
1118 if (aTag && aTag.cloneNode) {
1119 aTag = aTag.cloneNode(true);
1120 }
1121 let tryTimes=0;
1122 let validTimes=0;
1123 function requestDoc(_charset) {
1124 if (!_charset) _charset = charset;
1125 return GM_xmlhttpRequest({
1126 method: 'GET',
1127 url: aTag.href,
1128 headers:{
1129 referer:aTag.href,
1130 "Content-Type":"text/html;charset="+_charset
1131 },
1132 timeout:10000,
1133 overrideMimeType:"text/html;charset="+_charset,
1134 onload: async function(result) {
1135 let doc = getDocEle(result.responseText);
1136 if (charsetValid) {
1137 let equiv = doc.querySelector('[http-equiv="Content-Type"]');
1138 if (equiv && equiv.content) {
1139 let innerCharSet = equiv.content.match(/charset\=([^;]+)/);
1140 if (innerCharSet && innerCharSet[1].replace("-", "").toLowerCase() != _charset.replace("-", "").toLowerCase()) {
1141 charset = innerCharSet[1];
1142 return requestDoc(charset);
1143 }
1144 }
1145 }
1146 downIndex++;
1147 downNum++;
1148 if (/^{/.test(result.responseText)) {
1149 doc.json = () => {
1150 try {
1151 return JSON.parse(result.responseText);
1152 } catch(e) {}
1153 return {};
1154 }
1155 }

Callers 3

requestDocFunction · 0.85
checkIframeFunction · 0.85
indexDownloadFunction · 0.85

Calls 1

requestFunction · 0.85

Tested by

no test coverage detected