Skip to content

Instantly share code, notes, and snippets.

@ignasi35
Forked from marcospereira/github-notifications.js
Last active April 3, 2019 13:23
Show Gist options
  • Save ignasi35/e8ab05c072e8f0c6b432b8d4fbf8b7a7 to your computer and use it in GitHub Desktop.
Save ignasi35/e8ab05c072e8f0c6b432b8d4fbf8b7a7 to your computer and use it in GitHub Desktop.
GitHub Notifications By Organizations
// ==UserScript==
// @name GitHub Notifications By Organizations
// @namespace https://github.com
// @version 1.0
// @description Group the notifications list by organizations
// @author marcospereira
// @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 repositoriesParent = document.querySelector(".filter-list.small");
const repositories = repositoriesParent.querySelectorAll("li");
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