Skip to content

Instantly share code, notes, and snippets.

Bryan Yang BryanYang

Block or report user

Report or block BryanYang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@BryanYang
BryanYang / loop_label.js
Created Jan 25, 2019
the javascript code you don't know.
View loop_label.js
function gogogo() {
firstLoop:
for (let outer = 0; outer < 4; outer++) {
secondLoop:
for (let inner = 0; inner < 5; inner++) {
if (inner === 3) {
// Use continue to avoid runs 4 and 5
continue firstLoop;
}
console.warn(`outer: ${outer}; inner: ${inner}`);
@BryanYang
BryanYang / prefetch.js
Created Jan 23, 2019
动态prefetch下个页面的资源,提升用户首次体验。
View prefetch.js
requestIdleCallback(() => {
fetch("xxx/a.html").then(res => res.text()).then(html => {
const reg = /target*.js/gi;
const scripts = html.match(reg);
if(scripts && scripts.length) {
scripts.forEach(src => {
const link = document.createElement("link");
link.rel = "prefetch";
link.href = src;
document.head.appendChild(link);
View koa-proxy.ts
import Koa from 'koa';
const mnsUtil = require('@mtfe/mns-util');
const httpProxy = require('http-proxy');
import config = require('config');
const proxy = httpProxy.createProxyServer({
headers: {
Host: 'alitest.e.fanxiaojian.cn',
},
});
View array2tree.ts
/**
* 把平铺的 array 转成 树
*
* 比如原始数列:
* [
* {id: "13300", parentId: "13300", name: "蔬菜", status: 1},
* {id: "13301", parentId: "13301", name: "饮料", status: 1},
* {id: "13413", parentId: "13413", name: "青菜类", status: 1},
* {id: "13696", parentId: "13696", name: "肉类", status: 1},
View scriptable-packageQuery
// 快递地址从百度获取。(百度首页输入快递,查看请求url)
let url = "https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?appid=4001&com=zhongtong&nu=541247425507&vcode=&token=&_=1538102135046"
let req = new Request(url)
let json = await req.loadJSON()
let items = json.data.info.context
let table = new UITable()
for (item of items) {
let row = new UITableRow()
let time = item.time
let title = decode(item.desc)
@BryanYang
BryanYang / mutation-observer.html
Last active Sep 13, 2018
record user action with MutationObserver
View mutation-observer.html
<html>
<head>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<style>
.cls1 {
color: black;
}
.flex {
View utils.ts
// 测量字符串长度
export function measureText(pText: string, pFontSize: number) {
let lDiv = document.createElement('div');
document.body.appendChild(lDiv);
lDiv.style.fontSize = '' + pFontSize + 'px';
lDiv.style.position = 'absolute';
lDiv.style.visibility = 'hidden';
lDiv.innerHTML = pText;
You can’t perform that action at this time.