commit 026764374e1d802679e6bb0b41cd202c1e440620 Author: Jared Date: Thu Oct 20 15:35:59 2022 -0400 first commit diff --git a/BraveSearchPlus.user.js b/BraveSearchPlus.user.js new file mode 100644 index 0000000..b037405 --- /dev/null +++ b/BraveSearchPlus.user.js @@ -0,0 +1,51 @@ +// ==UserScript== +// @name Brave Search Plus +// @namespace https://ikibani.com +// @version 0.1 +// @description Supercharge the Brave search engine. +// @author afycyro +// @match https://search.brave.com/ +// @match https://search.brave.com/search?q=* +// @icon https://www.google.com/s2/favicons?sz=64&domain=brave.com +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + + let search = { + origTerms: "", + terms: "", + exclude: [], + } + + const searchBox = document.querySelector('input#searchbox'); + + document.querySelector('form.form').addEventListener('submit', () => { + let searchValue = searchBox.value.trim(); + search.origTerms = searchValue; + searchValue = searchValue.toLowerCase().split(' ').filter(t => !t.startsWith('-')).join(' '); + + search.exclude = searchBox.value.split(' ').filter(term => term.startsWith('-')).map(term => term.slice(1)); + search.terms = searchValue; + window.localStorage.setItem('searchOptions', JSON.stringify(search)); + searchBox.value = search.terms; + + return true; + }); + + if (window.location.href.split('/').filter(c => !!c).length > 2) { + search = JSON.parse(window.localStorage.getItem('searchOptions')); + searchBox.value = search.origTerms; + document.querySelector('head title').innerText = `${search.origTerms} - Brave Search` + const results = document.querySelectorAll('.snippet.fdb'); + for (let result of results) { + let resultLoc = result.querySelector('.netloc'); + for (let exclusion of search.exclude) { + if (resultLoc.innerText.toLowerCase().includes(exclusion)) { + result.style.display = 'none'; + } + } + }; + } +})();