Skip to content

Instantly share code, notes, and snippets.

@z-------------
z------------- / anchor-center.js
Last active August 29, 2015 13:56
Center an element on the screen
function gotoElem(sel) {
var targetElem = sel; // must be an element object, not a selector string
window.scrollTo(targetElem.offsetLeft+targetElem.offsetWidth/2-window.innerWidth/2,targetElem.offsetTop+targetElem.offsetHeight/2-window.innerHeight/2);
}
@z-------------
z------------- / pokeAll.js
Last active August 29, 2015 13:56
JavaScript for poking your Facebook friends back
// get poke buttons, including suggested pokes
var pokeButtons = document.querySelectorAll(".mls a._4jy0");
// exclude suggested pokes, because I couldn't find a way to do this using selectors ;_;
var pokeBacks = [];
for(i=0;i<pokeButtons.length;i++){
if(pokeButtons[i].parentNode.parentNode.parentNode.parentNode.innerHTML.indexOf("Suggested Poke") == -1){
pokeBacks.push(pokeButtons[i])
}
}
// click all poke buttons
@z-------------
z------------- / blacklight.html
Created March 4, 2014 00:11
JS + CSS fade effect
<style>
body {
opacity:0; /* invisible at first */
transition:opacity 1s; /* transition opacity for 1 second */
}
</style>
<script>
document.addEventListener("DOMContentLoaded",function(){ // equivalent to jQuery ready()
document.body.style.opacity = "1"; // set body's opacity to 1
@z-------------
z------------- / interval-test.js
Created March 4, 2014 00:29
Test speed of setInterval() against actual time
var I = 1;
var interval = setInterval(
function(){
console.log(I);
I++;
},1);
setTimeout(function(){clearInterval(interval)},1000);
@z-------------
z------------- / typingEffect.js
Created March 8, 2014 14:49
A nice-ish effect that looks a bit like when someone's typing
var typingEffect = function(string,node,delay){
var splitString = string.split(""),
increment = 0;
var le_interval = setInterval(function(){
if (increment < splitString.length) {
var span = document.createElement("span");
span.innerHTML = splitString[increment];
node.appendChild(span);
++increment;
} else {
@z-------------
z------------- / facebook-flatsearch.css
Created March 19, 2014 09:51
A flatter, more modern look to Facebook's search bar
div._585- {
background-color: transparent;
border: none;
box-shadow: none;
}
div._585- * {
color: rgba(255,255,255,.7);
}
@z-------------
z------------- / objectSort.js
Last active August 29, 2015 13:57
Sort an array of objects by property
var objectSort = function(array,sortKey,sortFunction) {
switch (sortFunction) {
case "number-asc":
return array.sort(function(a, b){
return a[sortKey]-b[sortKey];
});
break;
case "number-desc":
return array.sort(function(a, b){
return b[sortKey]-a[sortKey];
@z-------------
z------------- / bob-is-awesome.html
Created March 20, 2014 06:45
Substitute `person` with someone's name and watch the awesomeness
<!DOCTYPE html>
<html>
<head>
<style>
* {
font-family:"Helvetica Neue",Helvetica,sans-serif;
}
html,body {
height:100%;
width:100%;
@z-------------
z------------- / injectJS.js
Last active August 29, 2015 13:57
A simple function that simplifies script injection
var injectJS = function(uri){
var _injectJS_script = document.createElement("script");
_injectJS_script.src = uri;
document.querySelectorAll("head")[0].appendChild(_injectJS_script);
}
// injectJS("//ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js")
var autoClick = function(node,delay){
setInterval(function(){
node.click()
},delay)
}
// autoClick(document.body,1)
// delay is in milliseconds