-
-
Save vhf/27f3caacc08e76aa0d1f to your computer and use it in GitHub Desktop.
gh-feed-filter
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
'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