// ... / NixOS / nixpkgs / pull / / ... const number = new URL(window.location.href).pathname.split('/')[4] // There are (at the time of writing) two contexts in which the PR // number is visible: // // 1. in the header (following the PR title) // 2. sufficiently far down that the header is no longer visible (at // which point the header shrinks and affixes itself to the top of the // page) // // These are actually two distinct elements, the visibility of which // are dependent on your scroll position. They also have completely // different (and nondescript) CSS selectors, so instead of looking for // them directly, we locate the immediately preceding PR title elements // (which do have a common CSS selector), and grab their next sibling. for (let node of document.querySelectorAll('.js-issue-title')) { node = node.nextElementSibling const a = document.createElement('a') a.setAttribute('href', `https://nixpk.gs/pr-tracker.html?pr=${number}`) node.replaceWith(a) a.appendChild(node) }