Last active
September 30, 2021 21:19
-
-
Save pwntester/53ad7db537aac935d8317032780e0d39 to your computer and use it in GitHub Desktop.
Browser UserScript to show Project Star count for each LGTM result
This file contains hidden or 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 LGTM stars | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Show star counts | |
// @author Alvaro Muñoz (@pwntester) | |
// @match https://lgtm.com/query/* | |
// @grant none | |
// @run-at document-idle | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const callback = function(mutationsList, observer) { | |
for(const mutation of mutationsList) { | |
if (mutation.type === 'childList') { | |
const addedNode = mutation.addedNodes[0] | |
if (addedNode != undefined && addedNode.classList != undefined) { | |
if (addedNode.classList.contains('c-query-run-display')) { | |
const projectNode = addedNode.getElementsByClassName("project-name")[0] | |
if (projectNode != undefined) { | |
const name = projectNode.textContent; | |
fetch('https://api.github.com/repos/'+name) | |
.then(response => response.json()) | |
.then(data => { | |
// show watchers count | |
projectNode.textContent=name + " ✨"+data.watchers_count+"✨"; | |
// collapse element | |
const header = addedNode.getElementsByClassName("header")[0] | |
console.log(name, data.watchers_count, header); | |
header.dispatchEvent(new MouseEvent("click", {"view": window, "bubbles": true, "cancelable": false})); | |
}) | |
} | |
} | |
} | |
} | |
} | |
}; | |
var observer = new MutationObserver(callback); | |
observer.observe(document, { | |
childList: true, | |
subtree: true | |
}); | |
})(); |
Author
pwntester
commented
Feb 22, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment