Last active
June 4, 2019 11:45
-
-
Save PentaHelix/9e5679bd723c1289a63bcb36104a76a0 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/search* | |
// @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 go repos', run) | |
} else { | |
run() | |
} | |
})(); | |
function run () { | |
let isController = !GM_getValue('has-controller', false) | |
let repos = GM_getValue('collected-repos') || '[]' | |
repos = JSON.parse(repos) | |
if (isController) { | |
GM_setValue('has-controller', true) | |
GM_setValue('collected-repos', repos) | |
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-repos')))) | |
GM_deleteValue('has-controller') | |
GM_deleteValue('collected-repos') | |
GM_deleteValue('done-collecting') | |
}) | |
} | |
let els = document.querySelectorAll('a.text-bold') | |
for (let el of els) { | |
let name = el.innerHTML | |
repos.push(name) | |
} | |
GM_setValue('collected-repos', JSON.stringify(repos)) | |
let next = document.querySelector('a[rel="next"]') | |
if (next) { | |
let url = "https://github.com" + next.getAttribute('href') | |
GM_openInTab(url, { | |
active: false, | |
setParent: true | |
}) | |
} else { | |
GM_setValue('done-collecting', true) | |
} | |
if (!isController) window.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment