Tips
统计 Github 代码行数
'use strict';
//replace jquery/jquery with the repo you're interested in
fetch('https://api.github.com/repos/jquery/jquery/stats/contributors')
.then((response) => response.json())
.then((contributors) =>
contributors.map((contributor) => contributor.weeks.reduce((lineCount, week) => lineCount + week.a - week.d, 0)),
)
.then((lineCounts) => lineCounts.reduce((lineTotal, lineCount) => lineTotal + lineCount))
.then((lines) => window.alert(lines));
JS 载入脚本
// jQuery
$.getScript('script.js');
// vanilla
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'script.js';
document.head.appendChild(script);
// 简化版
document.head.appendChild(
Object.assign(document.createElement('script'), {
src: 'https://rawgit.com/js-cookie/js-cookie/master/src/js.cookie.js',
}),
);
// 可添加完成监听
document.head.appendChild(
Object.assign(document.createElement('script'), {
src: 'https://code.jquery.com/jquery-2.2.3.js',
onload: () => console.log('Load Complete'),
}),
);
常用脚本
- https://rawgit.com/js-cookie/js-cookie/master/src/js.cookie.js
- https://code.jquery.com/jquery-1.12.3.js
- https://code.jquery.com/jquery-2.2.3.js
- https://raw.githubusercontent.com/lodash/lodash/4.12.0/dist/lodash.js
- https://cdn.socket.io/socket.io-1.4.5.js