Skip to content

Instantly share code, notes, and snippets.

@vhf

vhf/script.js Secret

Last active January 25, 2016 16:42
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 vhf/27f3caacc08e76aa0d1f to your computer and use it in GitHub Desktop.
Save vhf/27f3caacc08e76aa0d1f to your computer and use it in GitHub Desktop.
gh-feed-filter
'use strict';
const hideSettings = {
'min-items': 30,
'vhf/free-programming-books': {
star: true,
fork: true,
},
'vhf/v8-bailout-reasons': {
star: true,
fork: false,
},
};
const shouldShow = el => {
const classes = el.classList;
const repo = el.querySelectorAll('.title > a')[1].text;
if (!hideSettings.hasOwnProperty(repo)) {
return true;
}
const hide = hideSettings[repo];
if (hide.star && classes.contains('watch_started')) {
return false;
}
if (hide.fork && classes.contains('fork')) {
return false;
}
return true;
};
const loadNextPage = () => {
const button = document.querySelector('.news > form > button');
if (button) {
button.click();
return true;
}
return false;
};
const feedCleaning = () => {
const lines = document.querySelectorAll('.news > .alert:not(.clean)'); // only clean new els
Array.prototype.forEach.call(lines, l => {
if (!shouldShow(l)) {
l.parentNode.removeChild(l);
}
l.classList.add('clean'); // mark el as clean
});
const remaining = document.querySelectorAll('.news > .alert').length;
return remaining;
};
const observer = new MutationObserver(() => {
if (feedCleaning() < hideSettings['min-items']) {
loadNextPage();
}
});
observer.observe(document.querySelector('.news'), {
childList: true,
});
// Start !
loadNextPage();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment