Last active
August 29, 2015 14:19
-
-
Save rlemon/ea1fa4411f82652f6625 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function jsonp(url) { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = url; | |
document.head.appendChild(script); | |
} | |
function ff(fonts) { | |
var style = document.createElement('style'); | |
var str = '@import url(' + location.protocol + '//fonts.googleapis.com/css?family=' + fonts.items.map(function (item) { | |
return item.family.replace(/ /g, '+') | |
}).join('|') + ');'; | |
style.textContent = str; | |
document.head.appendChild(style); | |
toggleFonts(fonts); | |
} | |
function toggleFonts(fonts) { | |
var font = fonts.items[Math.floor(Math.random() * fonts.items.length)].family; | |
document.body.style.fontFamily = font; | |
console.log('changing fonts to', font); | |
setTimeout(toggleFonts.bind(null, fonts), Math.random()*30000+10000); | |
} | |
jsonp("https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyDBzzPRqWl2eU_pBMDr_8mo1TbJgDkgst4&sort=trending&callback=ff"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment