Instantly share code, notes, and snippets.

@hikari-no-yume /gg2.js Secret
Last active Dec 21, 2015

Embed
What would you like to do?
spinning stars and other effects
// 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