From 1ee19dd0bf23ee4a59071b528eeca84fb23d6ed7 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 30 Dec 2024 13:55:15 +0100 Subject: [PATCH] feat: violenmonkey script --- scripts/github.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/github.js diff --git a/scripts/github.js b/scripts/github.js new file mode 100644 index 0000000..6fe4e88 --- /dev/null +++ b/scripts/github.js @@ -0,0 +1,46 @@ +// ==UserScript== +// @name Nixpkgs subscribe +// @namespace http://tampermonkey.net/ +// @version 2024-07-25 +// @description try to take over the world! +// @author You +// @match https://github.com/* +// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com +// ==/UserScript== + + +function addButton() { + const buttonContainerElement = document.querySelector('.gh-header-actions'); + const div = document.createElement('div'); + div.classList = 'flex-md-order-2 pr_tracker'; + const pr= window.location.pathname.split('/')[4]; + + const btn = document.createElement('button'); + btn.classList = 'Button--secondary Button--small Button'; + btn.type = 'button'; + btn.innerText = `Subscribe`; + btn.addEventListener('click', function() { + navigator.clipboard.writeText("nim add-pr " + pr); + }); + + + div.appendChild(btn); + buttonContainerElement.firstElementChild.before(div); +} + +function maybeAddButton(){ + const loc = window.location.pathname; + if (loc.match("^/NixOS/nixpkgs/pull/[0-9]*") && (document.getElementsByClassName("pr_tracker").length == 0 )){ + addButton(); + } + setTimeout(maybeAddButton, 250); + +} + +(function() { + 'use strict'; + + // Your code here... + maybeAddButton(); +})(); +