Skip to content

Instantly share code, notes, and snippets.

@guillemcanal
Last active May 6, 2021 13:31
Show Gist options
  • Save guillemcanal/a33192a193ccc387cb1cbc36fad90f5a to your computer and use it in GitHub Desktop.
Save guillemcanal/a33192a193ccc387cb1cbc36fad90f5a to your computer and use it in GitHub Desktop.
Github Notifications Page Cleanup
/**
* Clean the Github's Notification Page
*
* @see https://github.com/notifications
*
* @param {String} type Either "all", "merged", "closed", "draft" or "closed-issues"
*/
const clearGithubNotifications = type => {
// @TODO Handle notifications list refresh (when the user have multiple pages of notifications)
const PULL_REQUEST_MERGED = ".octicon-git-merge";
const PULL_REQUEST_DRAFT = ".octicon-git-pull-request.color-text-tertiary";
const PUll_REQUEST_CLOSED = ".octicon-git-pull-request.color-text-danger";
const ISSUE_CLOSED = ".octicon-issue-closed";
const CLEAR_SELECTED = '[title="Done"][type="submit"]';
const check = element => !element.checked && element.click();
const selectRow = element => check(element.closest('li').querySelector('input'));
const selectAll = selector => [...document.querySelectorAll(selector)].forEach(selectRow);
const clearSelected = () => document.querySelector(CLEAR_SELECTED).click();
switch(true) {
case ["merged", "all"].includes(type):
selectAll(PULL_REQUEST_MERGED);
case ["closed", "all"].includes(type):
selectAll(PUll_REQUEST_CLOSED);
case ["draft", "all"].includes(type):
selectAll(PULL_REQUEST_DRAFT);
case ["closed-issues", "all"].includes(type):
selectAll(ISSUE_CLOSED);
}
clearSelected();
}
// Call the function with either "all", "merged", "closed", "draft" or "closed-issues"
clearGithubNotifications("all");
// Copy/Paste the code above in https://caiorss.github.io/bookmarklet-maker/ and generate a bookmarklet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment