// ==UserScript==
// @name GitHammer
// @include /https:\/\/github.com\/[\w_-]+&...)?)?/
// @grant GM.xmlHttpRequest
// @version 0.1
// @author Anonymous
// @run-at document-idle
// @description A ban hammer that blocks affiliates of some GitHub repositories.
// ==/UserScript==
/* WARNING: Existential risk for FOSS community. */
'use strict';
const PERSONAL_TOKEN = ''; // Get it here: https://github.com/settings/token/new
let WHITELIST = [];
const n = window.location.pathname.split('/'), u = n[1] + '/' + n[2];
function z() {
let f = document.createElement('progress');
f.style.width = '100%';
let a = document.createElement('div'),
c = document.createElement('textarea');
c.style.height = c.style.width = '100%';
c.style.background = 'transparent';
c.style.color = 'green';
c.style.fontFamily = 'monotype';
c.readOnly = !0;
a.style.background = 'black';
a.style.top = '10%';
a.style.left = '10%';
a.style.width = '80%';
a.style.height = '90%';
a.style.position = 'fixed';
a.appendChild(f);
a.appendChild(c);
document.body.appendChild(a);
return [c, f]
}
{
let f = document.querySelector('a[data-hotkey=t]'), a = document.createElement('div');
a.className = f.className;
a.textContent = '4TGJ';
a.style.background = 'red';
a.style.color = 'white';
a.style.textDecoration = 'bold';
a.style.fontFamily = 'monotype';
f.parentElement.insertBefore(a, f);
a.addEventListener('click', function(c) {
function A(b, g, d, WHITELIST) {
function h(e) {
k.value = m + '\n' + JSON.stringify(e);
if (e.length) {
if (1 == e.length && !e[0]) return p;
for (let q of e) {
let v = g(q);
WHITELIST.has(v) || p.add(v)
}
k.value = m + '\n' + JSON.stringify([...p.values()]);
++m;
r.max = e.length;
return w(m)
}
return p
}
function w(e) {
return fetch(b + e).then(q => q.json()).then(h)
}
b += '?per_page=100&page=';
let m = 1,
p = d;
return w(m)
}
c.target.style.display = 'none';
let [k, r] = z(), t = `${'https://api.github.com/repos'}/${u}`;
if(!PERSONAL_TOKEN){
k.value = 'Generate a personal OAuth token in https://github.com/settings/token/new and set it in the beginning of the script!';
return;
}
c = `${t}/stargazers`;
let B = b => {
k.value = b
},
x = b => b.login;
c = [
[`${t}/contributors`, x],
[`${t}/forks`, b => b.owner.login],
[c, x]
];
try {
GM.xmlHttpRequest({
url: 'https://api.github.com/user/blocks',
method: 'GET',
headers: {
'Authorization': 'token ' + PERSONAL_TOKEN
},
onload: (b) => {
k.value = 'Already blocked:' + b.responseText;
b = JSON.parse(b.responseText);
WHITELIST = new Set(WHITELIST);
for (var g of b){
WHITELIST.add(g.login);
}
g = new Promise(d => d(new Set));
for (let [d, l] of c){
g = g.then(h => A(d, l, h, WHITELIST));
}
g.then(function(d) {
r.value = 0;
k.value = 'collected: ' + JSON.stringify([...d.values()]);
for (let l of d){
fetch(`${'https://api.github.com/user/blocks'}/${l}`, {
method: 'PUT',
headers: {
Authorization: 'token ' + PERSONAL_TOKEN
},
credentials: 'include'
}).then(h => h.text()).then(h => {
r.value++;
k.value = 'user ' + l + '\n' +
h
}, B);
}
});
}
});
} catch (b) {
k.value = b
}
}, !0)
};