Last active
April 4, 2020 11:27
-
-
Save kumpelblase2/5a51155875292a0a2605c34c154cbc6a to your computer and use it in GitHub Desktop.
Automatically expand github news entries
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 Github Autoexpand News Items | |
// @namespace https://kumpelblase2.github.io/ | |
// @version 0.1 | |
// @description Automatically expands news entries in your Github Feed. | |
// @author kumpelblase2 | |
// @match https://github.com/ | |
// @grant none | |
// ==/UserScript== | |
function findButtons() { | |
return [...document.querySelectorAll('button.js-details-target[aria-expanded="false"]')]; | |
} | |
function toggleButtons() { | |
const found = findButtons(); | |
found.forEach(button => button.click()); | |
} | |
function applyObserverTo(container) { | |
const observerConfig = { childList: true, subtree: true }; | |
const onChange = function(changeList, observer) { | |
setTimeout(toggleButtons, 1); | |
}; | |
const observer = new MutationObserver(onChange); | |
observer.observe(container, observerConfig); | |
} | |
(function() { | |
'use strict'; | |
const timer = setInterval(() => { | |
const newsContainer = document.querySelector('.news'); | |
if(newsContainer.children.length === 5 && newsContainer.children[3].className.length === 0) { | |
toggleButtons(); | |
applyObserverTo(newsContainer.children[3]); | |
clearInterval(timer); | |
} | |
}, 500); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment