MCPcopy
hub / github.com/hoothin/UserScripts / fetch

Function fetch

DownloadAllContent/DownloadAllContent.user.js:1719–1759  ·  view source on GitHub ↗
(forceSingle)

Source from the content-addressed store, hash-verified

1717 }
1718
1719 async function fetch(forceSingle){
1720 forceSingle=forceSingle===true;
1721 processFunc=null;
1722 initTxtDownDiv();
1723 var aEles=document.body.querySelectorAll("a"),list=[];
1724 txtDownWords.innerHTML=`Analysing ( 1/${aEles.length} )......`;
1725 txtDownContent.style.pointerEvents="none";
1726 for(var i=0;i<aEles.length;i++){
1727 if (i % 100 == 0) {
1728 await sleep(1);
1729 }
1730 txtDownWords.innerHTML=`Analysing ( ${i + 1}/${aEles.length} )......`;
1731 var aEle=aEles[i],has=false;
1732 if(aEle.dataset.href && (!aEle.href || aEle.href.indexOf("javascript")!=-1)){
1733 aEle.href=aEle.dataset.href;
1734 }
1735 if(aEle.href==location.href)continue;
1736 for(var j=0;j<list.length;j++){
1737 if(list[j].href==aEle.href){
1738 aEle=list[j];
1739 list.splice(j,1);
1740 list.push(aEle);
1741 has=true;
1742 break;
1743 }
1744 }
1745 if(!has && aEle.href && /^http/i.test(aEle.href) && ((aEle.innerText.trim()!="" && indexReg.test(aEle.innerText.trim())) || /chapter[\-_]?\d/.test(aEle.href))){
1746 list.push(aEle);
1747 }
1748 }
1749 txtDownContent.style.display="none";
1750 txtDownContent.style.pointerEvents="";
1751 txtDownWords.innerHTML="Analysing......";
1752 if(list.length>2 && !forceSingle){
1753 useIframe = false;
1754 filterList(list);
1755 }else{
1756 var blob = new Blob([i18n.info.replace("#t#", location.href)+"\r\n\r\n"+document.title+"\r\n\r\n"+getPageContent(document)], {type: "text/plain;charset=utf-8"});
1757 saveAs(blob, document.title+".txt");
1758 }
1759 }
1760
1761 function customDown(urls){
1762 processFunc = null;

Callers 14

downloadByFetchFunction · 0.85
_getBlobSizeMethod · 0.85
urlToBlobWithFetchFunction · 0.85
downloadPageFunction · 0.85
pvcep_rules.jsFile · 0.85
dist.user.jsFile · 0.85
_getBlobSizeMethod · 0.85
urlToBlobWithFetchFunction · 0.85
downloadPageFunction · 0.85

Calls 4

initTxtDownDivFunction · 0.85
filterListFunction · 0.85
getPageContentFunction · 0.85
sleepFunction · 0.70

Tested by

no test coverage detected