Last active
December 6, 2017 21:17
-
-
Save Pitmairen/38e499c4a37323714dc9607b1db8354b to your computer and use it in GitHub Desktop.
Userscript for current site search with selection search chrome extension. Tested with Violenmonkey.
This file contains 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 Search with the first input found on current site | |
// @namespace https://github.com/Pitmairen/selection-search | |
// @version 0.1 | |
// @description Use search url: #_selectionsearch_=%s With icon url: CURRENT_DOMAIN | |
// @author Pitmairen | |
// @license GPL-3.0 | |
// @match *://*/* | |
// @homepageURL https://chrome.google.com/webstore/detail/selection-search/gipnlpdeieaidmmeaichnddnmjmcakoe | |
// @supportURL https://github.com/Pitmairen/selection-search/issues | |
// @run-at document-idle | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var selectors = [ | |
'input[id*="search"]', | |
'input[class*="search"]', | |
'input[type="search"]', | |
'form[class*="search"] input[type="text"]', | |
'form[id*="search"] input[type="text"]', | |
'form[action*="search"] input[type="text"]', | |
'input[name="q"]', | |
]; | |
var overrides = { | |
'forum.vivaldi.net': (input) => { | |
input.form.action = '/search'; | |
input.name = 'term'; | |
}, | |
}; | |
var separator = '_selectionsearch_='; | |
var doSearch = () => { | |
if(location.hash.indexOf(separator) !== -1){ | |
var input = document.querySelector(selectors.join(',')); | |
if(input != null){ | |
var query = decodeURIComponent(location.hash.split(separator)[1]); | |
input.value=query; | |
if(location.host in overrides){ | |
overrides[location.host](input); | |
} | |
input.form.submit(); | |
} | |
} | |
} | |
window.addEventListener('hashchange', doSearch); | |
doSearch(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment