bangs/startpage.user.js

39 lines
969 B
JavaScript
Raw Normal View History

2019-05-26 17:36:15 +02:00
// ==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 = {
2019-06-13 15:04:44 +02:00
'bang': matchBang[2].toLowerCase(),
2019-05-26 17:36:15 +02:00
'query': matchBang[1]
}
}
matchBang = searchQuery.match(/\!(.*) (.*)/)
if (matchBang !== null) {
parsedBang = {
2019-06-13 15:04:44 +02:00
'bang': matchBang[1].toLowerCase(),
2019-05-26 17:36:15 +02:00
'query': matchBang[2]
}
}
if (parsedBang !== null) {
redirectURL = bangs[parsedBang.bang].replace('%s', encodeURI(parsedBang.query)).replace('%S', parsedBang.query)
2019-05-26 17:36:15 +02:00
window.location.replace(redirectURL);
}
})