// ==UserScript== // @name GitHub Mentioned Links // @version 0.1.3 // @description A userscript adds all mentioned links in the side bar // @license MIT // @author Rob Garrison // @namespace https://github.com/Mottie // @match https://github.com/* // @run-at document-idle // @grant GM_getValue // @grant GM_setValue // @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=1108163 // @require https://greasyfork.org/scripts/398877-utils-js/code/utilsjs.js?version=1079637 // @icon https://github.githubassets.com/pinned-octocat.svg // @updateURL https://raw.githubusercontent.com/Mottie/GitHub-userscripts/master/github-mentioned-links.user.js // @downloadURL https://raw.githubusercontent.com/Mottie/GitHub-userscripts/master/github-mentioned-links.user.js // @supportURL https://github.com/Mottie/GitHub-userscripts/issues // ==/UserScript== /* global $ $$ on */ (() => { "use strict"; // GitHub loves to change class names const selectors = { // Insert entry after milestone in the sidebar sidebar: ".discussion-sidebar-item.sidebar-progress-bar", // Load more comments button (2 buttons; either works) loadMore: "form[action*='more_items'] button", // Issue/PR timeline element with anchor id timelineGroup: ".timeline-comment-group", // All links within a timeline comment links: ".comment-body a:not(.user-mention)" }; const internalLinkIcon = ` ` // Sidebar item const item = document.createElement("details"); item.id = "ghml-wrapper"; item.className = "discussion-sidebar-item sidebar-mentioned-links"; item.open = GM_getValue("mentionedOpened", false); item.onclick = event => { // Set as opposite makes it work?! DOM update delay, maybe? GM_setValue("mentionedOpened", !event.target.parentElement.open); }; // Load more button const loadMoreButton = document.createElement("button"); loadMoreButton.className = "btn btn-block btn-sm width-auto ml-2 py-0 px-1 text-normal"; loadMoreButton.style.fontSize = "10px"; loadMoreButton.title = "Each click loads up to 60 items"; function getLinks() { const list = new Set(); const links = []; $$(selectors.timelineGroup).forEach(body => { $$(selectors.links, body).forEach(link => { if (!list.has(link.href) && !$("img", link)) { list.add(link.href); links.push( `