Last active
June 7, 2019 17:24
-
-
Save PentaHelix/f0b8198c23ae12d314d7d6e1cf65beca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name New Userscript | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://github.com/*/*/stargazers* | |
// @grant window.close | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @grant GM_deleteValue | |
// @grant GM_addValueChangeListener | |
// @grant GM_openInTab | |
// @grant GM_registerMenuCommand | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
debugger | |
let isController = !GM_getValue('has-controller', false) | |
if (isController) { | |
GM_registerMenuCommand('Scrape starrers', run) | |
} else { | |
run() | |
} | |
})(); | |
function run () { | |
let isController = !GM_getValue('has-controller', false) | |
let users = GM_getValue('collected-users') || '[]' | |
users = JSON.parse(users) | |
if (isController) { | |
GM_setValue('has-controller', true) | |
GM_setValue('collected-users', users) | |
GM_setValue('done-collecting', false) | |
GM_addValueChangeListener('done-collecting', (a, b, c, remote) => { | |
if (!remote) return | |
console.log(new Set(JSON.parse(GM_getValue('collected-users')))) | |
GM_deleteValue('has-controller') | |
GM_deleteValue('collected-users') | |
GM_deleteValue('done-collecting') | |
}) | |
} | |
let els = document.querySelectorAll('a[data-hovercard-type="user"]') | |
for (let el of els) { | |
let name = el.innerHTML | |
users.push(name) | |
} | |
GM_setValue('collected-users', JSON.stringify(users)) | |
let next = document.querySelector('.paginate-container > * > a:nth-child(2)') | |
if (next) { | |
let url = next.getAttribute('href') | |
setTimeout(() => { | |
GM_openInTab(url, { | |
active: false, | |
setParent: true | |
}) | |
if (!isController) window.close() | |
}, 1200) | |
} else { | |
GM_setValue('done-collecting', true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment