Skip to content

Instantly share code, notes, and snippets.

View 52cik's full-sized avatar

楼教主 52cik

View GitHub Profile
@52cik
52cik / hasClass.js
Created March 13, 2016 12:27
hasClass 测试
var some = Array.prototype.some;
function hasClass1(name){
if (!name) {
return false
}
return some.call(this, function(el){
return this.test(el.className)
}, new RegExp('(^|\\s)' + name + '(\\s|$)'));
@52cik
52cik / visibilitychange.js
Created March 13, 2016 12:32
页面可见性事件 - 标签页被隐藏或显示
(function(document) { // title提示
var titleTime;
var oldTitle = document.title;
var shortcut = document.getElementById('shortcut');
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
document.title = '(●—●)咦,去哪儿啊?';
clearTimeout(titleTime);
shortcut.href = 'images/fail.ico';
@52cik
52cik / assert.html
Created March 15, 2016 02:52
js assert 断言函数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Suite</title>
<style>
#results li.pass {color: green;}
#results li.fail {color: red;}
</style>
</head>
@52cik
52cik / events.js
Created March 15, 2016 03:51
jQuery 事件查看
var nodes = document.getElementsByTagName("*");
var events = [];
ev = lookEvents(document);
if (ev) {
events.push({el: document, ev: ev});
}
for (var i=0, l=nodes.length; i<l; i++) {
var ev = lookEvents(nodes[i]);
@52cik
52cik / client.php
Last active April 4, 2016 09:24
php 伪造IP及来源
<?php
$headers = [ // 构造IP
'CLIENT-IP: 8.8.8.8',
'X-FORWARDED-FOR: 8.8.8.8',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:8000/server.php');
curl_setopt($ch, CURLOPT_REFERER, 'http://www.baidu.com/'); // 构造来路
@52cik
52cik / debug.js
Created April 9, 2016 03:57
监控js错误并上报
// 源: https://sf-static.b0.upaiyun.com/v-5703995e/global/js/debug.js
/*
监控js错误并上报
wtser@sf.gg
*/
window.onerror = function(msg, url, line, col, error) {
if (msg !== "Script error." && !url) {
return true;
}
@52cik
52cik / 1px-gif.html
Created May 21, 2016 13:20
1x1px 透明 gif 的 base64 代码
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=">
@52cik
52cik / .gitattributes
Created August 12, 2016 10:27
忽略 github 归档文件
# Ignore all test and documentation for archive
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/tests export-ignore
/docs export-ignore
@52cik
52cik / ls.js
Created September 1, 2016 12:19
简易 localStorage/sessionStorage 封装
(function(window, undefined) {
// 编码
function encode(str) {
return encodeURIComponent(JSON.stringify(str));
}
// 解码
function decode(str) {
if (undefined == str) {
@52cik
52cik / crockford-style.js
Created September 26, 2016 12:15 — forked from nolanlawson/crockford-style.js
Updated IIFE benchmark
var s = performance.now();
/**
* Copyright (c) 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
(function () { 'use strict';var SLICE$0 = Array.prototype.slice;