Skip to content

Instantly share code, notes, and snippets.

@freayd
Created April 5, 2017 17:53
Show Gist options
  • Save freayd/0acfe98e02cbc334fbb3dbb2098a1791 to your computer and use it in GitHub Desktop.
Save freayd/0acfe98e02cbc334fbb3dbb2098a1791 to your computer and use it in GitHub Desktop.
Rough Java packages usage on Github
// Run this script in a Javascript console while browsing Github.
// Do not abuse, thanks!
var pkgs = ["java.applet","java.awt","java.beans","java.io","java.lang","java.math","java.net","java.nio","java.rmi","java.security","java.sql","java.text","java.time","java.util","javax.accessibility","javax.activation","javax.activity","javax.annotation","javax.crypto","javax.imageio","javax.jws","javax.lang","javax.management","javax.naming","javax.net","javax.print","javax.rmi","javax.script","javax.security","javax.sound","javax.sql","javax.swing","javax.tools","javax.transaction","javax.xml","org.ietf","org.omg","org.w3c","org.xml"];
var counts = {};
function requestByPackageIndex(i) {
var pkg = pkgs[i];
var xhr = new XMLHttpRequest();
xhr.open("GET", "/search?q=import+" + pkg + "&type=Code&utf8=%E2%9C%93&_pjax=%23js-pjax-container", true);
xhr.onload = function () {
var doc = new DOMParser().parseFromString(xhr.responseText, "text/html");
var result = doc.evaluate("//*[contains(text(),'code results')]/text()", doc, null, XPathResult.STRING_TYPE, null);
counts[pkg] = result.stringValue.trim();
console.log(i + "\t" + pkg + "\t" + counts[pkg]);
var delay = (i > 0 && i % 5 == 0) ? 5000 : 400;
setTimeout(function () {
if (i < pkgs.length - 1) requestByPackageIndex(i + 1);
}, delay);
};
xhr.send();
}
requestByPackageIndex(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment