// ==UserScript== // @name Coding Repos Size // @version 1.0.0 // @description Coding仓库大小统计 // @author Jack.Chan (971546@qq.com) // @namespace http://fulicat.com // @url https://greasyfork.org/zh-CN/scripts/475875-coding-repos-size // @match https://*.coding.net/api/repos* // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/475875/Coding%20Repos%20Size.user.js // @updateURL https://update.greasyfork.icu/scripts/475875/Coding%20Repos%20Size.meta.js // ==/UserScript== (function(){ function formatSize(size) { if (size === 0) return '0 B'; // var k = 1000; // or 1024 var k = 1024; // or 1024 size = size * k; var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; var i = Math.floor(Math.log(size) / Math.log(k)); return (size / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i]; } var $style = document.createElement('style'); $style.setAttribute('type', 'text/css'); $style.innerText = ` .loading{ text-align: center; padding: 50px 20px; } table{ border-collapse: collapse; width: 100%; } table th{ background: #f5f5f5; } table, table th, table td{ border: 1px solid #e5e5e5; } table th, table td{ padding: 2px 5px; } `; var profile = location.host.split('.')[0]; console.log('profile:', profile); if (!profile) { return console.error('出现异常了哇!'); } document.title = 'Coding Repos Size - by Jack.Chan'; var $body = document.body; var $result = document.createElement('div'); var $loading = document.createElement('p'); $loading.className = 'loading'; $loading.innerText = '加载中...'; $result.appendChild($loading); $body.innerHTML = ''; $body.appendChild($style); $body.appendChild($result); var baseURL = `https://${ profile }.coding.net`; fetch(`${ baseURL }/api/user/shebaochina/depots?type=ALL`, { method: 'GET' }).then((res) => res.json()).then((res) => { $loading.innerText = '计算中...'; console.log('res:', res); res.data.sort((a, b)=>{ return b.size - a.size; }); // res.data = res.data.sort((a, b) => { // return a.size - b.size // }); var totalSize = 0; var html = []; html.push(`
接口出错了哇!
'; console.error(err); }); })();