├── README.adoc └── combine-tw5-and-search-engine-results.user.js /README.adoc: -------------------------------------------------------------------------------- 1 | = Userscript: Combine TiddlyWiki5 and search engine (Google) results 2 | 3 | Have you ever been looking for something on Google and when you found the 4 | answer, you wanted to make a note of it, did you realize that you already had 5 | the answer in your https://tiddlywiki.com/[TiddlyWiki]? To avoid these 6 | situations by *integrating TiddlyWiki search results to Google* , use this 7 | userscript with TiddlyWiki (at least 5.1.22 version) on Node.js. 8 | 9 | Because the script searches in multiple TiddlyWikis at once, it can also be 10 | used to *search in all your wikis*. 11 | 12 | * https://github.com/bimlas/userscript-combine-tw5-and-search-engine-results (please star if you like it) 13 | 14 | == How to install? 15 | 16 | * Install 17 | https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/[Greasemonkey] or 18 | a compatible userscript-manager extension 19 | (https://violentmonkey.github.io/[Violentmonkey], 20 | https://www.tampermonkey.net/[Tampermonkey]) to your browser 21 | * Add this script to it: 22 | https://github.com/bimlas/userscript-combine-tw5-and-search-engine-results/raw/master/combine-tw5-and-search-engine-results.user.js 23 | * Set up `wikis` in the script (don't forget to save the changes) 24 | * Start your Node based TiddlyWikis 25 | * *Enable particular filters in each of them!* See 26 | https://tiddlywiki.com/#WebServer%20API%3A%20Get%20All%20Tiddlers 27 | * Open your favourite search engine and start searching 28 | 29 | image::https://i.imgur.com/D7tZA8C.gif[screencast] 30 | 31 | == Supported search engines 32 | 33 | * https://www.google.com/[Google] 34 | * https://www.startpage.com/[StartPage] 35 | * https://duckduckgo.com/[DuckDuckGo] 36 | * https://www.ecosia.org/[Ecosia] 37 | -------------------------------------------------------------------------------- /combine-tw5-and-search-engine-results.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name TiddlyWiki5: Combine TW5 and search engine results 3 | // @description Combine TiddlyWiki and your preferred search engine to find your own answers more easily 4 | // @version 0.3.1 5 | // @author bimlas 6 | // @supportURL https://github.com/bimlas/userscript-combine-tw5-and-search-engine-results 7 | // @downloadURL https://github.com/bimlas/userscript-combine-tw5-and-search-engine-results/raw/master/combine-tw5-and-search-engine-results.user.js 8 | // @icon https://tiddlywiki.com/favicon.ico 9 | // @namespace Violentmonkey Scripts 10 | // @match *://www.google.com/search* 11 | // @match *://www.startpage.com/* 12 | // @match *://duckduckgo.com/* 13 | // @match *://www.ecosia.org/search* 14 | // @grant GM_xmlhttpRequest 15 | // ==/UserScript== 16 | 17 | // READ THE DOCUMENTATION BEFORE TRYING TO USE THE SCRIPT! 18 | // https://github.com/bimlas/userscript-combine-tw5-and-search-engine-results 19 | 20 | const wikis = ["http://localhost:8080"]; 21 | const buildWikiFilter = function (query) { 22 | return `[!is[system]search[${query}]]`; 23 | }; 24 | 25 | // NOTE: If you want to show results in the sidebar, change this option to 26 | // 'sidebar', but remember that the sidebar is not always visible (for example, 27 | // if the window is too narrow). 28 | const placementOfResults = "main"; 29 | 30 | const searchEngineConfigs = { 31 | "www.google.com": { 32 | searchInputSelector: "input[name=q]", 33 | searchResultsSelector: { 34 | main: "#center_col", 35 | sidebar: "#rhs", 36 | }, 37 | }, 38 | // StartPage changes its URL and website structure, so the script does not work in all cases 39 | "www.startpage.com": { 40 | searchInputSelector: "#q", 41 | searchResultsSelector: { 42 | main: "div.mainline-results", 43 | sidebar: "div.sidebar-results", 44 | }, 45 | }, 46 | "duckduckgo.com": { 47 | searchInputSelector: "input[name=q]", 48 | searchResultsSelector: { 49 | main: "#links.results", 50 | sidebar: "div.sidebar-modules", 51 | }, 52 | }, 53 | "www.ecosia.org": { 54 | searchInputSelector: "input[name=q]", 55 | searchResultsSelector: { 56 | main: "div.mainline", 57 | sidebar: "div.sidebar", 58 | }, 59 | }, 60 | }; 61 | const searchEngine = searchEngineConfigs[document.domain]; 62 | 63 | function fetchJSON(origin, url) { 64 | return new Promise((resolve, reject) => { 65 | GM_xmlhttpRequest({ 66 | method: "GET", 67 | headers: { 68 | Origin: origin, 69 | }, 70 | url: url, 71 | onload: function (response) { 72 | resolve(JSON.parse(response.responseText)); 73 | }, 74 | }); 75 | }); 76 | } 77 | 78 | function getTiddlerLink(wiki, title) { 79 | const urlEncodedTitle = encodeURIComponent(title); 80 | const singleViewUrl = `${wiki}/${urlEncodedTitle}`; 81 | const normalViewUrl = `${wiki}/#${urlEncodedTitle}`; 82 | return `${title} (#)`; 83 | } 84 | 85 | function getWikiTitle(wiki) { 86 | return new Promise((resolve, reject) => { 87 | const urlEncodedQuery = encodeURIComponent("$:/SiteTitle"); 88 | const url = `${wiki}/recipes/default/tiddlers/${urlEncodedQuery}`; 89 | fetchJSON(wiki, url).then((results) => { 90 | resolve(results.text); 91 | }); 92 | }); 93 | } 94 | 95 | function addToPage(text) { 96 | const searchEngineResults = document.querySelector( 97 | searchEngine.searchResultsSelector[placementOfResults] 98 | ); 99 | const node = document.createElement("div"); 100 | node.style.display = "inline-flex"; 101 | node.style.margin = "1em"; 102 | node.style.backgroundColor = "rgba(0, 0, 0, 0.05)"; 103 | node.innerHTML = text; 104 | searchEngineResults.insertBefore(node, searchEngineResults.childNodes[0]); 105 | } 106 | 107 | function makeHtmlListFromTiddlers(wiki, listOfTiddlers) { 108 | const htmlList = listOfTiddlers.reduce((text, tiddler) => { 109 | return text + `
`; 124 | addToPage( 125 | `
${makeHtmlListFromTiddlers( 126 | wiki, 127 | results 128 | )}