-
-
Save hikari-no-yume/9d9d652e0e84816e4164 to your computer and use it in GitHub Desktop.
spinning stars and other effects
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
// this is minified with http://lisperator.net/uglifyjs/ before being put inside [html]<script>...</script>[/html] in the News | |
(function () { | |
if (!String.prototype.hasOwnProperty('startsWith')) { // Chrome sucks so we have to polyfill this stuff | |
String.prototype.startsWith = function (str) { | |
return this.substr(0, str.length) === str; | |
}; | |
} | |
if (!String.prototype.hasOwnProperty('endsWith')) { | |
String.prototype.endsWith = function (str) { | |
return this.substr(this.length - str.length) === str; | |
}; | |
} | |
function doStars() { | |
var lastParent = null, speed = 1; | |
Array.prototype.filter.call(document.getElementsByTagName('img'), function (img) { | |
return img.src.endsWith("startechadmin.gif"); | |
}).forEach(function (img) { | |
if (img.parentNode !== lastParent) { | |
speed = 1; | |
lastParent = img.parentNode; | |
} | |
img.style.animation = img.style.webkitAnimation = img.style.mozAnimation = 'spin ' + (speed++) + 's infinite linear'; | |
img.style.transformOrigin = '8px 9px'; | |
}); | |
var style = document.createElement('style'); | |
style.innerHTML = '@keyframes spin { from {transform:rotate(0deg);} to {transform:rotate(360deg);}}'; | |
document.body.appendChild(style); | |
} | |
function wobbly(element) { | |
var numWobbles = 10; | |
var HTML = element.innerHTML; | |
HTML = HTML.replace(/\<script\>[\s\S]*\<\/script\>/gi, ''); | |
var curTag = ''; | |
var outHTML = ''; | |
Array.prototype.forEach.call(HTML, function (c) { | |
if (!curTag) { | |
if (c === '<') { | |
curTag += c; | |
} else { | |
outHTML += '<span class=wobble' + Math.floor(Math.random() * numWobbles) + '>' + c + '</span>'; | |
} | |
} else { | |
curTag += c; | |
if (c === '>') { | |
outHTML += curTag; | |
curTag = ''; | |
} | |
} | |
}); | |
element.innerHTML = outHTML; | |
var styles = document.createElement('style'); | |
document.body.appendChild(styles); | |
window.setInterval(function () { | |
CSS = ''; | |
for (var i = 0; i < numWobbles; i++) { | |
CSS += '.wobble' + i + ' { display: inline-block; transform: translate(' + (Math.random() * 3 - 1.5) + 'px, ' + (Math.random() * 3 - 1.5) + 'px); }'; | |
} | |
styles.innerHTML = CSS; | |
}, 1000/30); | |
} | |
window.addEventListener('DOMContentLoaded', function () { | |
doStars(); | |
Array.prototype.forEach.call(document.getElementsByClassName('gyeh'), function (element) { | |
wobbly(element); | |
}); | |
}, false); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment