“百度網盤”程序做的比較爛,以百度的技術實力按說不應該如此。真正試了就知道真的不怎么樣。
? 為了統計百度網盤的文件寫了以下腳本,僅供參考:
var root = "";//指定目錄,空取當前目錄
var totalCount = 0;
var startTime = new Date();
function timeSpan(stime, etime) {var usedTime = etime - stime;var days = Math.floor(usedTime / (24 * 3600 * 1000));var leave1 = usedTime % (24 * 3600 * 1000);var hours = Math.floor(leave1 / (3600 * 1000));var leave2 = leave1 % (3600 * 1000);var minutes = Math.floor(leave2 / (60 * 1000));var leave3 = leave2 % (60 * 1000);var seconds = Math.round(leave3 / 1000);var time ="";if(days>0){time+=days+"天";}if(hours>0){time+=hours+"小時";}if(minutes>0){time+=minutes+"分鐘";}time+=seconds+"秒";return time;
} (function($){$.getUrlParam = function (name) {var search = document.location.hash;var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");var matcher = pattern.exec(search);var items = null;if (null != matcher) {try {items = decodeURIComponent(decodeURIComponent(matcher[1]));} catch (e) {try {items = decodeURIComponent(matcher[1]);} catch (e) {items = matcher[1];}}}return items;}
})(jQuery);if(root=="")
{root=$.getUrlParam("path");
}function GetFilesCount(fileLists)
{var count=0;var fl=fileLists.length;for (var index=0; index<fl; index++) { (function(index) { var file=fileLists[index];if(file.isdir==0){count++;totalCount++;}else if(file.isdir==1){count=count+GetDirFilsCount(file.path);}})(index); } return count;
}function GetDirFilsCount(dirName)
{var dfCount=0;$.ajax({url: 'https://pan.baidu.com/api/list?dir='+dirName,type: 'get',async: true,//true 異步,false 同步success: function(data) {var fileLists = data.list;dfCount=GetFilesCount(fileLists); console.log(decodeURIComponent(dirName)+":"+dfCount);console.log("統計目錄為:“"+decodeURIComponent(root)+"” 當前計算總數:"+totalCount+" 用時:" +timeSpan(startTime, new Date()));}});return dfCount;
}GetDirFilsCount(root);
執行過程截圖(異步 測試目錄用時10秒):
執行過程截圖(同步 測試目錄用時49秒):