Skip to content

Instantly share code, notes, and snippets.

@luchaninov
Created April 19, 2018 16:52
Show Gist options
  • Save luchaninov/c3eba99bdfc1e61f3458273cd3375d8a to your computer and use it in GitHub Desktop.
Save luchaninov/c3eba99bdfc1e61f3458273cd3375d8a to your computer and use it in GitHub Desktop.
Bookmarklet: Google SERP Table
javascript:(function(){
var t, url, pos, num;
var table = [['position', 'domain', 'link', 'title'].join("\t")];
url = window.location.href;
t = url.match(/start=(\d+)/);
pos = t ? t[1] : 0;
t = url.match(/num=(\d+)/);
num = t ? t[1] : 0;
Array.prototype.forEach.call(document.querySelectorAll('h3.r a'), function(el, i){
let href = el.getAttribute('href');
let domain = href.replace(/^.*:\/\/(www\.)?/, '').replace(/\/.*$/, '');
let title = el.innerText;
table.push([++pos, domain, href, title].join("\t"));
});
if (document.querySelector('#playtini-results')) {
document.querySelector('#playtini-results').innerHTML = table.join("\n");
} else {
var bar = document.querySelector('#top_nav');
bar.innerHTML += '<textarea id="playtini-results" style="width:600px; height:300px; margin-left: 165px" wrap="off" onfocus="var inp=this; setTimeout(function(){inp.select();},10);">' + table.join("\n") + '</textarea>';
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment