Created
April 17, 2019 09:28
-
-
Save mspreij/d4ab0aa62376641231030c3c4f537772 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Google results | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://www.google.com/search* | |
// @grant none | |
// @require http://code.jquery.com/jquery-2.2.4.min.js | |
// sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44= | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
$('#hdtbSum').css({ | |
"background": '#eee' | |
}); | |
var filter_results = [ | |
'toptenz.net', | |
'softonic.com', | |
'experts-exchange.com' | |
]; | |
var linkSelector = '#rso .g .rc a h3'; | |
if ($('#search').length) { | |
var links = $(linkSelector); | |
var c = 1; // independent counter because we're filtering stuff out | |
links.each(function() { | |
var a = $(this).closest('a'); | |
// filter results | |
for (var i in filter_results) { | |
if (a.attr('href').indexOf(filter_results[i]) > 0) { | |
a.closest('.g').remove(); | |
return; | |
} | |
} | |
// mark link label with shortcut key | |
$(this).html('<span style="font-size: .8em; color: #080;">[' + c++ + ']</span> ' + $(this).html()); | |
}); | |
links = $(linkSelector); // re-set links, some may have been filtered out and it threw off the links.eq() below | |
$(document).on('keyup', function(e) { | |
if ($(document.activeElement).is("input, textarea")) return false; // ignore actual text entry | |
var key = e.which; | |
if (key >= 96 && key <= 105) key -= 48; // 96-105 = keypad | |
if (key >= 48 && key <= 57) { // 48-57 are numeric 0-9 | |
if (key == 48) key += 10; // make 0 the last instead of the first, | |
key -= 49; // and subtract one too key 1 becomes index 0, key 0 index 9 | |
// links.eq(key).css({backgroundColor: 'red'}); // target practice | |
// this sadly requires telling the browser to allow popups from this site | |
var href = links.eq(key).closest('a').attr('href'); | |
if (e.altKey) { | |
document.location.href = href; | |
}else{ | |
// this sadly requires telling the browser to allow popups from this site | |
window.open(href, '_blank'); | |
} | |
} | |
// jump to search box | |
if (key == 69) { // 'e' for edit (or something) | |
$('input[name=q]').focus(); | |
} | |
// 'n' for next page | |
if (e.key == 'n') { | |
document.location.href = $('#pnnext').attr('href'); | |
} | |
// 'i' for images | |
if (e.key == 'i') { | |
document.location = $('#hdtb-msb-vis a:contains("Images")').attr('href'); // kittens! | |
} | |
return true; // pacify jslint | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment