Last active
November 19, 2015 22:07
-
-
Save EliseWei/f70e818f30ff46dca4d9 to your computer and use it in GitHub Desktop.
Script snippets used for Dev Day talk on 4/23/15 (updated 11/19/15)
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
// Placekittens http://www.houzz.com/photos/products | |
// Example 1 | |
var target = document.getElementsByClassName('shop-landing-top-promotions')[0]; | |
target.innerHTML = '<img src="http://placekitten.com/g/800/120" alt="" />'; | |
// Example 2 | |
var target = document.getElementsByClassName('shop-landing-top-promotions')[0]; | |
var targetInner = target.getElementsByClassName('shop-landing-top-promotions-content')[0]; | |
targetInner.style.visibility='hidden'; | |
target.style.background = 'url("http://placekitten.com/g/800/120") 0 0 repeat'; | |
// Example 3 | |
var target = document.getElementsByClassName('topic-groups')[0]; | |
var links = target.getElementsByClassName('topic-thumb'); | |
for (var i = 0, l = links.length; i < l; i++) { | |
var link = links[i]; | |
var img = link.getElementsByTagName('img')[0]; | |
img.src = 'http://placekitten.com/g/800/120'; | |
} | |
// Mind the Gap Any site. Tested on http://www.amazon.com/gp/goldbox/ref=nav_cs_gb | |
var deadline = new Date('January 1, 2016 00:00 UTC'); | |
var serverTime; | |
var getServerTime = function() { | |
var dateFetched = false; | |
// Create XMLHttpRequest object | |
var xmlhttp; | |
if (window.XMLHttpRequest) { | |
// code for IE7+, Firefox, Chrome, Opera, Safari | |
xmlhttp = new XMLHttpRequest(); | |
} else { | |
// code for IE6, IE5 | |
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); | |
} | |
// Add onreadystatechange function for partial or complete response, | |
// either of which should be timestamped. | |
xmlhttp.onreadystatechange = function() { | |
console.log('countdown.getServerTime readyState:', xmlhttp.readyState); | |
if (!dateFetched && xmlhttp.readyState == 4) { | |
dateFetched = true; | |
var dateStr = xmlhttp.getResponseHeader('date'); | |
serverTime = new Date(dateStr); | |
var userTime = new Date(); | |
console.log('serverTime:', serverTime); | |
console.log('userTime:', userTime); | |
console.log('deadline:', deadline); | |
} | |
}; | |
// Make the call. | |
var nonce = '?nonce=' + Math.random().toString(); | |
xmlhttp.open('GET', document.location.href + nonce, true); | |
xmlhttp.setRequestHeader('Expires', '-1'); | |
xmlhttp.setRequestHeader('Cache-Control', 'no-cache'); | |
xmlhttp.send(); | |
}; | |
getServerTime(); | |
// Domino https://www.jcrew.com/de/girls_category/shirts.jsp | |
var newFunc = function() { | |
alert('Quickshop!'); | |
}; | |
var origMethod = window.QuickShop.prototype.renderQuickShopTemplate; | |
window.QuickShop.prototype.renderQuickShopTemplate = function() { | |
newFunc.apply(this, arguments); | |
return origMethod.apply(this, arguments); | |
}; | |
// Looking Glass https://www.jcrew.com/de/girls_category/shirts.jsp | |
var iframe = document.createElement('iframe'); | |
iframe.onload = function(){console.log('iframe loaded');}; | |
iframe.style.display = 'none'; | |
iframe.name = 'formTarget' | |
document.body.appendChild(iframe); | |
var form = document.createElement('form'); | |
form.setAttribute('method', 'POST'); | |
form.setAttribute('action', 'https://factory.jcrew.com'); | |
form.setAttribute('target', 'formTarget'); | |
document.body.appendChild(form); | |
form.submit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment