Created
January 17, 2020 23:56
-
-
Save josefandersson/5afb04cff0a82c867ce467affff83878 to your computer and use it in GitHub Desktop.
GitHub Draw on Commits Calendar Graph in Profile (userscript)
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 Commits Editor | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://github.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const empty = '#ebedf0' | |
const colors = ['#c6e48b', '#7bc96f', '#239a3b', '#196127'] | |
let rects = document.querySelectorAll('rect') | |
let current | |
let onMouseEnter = ev => { | |
current = ev.target | |
if (fill) { | |
current.setAttribute('fill', colors[Math.floor(Math.random() * 4)]) | |
count() | |
} | |
if (clear) { | |
current.setAttribute('fill', empty) | |
count() | |
} | |
} | |
let clear = false | |
let fill = false | |
let onKeyDown = ev => { | |
if (ev.code === 'ShiftLeft') { | |
clear = true | |
if (current != null) { | |
current.setAttribute('fill', empty) | |
count() | |
} | |
} | |
if (ev.code === 'ControlLeft') { | |
fill = true | |
if (current != null) { | |
current.setAttribute('fill', colors[Math.floor(Math.random() * 4)]) | |
count() | |
} | |
} | |
} | |
let onKeyUp = ev => { | |
if (ev.code === 'ShiftLeft') { | |
clear = false | |
} | |
if (ev.code === 'ControlLeft') { | |
fill = false | |
} | |
} | |
rects.forEach(r => r.addEventListener('mouseenter', onMouseEnter)) | |
document.addEventListener('keydown', onKeyDown) | |
document.addEventListener('keyup', onKeyUp) | |
const colorContr = { '#ebedf0': 0, '#c6e48b': 1, '#7bc96f': 2, '#239a3b': 3, '#196127': 5 } | |
let countTextElem = document.querySelector('div.js-yearly-contributions > div > h2') | |
let count = () => { | |
let c = 0 | |
rects.forEach(r => { | |
let color = r.getAttribute('fill') | |
if (color !== empty) { | |
c += colorContr[color] | |
} | |
}) | |
countTextElem.innerText = `${c} contributions in the last year` | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment