add user script

This commit is contained in:
Simon Bruder 2019-05-26 15:36:15 +00:00
parent 029b83ef9b
commit 86522cc0d6
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F

38
startpage.user.js Normal file
View file

@ -0,0 +1,38 @@
// ==UserScript==
// @name Startpage Bangs
// @version 1
// @grant none
// @run-at document-start
// @include https://*.startpage.com/*
// ==/UserScript==
fetch('https://s3.sbruder.de/cdn/bangs/bangs.json')
.then(text => text.json())
.then(bangs => {
const urlParams = new URLSearchParams(window.location.search)
const searchQuery = urlParams.get('query')
let matchBang = null
let parsedBang = null
matchBang = searchQuery.match(/(.*) \!(.*)/)
if (matchBang !== null) {
parsedBang = {
'bang': matchBang[2],
'query': matchBang[1]
}
}
matchBang = searchQuery.match(/\!(.*) (.*)/)
if (matchBang !== null) {
parsedBang = {
'bang': matchBang[1],
'query': matchBang[2]
}
}
if (parsedBang !== null) {
redirectURL = bangs[parsedBang.bang].replace('%s', parsedBang.query)
window.location.replace(redirectURL);
}
})