Add script.user.js
This commit is contained in:
commit
63607abda0
1 changed files with 103 additions and 0 deletions
103
script.user.js
Normal file
103
script.user.js
Normal file
|
@ -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 = '<path d="M1 2.5A2.5 2.5 0 0 1 3.5 0h8.75a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0V1.5h-8a1 1 0 0 0-1 1v6.708A2.5 2.5 0 0 1 3.5 9h3.25a.75.75 0 0 1 0 1.5H3.5a1 1 0 0 0 0 2h5.75a.75.75 0 0 1 0 1.5H3.5A2.5 2.5 0 0 1 1 11.5Zm13.23 7.79zl-1.224-1.224v6.184a.75.75 0 0 1-1.5 0V9.066L10.28 10.29a.75.75 0 0 1-1.06-1.061l2.505-2.504a.75.75 0 0 1 1.06 0L15.29 9.23a.75.75 0 0 1-.018 1.042.75.75 0 0 1-1.042.018"></path>';
|
||||
|
||||
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);
|
||||
})();
|
Loading…
Add table
Reference in a new issue