feat: violenmonkey script

This commit is contained in:
Patrick 2024-12-30 13:55:15 +01:00
parent 99cbcc03d9
commit 1ee19dd0bf
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F

46
scripts/github.js Normal file
View file

@ -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();
})();