Skip to content

Instantly share code, notes, and snippets.

@froxxxy
Last active August 27, 2020 05:40
Show Gist options
  • Save froxxxy/603bf81bca7a7f18169f816491d9821b to your computer and use it in GitHub Desktop.
Save froxxxy/603bf81bca7a7f18169f816491d9821b to your computer and use it in GitHub Desktop.
Tampermonkey userscript to get the party started with some parrots on any website! ;)
// ==UserScript==
// @name party parrot - PARTY OR DIE
// @namespace https://github.com/jmhobbs/cultofthepartyparrot.com
// @version 0.1
// @description There's no parrot like party parrot!
// @author You
// @match http://*/*
// @match https://*/*
// @grant GM_addStyle
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @updateURL https://gist.github.com/cuidas/603bf81bca7a7f18169f816491d9821b
// ==/UserScript==
(function () {
// Starting the party, and there is no party without parrots!!
var parrots = [];
$.getJSON('https://api.github.com/repos/jmhobbs/cultofthepartyparrot.com/contents/parrots/hd', function (data) {
for (var item of data) {
if (item.type != 'file') {
continue;
}
parrots.push(item.download_url);
}
});
// Konami Code
// From https://css-tricks.com/snippets/jquery/konomi-code/
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function (e) {
kkeys.push(e.keyCode);
if (kkeys.toString().indexOf(konami) >= 0) {
$(document).unbind('keydown', arguments.callee);
animateBG();
createParrot();
setInterval(createParrot, 1000);
}
});
// Random X-Value in viewport with a 50px margin
function newX() {
return Math.floor(Math.random() * ($(window).width() - 50));
}
// Random Y-Value in viewport with a 50px margin
function newY() {
return Math.floor(Math.random() * ($(window).height() - 50));
}
// Appends a new parrot to the body and animates it
// parrot chosen by random
function createParrot() {
$("body").append(
'<img class="parrot" src="' + parrots[Math.floor(Math.random() * parrots.length)] + '" style="position: fixed; top: ' + newY() + '; left: ' + newX() + '; z-index: 9001">'
);
animateIMG();
}
// Animation of the parrot (position and size)
function animateIMG() {
$('.parrot').animate({
top: newY(),
left: newX(),
width: '+=' + (Math.floor(Math.random() * 10) - 5) + '%'
}, 800, 'swing', function () {
animateIMG();
});
}
function animateBG() {
GM_addStyle(`
@keyframes parrot {
0% {background-color:#FECE7A;}
12% {background-color:#7EFF7A;}
24% {background-color:#7EFFFF;}
36% {background-color:#7BA3FE;}
48% {background-color:#CB70FE;}
60% {background-color:#FC49F5;}
78% {background-color:#FC4EA7;}
90% {background-color:#FD5258;}
100% {background-color:#FECE7A;}
}
:not(.parrot) {
animation-name: parrot;
animation-duration:1s;
animation-direction:alternate;
animation-iteration-count:infinite;
}
`);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment