7 js function
debounce = function debounce(func, wait, immediate) { | |
var timeout; | |
return function() { | |
var context = this, args = arguments; | |
var later = function() { | |
timeout = null; | |
if (!immediate) func.apply(context, args); | |
}; | |
var callNow = immediate && !timeout; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
if (callNow) func.apply(context, args); | |
}; | |
}; | |
poll = function poll(fn, callback, errback, timeout, interval) { | |
var endTime = Number(new Date()) + (timeout || 2000); | |
interval = interval || 100; | |
(function p() { | |
// If the condition is met, we're done! | |
if(fn()) { | |
callback(); | |
} | |
// If the condition isn't met but the timeout hasn't elapsed, go again | |
else if (Number(new Date()) < endTime) { | |
setTimeout(p, interval); | |
} | |
// Didn't match and too much time, reject! | |
else { | |
errback(new Error('timed out for ' + fn + ': ' + arguments)); | |
} | |
})(); | |
} | |
once = function once(fn, context) { | |
var result; | |
return function() { | |
if(fn) { | |
result = fn.apply(context || this, arguments); | |
fn = null; | |
} | |
return result; | |
}; | |
} | |
getAbsoluteUrl = (function() { | |
var a; | |
return function(url) { | |
if(!a) a = document.createElement('a'); | |
a.href = url; | |
return a.href; | |
}; | |
})(); | |
(function(module) { | |
// Used to resolve the internal `[[Class]]` of values | |
var toString = Object.prototype.toString; | |
// Used to resolve the decompiled source of functions | |
var fnToString = Function.prototype.toString; | |
// Used to detect host constructors (Safari > 4; really typed array specific) | |
var reHostCtor = /^\[object .+?Constructor\]$/; | |
// Compile a regexp using a common native method as a template. | |
// We chose `Object#toString` because there's a good chance it is not being mucked with. | |
var reNative = RegExp('^' + | |
// Coerce `Object#toString` to a string | |
String(toString) | |
// Escape any special regexp characters | |
.replace(/[.*+?^${}()|[\]\/\\]/g, '\\$&') | |
// Replace mentions of `toString` with `.*?` to keep the template generic. | |
// Replace thing like `for ...` to support environments like Rhino which add extra info | |
// such as method arity. | |
.replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' | |
); | |
isNative = function isNative(value) { | |
var type = typeof value; | |
return type == 'function' | |
// Use `Function#toString` to bypass the value's own `toString` method | |
// and avoid being faked out. | |
? reNative.test(fnToString.call(value)) | |
// Fallback to a host object check because some environments will represent | |
// things like typed arrays as DOM methods which may not conform to the | |
// normal native pattern. | |
: (value && type == 'object' && reHostCtor.test(toString.call(value))) || false; | |
} | |
module.isNative = isNative; | |
}(window)); | |
sheet = (function() { | |
// Create the <style> tag | |
var style = document.createElement('style'); | |
// Add a media (and/or media query) here if you'd like! | |
// style.setAttribute('media', 'screen') | |
// style.setAttribute('media', 'only screen and (max-width : 1024px)') | |
// WebKit hack :( | |
style.appendChild(document.createTextNode('')); | |
// Add the <style> element to the page | |
document.head.appendChild(style); | |
return style.sheet; | |
})(); | |
matchesSelector = function matchesSelector(el, selector) { | |
var p = Element.prototype; | |
var f = p.matches || p.webkitMatchesSelector || p.mozMatchesSelector || p.msMatchesSelector || function(s) { | |
return [].indexOf.call(document.querySelectorAll(s), this) !== -1; | |
}; | |
return f.call(el, selector); | |
} | |
alert('loaded'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
solsend2l commentedJan 6, 2016
Bookmarklet!
javascript:(function(){;debounce=function%20debounce(func,wait,immediate)%7Bvar%20timeout;return%20function()%7Bvar%20context=this,args=arguments;var%20later=function()%7Btimeout=null;if(!immediate)func.apply(context,args)%7D;var%20callNow=immediate&&!timeout;clearTimeout(timeout);timeout=setTimeout(later,wait);if(callNow)func.apply(context,args)%7D%7D;poll=function%20poll(fn,callback,errback,timeout,interval)%7Bvar%20endTime=Number(new%20Date)+(timeout%7C%7C2e3);interval=interval%7C%7C100;(function%20p()%7Bif(fn())%7Bcallback()%7Delse%20if(Number(new%20Date)%3CendTime)%7BsetTimeout(p,interval)%7Delse%7Berrback(new%20Error(%22timed%20out%20for%20%22+fn+%22:%20%22+arguments))%7D%7D)()%7D;once=function%20once(fn,context)%7Bvar%20result;return%20function()%7Bif(fn)%7Bresult=fn.apply(context%7C%7Cthis,arguments);fn=null%7Dreturn%20result%7D%7D;getAbsoluteUrl=function()%7Bvar%20a;return%20function(url)%7Bif(!a)a=document.createElement(%22a%22);a.href=url;return%20a.href%7D%7D();(function(module)%7Bvar%20toString=Object.prototype.toString;var%20fnToString=Function.prototype.toString;var%20reHostCtor=/%5E%5C%5Bobject%20.+?Constructor%5C%5D$/;var%20reNative=RegExp(%22%5E%22+String(toString).replace(/%5B.+?%5E$%7B%7D()%7C%5B%5C%5D%5C/%5C%5C%5D/g,%22%5C%5C$&%22).replace(/toString%7C(function).?(?=%5C%5C%5C()%7C%20for%20.+?(?=%5C%5C%5C%5D)/g,%22$1.*?%22)+%22$%22);isNative=function%20isNative(value)%7Bvar%20type=typeof%20value;return%20type==%22function%22?reNative.test(fnToString.call(value)):value&&type==%22object%22&&reHostCtor.test(toString.call(value))%7C%7Cfalse%7D;module.isNative=isNative%7D)(window);sheet=function()%7Bvar%20style=document.createElement(%22style%22);style.appendChild(document.createTextNode(%22%22));document.head.appendChild(style);return%20style.sheet%7D();matchesSelector=function%20matchesSelector(el,selector)%7Bvar%20p=Element.prototype;var%20f=p.matches%7C%7Cp.webkitMatchesSelector%7C%7Cp.mozMatchesSelector%7C%7Cp.msMatchesSelector%7C%7Cfunction(s)%7Breturn%5B%5D.indexOf.call(document.querySelectorAll(s),this)!==-1%7D;return%20f.call(el,selector)%7D;alert(%22loaded%22);})()