summary refs log tree commit diff
diff options
context:
space:
mode:
authorV <v@anomalous.eu>2022-05-17 15:46:46 +0200
committerV <v@anomalous.eu>2022-05-17 18:20:32 +0200
commitf2afbcee6c2d495ada2b140e1882e9482a3d640b (patch)
tree418b4f226196904fda250f2b9ad6ff93f9c40118
downloadrefined-nixpkgs-0.1.tar.zst
Root commit v0.1
Here we go again! The initial release of a new extension.
-rw-r--r--content.js23
-rw-r--r--manifest.json17
2 files changed, 40 insertions, 0 deletions
diff --git a/content.js b/content.js
new file mode 100644
index 0000000..153f5a5
--- /dev/null
+++ b/content.js
@@ -0,0 +1,23 @@
+// ... / NixOS / nixpkgs / pull / <number> / ...
+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)
+}
diff --git a/manifest.json b/manifest.json
new file mode 100644
index 0000000..1fd731c
--- /dev/null
+++ b/manifest.json
@@ -0,0 +1,17 @@
+{
+	"manifest_version": 2,
+
+	"name": "Refined Nixpkgs",
+	"version": "0.1",
+
+	"description": "Improve the experience for Nixpkgs maintainers",
+	"homepage_url": "https://anomalous.eu/projects/refined-nixpkgs",
+
+	"content_scripts": [
+		{
+			"matches": [ "https://github.com/NixOS/nixpkgs/pull/*" ],
+			"js": [ "content.js" ],
+			"run_at": "document_end"
+		}
+	]
+}