-
-
Save pabloab/72539941c2ed68f21dc36abb814b8dd4 to your computer and use it in GitHub Desktop.
Adds !s to StartPage, like DDG
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 StartPage Bangs | |
// @namespace http://tarkus.co/ | |
// @version 0.1 | |
// @description Adds !s to StartPage, like DDG | |
// @match https://startpage.com/* | |
// @run-at document-start | |
// ==/UserScript== | |
// Bangs | |
function starts_with(haystack, needle) { | |
return (haystack.substr(0, needle.length) == needle); | |
} | |
function get_dict() { | |
var out = {}; | |
var params = document.location.search.substr(1).split("&"); | |
var param = []; | |
for(var i = 0; i < params.length; i++) { | |
param = params[i].split("="); | |
out[param[0]] = param[1]; | |
} | |
return out; | |
} | |
function bang(query) { | |
if(starts_with(query, "!")) { | |
var bangs = { | |
"!g": "https://www.google.com/#q=", | |
"!gi": "https://encrypted.google.com/search?tbm=isch&q=", | |
"!gis": "https://www.google.com/searchbyimage?image_url=", | |
"!so": "https://stackoverflow.com/search?q=", | |
"!ddg": "https://duckduckgo.com/?q=", | |
}; | |
var query_split = query.split(" "); | |
if(bangs[query_split[0]] !== undefined) { | |
window.location.replace(bangs[query_split[0]] + query.substr(query_split[0].length + 1, query.length)); | |
} | |
} | |
} | |
var query = get_dict()["query"]; | |
// For POST only, requires whole page to load | |
if(query === undefined) { | |
window.onload = function () { | |
bang(document.getElementById("query_top").value); | |
}; | |
} else { | |
bang(query.replace("%21", "!").replace("+", " ")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment