NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name BaiduFilesSize // @namespace https://openuserjs.org // @version 0.5 // @description 计算百度分享总文件大小 Baidu Sharelink Files Size! // @author Mike // @match https://pan.baidu.com/s/* // @grant unsafeWindow // @require http://code.jquery.com/jquery-1.11.0.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js // @copyright 2019, mikecoding (https://openuserjs.org/users/mikecoding) // @updateURL https://openuserjs.org/meta/mikecoding/BaiduFilesSize.meta.js // @license MIT // ==/UserScript== (function () { 'use strict'; /* var files = document.getElementsByClassName("file-size"); var filesize=0; for(var i=0;i<files.length;i++){ var filesize = document.getElementsByClassName("file-size")[i].innerText; } */ var sizeList = Array(); var panAPIUrl = location.protocol + "//" + location.host + "/api/"; var shareListUrl = location.protocol + "//" + location.host + "/share/list"; var restAPIUrl = location.protocol + "//pcs.baidu.com/rest/2.0/pcs/"; var clientAPIUrl = location.protocol + "//d.pcs.baidu.com/rest/2.0/pcs/"; var channel = 'chunlei'; var clienttype = 0; var app_id = 250528; var web = 1; var uk = yunData.SHARE_UK; var shareid = yunData.SHARE_ID; function signFnc() { return yunData.sign; } function getBDStoken() { return yunData.MYBDSTOKEN; } var sign = getSign(); var timestamp = getTimestamp(); var bdstoken = getBDStoken(); var logid = getLogID(); function getPaths(url) { var regx = /[/].*/i; var result = url.match(regx); return decodeURIComponent(result); } /* function getPaths(url){ var regx =url.lastIndexOf("/"); var result = url.substr(regx); return decodeURIComponent(result); } */ function getPath() { var hash = location.hash; var regx = /(^|&|\/)path=([^&]*)(&|$)/i; var result = hash.match(regx); return decodeURIComponent(result[2]); } function base64Encode(t) { var a, r, e, n, i, s, o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; for (e = t.length, r = 0, a = ""; e > r;) { if (n = 255 & t.charCodeAt(r++), r == e) { a += o.charAt(n >> 2); a += o.charAt((3 & n) << 4); a += "=="; break; } if (i = t.charCodeAt(r++), r == e) { a += o.charAt(n >> 2); a += o.charAt((3 & n) << 4 | (240 & i) >> 4); a += o.charAt((15 & i) << 2); a += "="; break; } s = t.charCodeAt(r++); a += o.charAt(n >> 2); a += o.charAt((3 & n) << 4 | (240 & i) >> 4); a += o.charAt((15 & i) << 2 | (192 & s) >> 6); a += o.charAt(63 & s); } return a; } function getTimestamp() { return yunData.timestamp; } function getSign() { return yunData.sign; /* var signFnc; try{ signFnc = new Function("return " + yunData.sign2)(); } catch(e){ throw new Error(e.message); } return base64Encode(signFnc(yunData.sign5,yunData.sign1)); */ } function getLogID() { var name = "BAIDUID"; var u = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/~!@#¥%……&"; var d = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g; var f = String.fromCharCode; function l(e) { if (e.length < 2) { var n = e.charCodeAt(0); return 128 > n ? e : 2048 > n ? f(192 | n >>> 6) + f(128 | 63 & n) : f(224 | n >>> 12 & 15) + f(128 | n >>> 6 & 63) + f(128 | 63 & n); } var n = 65536 + 1024 * (e.charCodeAt(0) - 55296) + (e.charCodeAt(1) - 56320); return f(240 | n >>> 18 & 7) + f(128 | n >>> 12 & 63) + f(128 | n >>> 6 & 63) + f(128 | 63 & n); } function g(e) { return (e + "" + Math.random()).replace(d, l); } function m(e) { var n = [0, 2, 1][e.length % 3]; var t = e.charCodeAt(0) << 16 | (e.length > 1 ? e.charCodeAt(1) : 0) << 8 | (e.length > 2 ? e.charCodeAt(2) : 0); var o = [u.charAt(t >>> 18), u.charAt(t >>> 12 & 63), n >= 2 ? "=" : u.charAt(t >>> 6 & 63), n >= 1 ? "=" : u.charAt(63 & t)]; return o.join(""); } function h(e) { return e.replace(/[\s\S]{1,3}/g, m); } function p() { return h(g((new Date()).getTime())); } function w(e, n) { return n ? p(String(e)).replace(/[+\/]/g, function (e) { return "+" == e ? "-" : "_"; }).replace(/=/g, "") : p(String(e)); } return w(getCookie(name)); } function getCookie(e) { var o, t; var n = document, c = decodeURI; return n.cookie.length > 0 && (o = n.cookie.indexOf(e + "="), -1 != o) ? (o = o + e.length + 1, t = n.cookie.indexOf(";", o), -1 == t && (t = n.cookie.length), c(n.cookie.substring(o, t))) : ""; } function getFileList() { var result = []; if (getPath() == '/') { result = yunData.FILEINFO; } else { logid = getLogID(); var params = { uk: uk, shareid: shareid, order: 'other', desc: 1, showempty: 0, web: web, dir: getPath(), t: Math.random(), bdstoken: bdstoken, channel: channel, clienttype: clienttype, app_id: app_id, logid: logid }; $.ajax({ url: shareListUrl, method: 'GET', async: false, data: params, success: function (response) { if (response.errno === 0) { result = response.list; } } }); } return result; } function getFileLists(path) { var result = []; if (path == '/') { result = yunData.FILEINFO; } else { logid = getLogID(); var params = { uk: uk, shareid: shareid, order: 'other', desc: 1, showempty: 0, web: web, dir: path, t: Math.random(), bdstoken: bdstoken, channel: channel, clienttype: clienttype, app_id: app_id, logid: logid }; $.ajax({ url: shareListUrl, method: 'GET', async: false, data: params, success: function (response) { if (response.errno === 0) { result = response.list; } } }); } return result; } function recurseSize(url) { var list = getFileLists(url); console.log(list); for (var i = 0; i < list.length; i++) { sizeList.push(list[i].size); if (list[i].isdir == 1) { var pathz = getPaths(list[i].path); console.log(pathz); recurseSize(pathz); } } return true; } /* function getFileList(){ var filelist = []; var listUrl = panAPIUrl + "list"; var path = getPath(); logid = getLogID(); var params = { dir:path, bdstoken:bdstoken, logid:logid, order:'size', desc:0, clienttype:0, showempty:0, web:1, channel:'chunlei', appid:250528 }; $.ajax({ url:listUrl, async:false, method:'GET', data:params, success:function(response){ filelist = 0===response.errno ? response.list : []; } }); return filelist; } */ // $(document).ready(function (){$("<input onclick='alert(getFileList())' />").appendTo("body");}); // $(".icon icon-qrcode").bind('click', function (e) { alert(getFileList()); }); function selectS() { $('#cp').select(); } $(document).ready(function () { recurseSize("/"); fetchAllSize() $('<button id="copy">Copy Size</button>').appendTo(".title-funcs"); $("#copy").bind('click', selectS); }); $("em.icon-qrcode").bind('click', ); function fetchAllSize() { console.log(sizeList); var sumSize = 0; for (var j = 0; j < sizeList.length; j++) { sumSize = sumSize + sizeList[j] / 1024 / 1024; } console.log("总共大小为" + sumSize); //$(".share-file-info").text((sumSize^0)); //$(".share-file-info").html("<input id='cp' value='"+(sumSize^0)+"' />"); //$(".share-valid-check").text("MB"); //alert("总共大小为"+(sumSize^0)+"MB"); $("<input id='cp' value='" + (sumSize.toFixed(2)) + "' />").appendTo(".title-funcs"); $("<label> MB</label>").appendTo(".title-funcs"); } })();