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 getConstellation(month, day){ | |
const cons = ["摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座"]; | |
const divide = [20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22]; | |
const m = month - 1; | |
const d = day; | |
return cons[m + (divide[m] <= d)]; | |
} |
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
/** | |
* y:年, | |
* M:年中的月份(1-12), | |
* d:月份中的天(1-31), | |
* h:小时(0-23), | |
* m:分(0-59), | |
* s:秒(0-59), | |
* S:毫秒(0-999), | |
* q:季度(1-4) | |
*/ |
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()}) |
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
// (∑(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
/** | |
* 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
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
// 包装执行生成器 | |
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
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
;(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'; |
OlderNewer