Created
April 17, 2019 14:54
-
-
Save ignasi35/258bad318022d20bfbef9ca0bf25733f to your computer and use it in GitHub Desktop.
WIP - tampermokey to mark all closed as read on GH Notifications
This file contains hidden or 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 Notifications - Mark all closed | |
// @namespace https://github.com | |
// @version 1.0 | |
// @description Mark closed issues, closed PRs and merged PRs as read | |
// @author ignasi35 | |
// @match https://github.com/notifications | |
// @include https://github.com/*/notifications | |
// @include https://github.com/notifications/* | |
// @license MIT | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const buttonHolder = document.querySelector(".btn.btn-sm.rgh-open-notifications-button.BtnGroup-item").parentElement | |
var newB = document.createElement("button") | |
newB.textContent = "Mark Closed as Read" | |
newB.setAttribute("class", "btn btn-sm rgh-mark-as-read-button BtnGroup-item") | |
document.querySelector(".btn.btn-sm.rgh-open-notifications-button.BtnGroup-item").parentElement.appendChild(newB) | |
const notifications = document.querySelector(".boxed-group-inner.list-group.notifications").querySelectorAll("li"); | |
const closedNotifications = notifications | |
const groupedByOrg = {}; | |
repositories.forEach(element => { | |
const ownerAndRepo = element.querySelector(".repo-and-owner"); | |
const owner = ownerAndRepo.textContent.split("/")[0]; | |
const repo = ownerAndRepo.textContent.split("/")[1]; | |
// short the text content to have only the repository name | |
// since it will be under the org list. | |
ownerAndRepo.textContent = repo; | |
// Is this really how you check if a dictionary has a key | |
// in JavaScript? | |
if (Object.keys(groupedByOrg).some(k => k == owner)) { | |
groupedByOrg[owner].push(element); | |
} else { | |
groupedByOrg[owner] = [element]; | |
} | |
}); | |
repositoriesParent.innerHTML = ""; | |
Object.keys(groupedByOrg).forEach(orgName => { | |
const orgLi = document.createElement("li"); | |
const orgHeader = document.createElement("h5"); | |
orgHeader.textContent = orgName; | |
orgLi.appendChild(orgHeader); | |
const reposUl = document.createElement("ul"); | |
reposUl.setAttribute("class", "filter-list small"); | |
groupedByOrg[orgName].forEach(e => reposUl.appendChild(e)); | |
orgLi.appendChild(reposUl); | |
repositoriesParent.appendChild(orgLi); | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment