This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 根据经纬度计算两点间距离, {@link http://www.movable-type.co.uk/scripts/latlong.html} | |
* @param {Double} lng1 | |
* @param {Double} lat1 | |
* @param {Double} lng2 | |
* @param {Double} lat2 distance in KM | |
*/ | |
CoolWPDistance(lng1, lat1, lng2, lat2) { | |
if (!lng1 || !lat1 || !lng2 || !lat2) return null; | |
const R = 6371; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function request(method, url, data) { | |
method = method.toUpperCase(); | |
url = new URL(url); | |
const option = { | |
method, | |
"mode": "same-origin", | |
"credentials": "same-origin", | |
"headers": {}, | |
"redirect": "follow", | |
"referrer": "no-referrer", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function(root, factory) { | |
if (typeof module !== 'undefined' && module.exports) { | |
module.exports = factory(); | |
} else if (typeof define === 'function' && define.amd) { | |
define(factory); | |
} else { | |
root.Promise = factory.call(root); | |
} | |
})(this, function() { | |
'use strict'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (cf) { | |
return function () { | |
// 将参数传入上一次得到的不完全函数,得到下一个不完全函数 | |
const nextCF = cf.bind(null, ...arguments); | |
// 参数总长度达到原函数所需长度时,执行该函数 | |
if (nextCF.length <= 0) return nextCF(); | |
// 参数长度未达到原函数所需长度时,返回新的函数 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 包装执行生成器 | |
module.exports = function(generator) { | |
const g = generator(); | |
return (function loop(s) { | |
// 如果生成器执行结束则退出 | |
if (s.done) return; | |
// 获取 yield 得到的promise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Router { | |
constructor(routerMap) { | |
this.routerMap = { | |
// "/user/:user_id":{ | |
// "handler": function (userId) {}, | |
// "routerReg": new RegExp("^/user/[^/+]/?$") | |
// } | |
}; | |
// "/user/:group_id/:userId" => "/user/([^/]+)/([^/]+)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 1. %>...<% 转换为 %>p += '...';<%, 起始和结束同此, 将内容直接作为输出 | |
* 2. <%...%> 转换为 ...;, 逻辑处理, 直接执行 | |
* 3. <%=...%> 转换为 p += (...);, 将运算结果作为输出 | |
*/ | |
function render(tpl) { | |
return new Function("data", "var p = ''; with(data){" + | |
tpl.replace(/(\s)+/g, " ") | |
.replace(/(\%\>|^)(.+?)(\<\%|$)/g, "$1p += '$2';$3") | |
.replace(/\<\%([^=](.(?!\<\%))+)\%\>/g, "$1;") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (∑(ai×Wi)) % 11 | |
exports.checkIdNum = function(idNum) { | |
idNum = idNum.toUpperCase(); | |
const reg = /^\d{6}(19|20)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}[0-9X]$/; | |
if (!reg.test(idNum)) return false; | |
const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; | |
const parity = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"]; | |
const sum = factor.reduce((s, f, i) => s + f * idNum[i], 0); | |
return parity[sum % 11] === idNum[17] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encode(str) { | |
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) { | |
return String.fromCharCode('0x' + p1); | |
})); | |
} | |
function decode(str) { | |
return decodeURIComponent(atob(str).split('').map(function(c) { | |
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | |
}).join('')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 删除微博 | |
document.querySelector(".WB_feed").addEventListener("click", function(e) { | |
var card = e.target; | |
while(!card.matches(".WB_cardwrap")) card = card.parentElement; | |
fetch("//weibo.com/aj/mblog/del?ajwvr=6", { | |
method:"post", | |
credentials: "same-origin", | |
headers: {'content-type': "application/x-www-form-urlencoded"}, | |
body:"mid="+card.getAttribute("mid") | |
}).then(function(resp){return resp.text()}) |