commit 63607abda06c4244728bc84d8c3c4ba5e8bf7c59 Author: ashley Date: Thu Oct 17 22:06:15 2024 +0000 Add script.user.js diff --git a/script.user.js b/script.user.js new file mode 100644 index 0000000..9728c85 --- /dev/null +++ b/script.user.js @@ -0,0 +1,103 @@ +// ==UserScript== +// @name incest mirror :) +// @description kiss your sister + +// @include https://www.github.com/* +// @include http://www.github.com/* +// @include https://github.com/* +// @include http://github.com/* + +// @grant GM.setValue +// @grant GM.getValue +// @grant GM.xmlHttpRequest +// ==/UserScript== + +var mirrorIcon = ''; + +if(!GM) { + alert("This script requires GreaseMonkey!"); + return; +} + +async function api(url, data) { + var token = await GM.getValue("token"); + + if(!token) { + var input = prompt("Enter your git.incest.world access token\nSee: https://git.incest.world/user/settings/applications"); + GM.setValue("token", input); + } + + return new Promise((resolve, reject) => { + GM.xmlHttpRequest({ + method: "POST", + url: `https://git.incest.world/api/v1/${url}`, + data: JSON.stringify(data), + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "Authorization": `token ${token}`, + }, + onload: (response) => { + resolve(response); + } + }); + }); +} + +(async () => { + function main() { + var container = document.querySelector(".pagehead-actions"); + if(!container) + return; + + var mirrorButton = container.querySelector("#mirror"); + if(mirrorButton != null) + return; + + mirrorButton = container.children[container.children.length - 1].cloneNode(true); + mirrorButton.id = "mirror"; + + var starCount = mirrorButton.querySelector("#repo-stars-counter-star"); + if(starCount) + starCount.parentNode.removeChild(starCount); + + var dropDown = mirrorButton.querySelector("details"); + dropDown.parentNode.removeChild(dropDown); + + var btn = mirrorButton.querySelector(".unstarred button"); + + var newButton = document.createElement("button"); + newButton.className = btn.className; + newButton.innerHTML = btn.innerHTML; + newButton.querySelector("svg").innerHTML = mirrorIcon; + newButton.querySelector("span").innerText = "Mirror"; + newButton.onclick = async () => { + newButton.disabled = true; + + var data = await api("repos/migrate", { + "clone_addr": location.href, + "repo_name": location.pathname.split("/")[2], + "mirror": true, + "repo_owner": "mirrors", + "description": "Mirror of " + location.href, + "private": false, + "issues": false, + "pull_requests": false + }); + + var resp = JSON.parse(data.response); + if(resp.message) + alert(resp.message); + else + window.open(resp.html_url); + + newButton.disabled = false; + }; + + mirrorButton.innerHTML = ""; + mirrorButton.appendChild(newButton); + container.prepend(mirrorButton); + } + + setInterval(main, 1); +})(); \ No newline at end of file