Skip to content

Instantly share code, notes, and snippets.

@hackerxian
hackerxian / gist:2bc8977b95112660b7f96df4522cd4d6
Created September 30, 2018 02:16
module require and define
(function(global) {
if (global.define) {
return;
}
/* eslint strict:0 */
var modules = {};
var inGuard = false;
function def(id, deps, factory) {
@hackerxian
hackerxian / sinaimg.js
Last active September 5, 2017 07:02 — forked from mysteriouss/sinaimg.js
//http://www.cnblogs.com/gaizai/p/4233780.html
//https://www.v2ex.com/t/388152?p=2
(function () {
'use strict';
function string10to62(number) {
var chars = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ'.split('');
var radix = chars.length;
var qutient = +number;
var arr = [];
/*
* Copyright (c) 2010 Apple Inc. All rights reserved.
*/
function characterNeedsScoreMultiplier(e) {
if (!e || e.length === 0)
return !1;
var t = e.charCodeAt(0);
return t > 11904 && t < 12031?!0 : t > 12352 && t < 12543?!0 : t > 12736 && t < 19903?!0 : t > 19968 && t < 40959?!0 : t > 44032 && t < 55215?!0 : t > 63744 && t < 64255?!0 : t > 65072 && t < 65103?!0 : t > 131072 && t < 173791?!0 : t > 194560 && t < 195103?!0 : !1
}
function domDistance(e, t, n) {
@hackerxian
hackerxian / isElementInViewport.js
Created October 6, 2016 09:20
判断元素是否视窗内
//http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport/7557433#7557433
function isElementInViewport (el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
@hackerxian
hackerxian / getText.md
Created March 4, 2016 07:13
获取标签内部的文本内容但是不获取该标签中的其他标签的文本
<div>
    <p>内容<span>我不获取的内容</span>内容</p>
</div>
var str = $('div p').contents().filter(function (index, content) {
    return content.nodeType === 3;
}).text();
TESTS = $(shell ls -S `find test -type f -name "*.test.js" -print`)
REPORTER = spec
TIMEOUT = 10000
MOCHA_OPTS =
install:
@tnpm install
standard:
@node_modules/.bin/standard
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
@hackerxian
hackerxian / gist:ac7409993ae790288f09
Created December 8, 2015 05:36
update url parameter
function addOrUpdateUrlParam(name, value) {
var href = window.location.href;
var regexPage = /[&\?]page=\d+/;
href = decodeURIComponent(href.replace(regexPage, ""));
var regex = new RegExp("[&\\?]" + name + "=");
if (regex.test(href)) {
//regex = new RegExp("([&\\?])" + name + "=(\\w+(,\\w+)\*)");
regex = new RegExp("([&\\?])" + name + "=((\\w+(,\\w+)\*)|([\\u4e00-\\u9fa5]*\\/?[\\u4e00-\\u9fa5]\*))");
if (regex.test(href)) {
window.location.href = href.replace(regex, "$1" + name + "=" + value);
//PhantomJS http://phantomjs.org/ based web crawler Anton Ivanov [email protected] 2012
//UPDATE: This gist has been made into a Node.js module and now can be installed with "npm install js-crawler"
//the Node.js version does not use Phantom.JS, but the API available to the client is similar to the present gist
(function(host) {
function Crawler() {
this.visitedURLs = {};
};
// This example shows how to render pages that perform AJAX calls
// upon page load.
//
// Instead of waiting a fixed amount of time before doing the render,
// we are keeping track of every resource that is loaded.
//
// Once all resources are loaded, we wait a small amount of time
// (resourceWait) in case these resources load other resources.
//
// The page is rendered after a maximum amount of time (maxRenderTime)