Last active
January 12, 2023 14:44
-
-
Save mstoecklein/0d5633dd6901ece5b170e909bbb51b65 to your computer and use it in GitHub Desktop.
Creates a glitch in the Matrix in your GitHub profile ;-)
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
// ==UserScript== | |
// @name Calender Graph Hack | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Just for fun | |
// @author Mario Stöcklein (https://github.com/mstoecklein) | |
// @match https://github.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const matrix = document.querySelectorAll('.js-calendar-graph-svg>g>g'); | |
if (!matrix) {return} | |
const cols = Array.from(matrix).slice(0, 52); | |
let lastTS = null | |
function update(timestamp) { | |
if (lastTS + 60 > timestamp) { | |
requestAnimationFrame(update); | |
return; | |
} | |
// move down and fade old position | |
for (let i = 0; i < cols.length; i++) { | |
const rows = cols[i].querySelectorAll('rect'); | |
const changed = []; | |
for (let j = 0; j < rows.length; j++) { | |
if (!changed.includes(j)) { | |
const level = parseInt(rows[j].getAttribute('data-level'), 10); | |
rows[j].setAttribute('data-level', level > 0 ? level - 1 : 0); | |
if (level === 4 && rows.length > j + 1) { | |
rows[j + 1].setAttribute('data-level', level > 0 ? level : 0); | |
if (level > 0) { | |
changed.push(j + 1); | |
} | |
} | |
} | |
} | |
} | |
const started = []; | |
do { | |
const i = Math.round(Math.random() * (cols.length - 1)); | |
if (!started.includes(i)) { | |
cols[i].querySelector('rect').setAttribute('data-level', 4); | |
started.push(i); | |
} | |
} while(started.length === 25) | |
lastTS = timestamp; | |
requestAnimationFrame(update); | |
} | |
update(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment