/* create a function that searches internal files of a website */
function searchFiles(query) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.github.com/search/code?q=' + query, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var results = JSON.parse(xhr.responseText);
var resultsDiv = document.createElement('div');
resultsDiv.innerHTML = '<h2>Results</h2>';
for (var i = 0; i < results.items.length; i++) {
var result = results.items[i];
var resultDiv = document.createElement('div');
resultDiv.innerHTML = '<a href="' + result.html_url + '">' + result.html_url + '</a>';
resultsDiv.appendChild(resultDiv);
}
document.body.appendChild(resultsDiv);
}
};
xhr.send();
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter