Last active
May 23, 2019 11:04
-
-
Save pomber/e73e92d34b4230040da11e8521871c07 to your computer and use it in GitHub Desktop.
Decimate issues button for GitHub
This file contains hidden or 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
const buttonHtml = ` | |
<a id="thanos" class="btn btn-primary float-right" role="button" | |
style="margin-left:38px"> | |
Decimate issues | |
</a>`; | |
var css = '#thanos:hover{ background-image: linear-gradient(-180deg,#6d3678,#693270 90%) }'; | |
var style = document.createElement('style'); | |
if (style.styleSheet) { | |
style.styleSheet.cssText = css; | |
} else { | |
style.appendChild(document.createTextNode(css)); | |
} | |
document.getElementsByTagName('head')[0].appendChild(style); | |
document | |
.querySelector(".subnav .pr-2") | |
.insertAdjacentHTML("beforeend", buttonHtml); | |
const $button = document.getElementById("thanos"); | |
const $tabCount = document.querySelector( | |
"#js-repo-pjax-container > div.pagehead.repohead.instapaper_ignore.readability-menu.experiment-repo-nav > nav > span:nth-child(2) > a > span.Counter" | |
); | |
const $openCount = document.querySelector( | |
"#js-issues-toolbar > div > div > div.flex-auto > div > a.btn-link.selected" | |
); | |
const $closedCount = document.querySelector( | |
"#js-issues-toolbar > div > div > div.flex-auto > div > a:nth-child(2)" | |
); | |
document.body.style.transition = | |
"filter 0.4s cubic-bezier(0.55, 0.055, 0.675, 0.19)"; | |
const state = { | |
openCount: parseFloat($openCount.childNodes[2].nodeValue.replace(/,/g, '')), | |
closedCount: parseFloat($closedCount.childNodes[2].nodeValue.replace(/,/g, '')), | |
brightness: 100, | |
start: null | |
}; | |
const duration = 12000; | |
$button.onclick = () => { | |
state.brightness = 1000; | |
state.start = performance.now(); | |
render(); | |
state.brightness = 100; | |
setTimeout(() => requestAnimationFrame(loop), 500); | |
}; | |
function loop() { | |
render(); | |
requestAnimationFrame(loop); | |
} | |
function render() { | |
const t = | |
state.start && | |
Math.min(duration, performance.now() - state.start) / duration; | |
const killed = Math.round((easeInOut(t) * state.openCount) / 2); | |
const open = state.openCount - killed; | |
const close = state.closedCount + killed; | |
$tabCount.innerText = open.toLocaleString(); | |
$openCount.childNodes[2].nodeValue = ` ${open.toLocaleString()} Open`; | |
$closedCount.childNodes[2].nodeValue = ` ${close.toLocaleString()} Closed`; | |
document.body.style.filter = `brightness(${state.brightness}%)`; | |
} | |
render(); | |
function easeInOut(t) { | |
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment