Skip to content

Instantly share code, notes, and snippets.

@pwntester
Last active September 30, 2021 21:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pwntester/53ad7db537aac935d8317032780e0d39 to your computer and use it in GitHub Desktop.
Save pwntester/53ad7db537aac935d8317032780e0d39 to your computer and use it in GitHub Desktop.
Browser UserScript to show Project Star count for each LGTM result
// ==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
});
})();
@pwntester
Copy link
Author

imagen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment