Skip to content

Instantly share code, notes, and snippets.

@joelalejandro
Last active October 11, 2017 17:53
Show Gist options
  • Select an option

  • Save joelalejandro/a096adf0090360240e36c94bcea5caba to your computer and use it in GitHub Desktop.

Select an option

Save joelalejandro/a096adf0090360240e36c94bcea5caba to your computer and use it in GitHub Desktop.
An easy way to retrieve common definitions from a GitHub search result.
// 1. Do a GitHub search.
// 2. Determine what data to extract.
// 3. Adapt the `lineDetect` and `lineParse` functions.
// 4. ??
// 5. Profit! Run this script on the console.
console.log(
// Begin: Don't change this ----------------------------------------------------------------------------------
((functions) => [...new Set([].slice.call(
// Select all code results from thi spage.
document.querySelectorAll('.blob-code-inner')
).filter(functions.lineDetect) // Work with the lines we want
.map(
line =>
// Get the repo name.
line.parentNode.parentNode.parentNode.parentNode.parentNode.querySelector('.d-inline-block > a').innerText
+ '\t'
// Get whatever data we want from the line.
+ functions.lineParse(line)
))].join('\r\n'))({
// End: Don't change this ----------------------------------------------------------------------------------
lineDetect: (line) => line.innerText.indexOf('#ENV') === -1
&& line.innerText.indexOf('# ENV') === -1
&& line.innerText.indexOf('NODE_VERSION') > -1,
lineParse: (line) => line.innerText.split('=')[1]
})
);
// Sample output: Get jQuery versions from different repos:
// URL: https://github.com/search?utf8=%E2%9C%93&q=package.json+jquery+dependencies+language%3Ajson&type=Code
// lineDetect: (line) => line.innerText.indexOf('"jquery"') > -1,
// lineParse: (line) => line.innerText.replace(/"/g, '')
```
stephanvan/svg-practice ~2.1.0
Generick/amorick >=1.8.3
linhlv/thing-panel >=1.8.3
wei2lee/infradesign-blueoctopus-microsite >=1.4.3
roaldjap/roaldjap.github.io >=1.8.3
LilShy/test >=1.8.3
WhiteboxHub/UIProject-Angular1 >=1.8.3
mbalex99/aintro >=1.8.3
MaxLeap/Console >=1.8.3
faro84/sordipubbliciredux >=1.8.3
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment