Sph*_*xxx 22
如果没有正式的方法,这里有一个书签,它使用GitHub的API来添加大小信息(在IE中不起作用):
javascript:(function(){function u(n){var r=document.querySelector('table.files a[title="'+n.name+'"]'),i=r.closest("tr").querySelector("td.age"),t=document.createElement("td");n.type==="file"&&(t.textContent=(n.size/1024).toLocaleString("en-US",{minimumFractionDigits:1,maximumFractionDigits:1})+" KB",t.style.textAlign="right");i.parentNode.insertBefore(t,i)}var n=window.location.pathname.split("/"),t,r,i;n[0].length===0&&(n=n.slice(1));t=["https://api.github.com/repos",n[0],n[1],"contents"];n.length>2&&(n.length>4&&(t=t.concat(n.slice(4))),r=n[3]);i=t.join("/");r&&(i+="?ref="+r);console.log(i);fetch(i).then(n=>n.json()).then(n=>{Array.isArray(n)&&n.forEach(u)})})()
Run Code Online (Sandbox Code Playgroud)
未经授权的来源:
(function () {
"use strict";
//Parse the current GitHub repo url. Examples:
// Repo root: /Sphinxxxx/vanilla-picker
// Subfolder: /Sphinxxxx/vanilla-picker/tree/master/src/css
// Subfolder at commit: /Sphinxxxx/vanilla-picker/tree/382231756aac75a49f046ccee1b04263196f9a22/src/css
// Subfolder at tag: /Sphinxxxx/vanilla-picker/tree/v2.2.0/src/css
//
//If applicable, the name of the commit/branch/tag is always the 4th element in the url path.
//Here, we put that in the "ref" variable:
const [/* Leading slash */, owner, repo, /* "tree" */, ref, ...path] = window.location.pathname.split('/');
//Create the URL to query GitHub's API: https://developer.github.com/v3/repos/contents/#get-contents
//Example:
// https://api.github.com/repos/Sphinxxxx/vanilla-picker/contents/src/css?ref=382231756aac75a49f046ccee1b04263196f9a22
const query = ['https://api.github.com/repos', owner, repo, 'contents'].concat(path || []),
url = query.join('/') + (ref ? '?ref=' + ref : '');
console.log(url);
//https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
fetch(url).then(r => r.json())
.then(j => Array.isArray(j) ? j.forEach(handleFileInfo) : console.warn(j));
function handleFileInfo(info) {
//console.log(info);
const link = document.querySelector('table.files a[title="' +info.name+ '"]');
const ageCol = link.closest('tr').querySelector('td.age');
const sizeCell = document.createElement('td');
if(info.type === 'file') {
//http://stackoverflow.com/a/17663871/1869660
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Parameters
sizeCell.textContent = (info.size/1024).toLocaleString('en-US', { minimumFractionDigits: 1, maximumFractionDigits: 1 }) + ' KB';
sizeCell.style.textAlign = 'right';
}
ageCol.parentNode.insertBefore(sizeCell, ageCol);
}
})();
Run Code Online (Sandbox Code Playgroud)
不,GitHub 文件浏览器不能以这种方式配置。
取回这些额外信息意味着要为 GitHub 传输大量额外数据(每个存储库的每个页面),因此我不确定您是否会很快看到此功能。
请注意,“大小”是 GitHub 搜索的可接受标准(这意味着大小信息存在并且可以使用,而不仅仅是用于浏览文件)。
将代码与标记为 XML 且正好有 100 个字节的“元素”一词相匹配。
| 归档时间: |
|
| 查看次数: |
2537 次 |
| 最近记录: |