Skip to content

Instantly share code, notes, and snippets.

@kumpelblase2
Last active April 4, 2020 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumpelblase2/5a51155875292a0a2605c34c154cbc6a to your computer and use it in GitHub Desktop.
Save kumpelblase2/5a51155875292a0a2605c34c154cbc6a to your computer and use it in GitHub Desktop.
Automatically expand github news entries
// ==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