From f48104584730e3e6b358721ddba3cf82240b7769 Mon Sep 17 00:00:00 2001 From: Zhenbo Li <3221521+Endle@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:02:42 -0400 Subject: [PATCH] Add support for Metger (#129) (Feature request https://github.com/Endle/fireSeqSearch/issues/127) --- README.md | 3 +- fireSeqSearch_addon/main.js | 21 +++++--- fireSeqSearch_addon/manifest.json | 5 +- .../violentmonkeyscript.user.js | 49 +++++++++++-------- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 8cc4e4d..4167140 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ fireSeqSearch has a server-side app and a browser extension. ### Install Browser Extension 1. Install latest web extension -2. If you're using other browser, you can install [Tampermonkey](https://www.tampermonkey.net/), then install [monkeyscript.user.js](https://github.com/Endle/fireSeqSearch/raw/master/fireSeqSearch_addon/monkeyscript.user.js). If you prefer (Violentmonkey)[https://violentmonkey.github.io/], you can install [violentmonkeyscript.user.js](https://github.com/Endle/fireSeqSearch/blob/master/fireSeqSearch_addon/violentmonkeyscript.user.js) +2. If you're using other browser, you can install [Tampermonkey](https://www.tampermonkey.net/), then install [monkeyscript.user.js](https://github.com/Endle/fireSeqSearch/raw/master/fireSeqSearch_addon/monkeyscript.user.js). If you prefer [Violentmonkey(https://violentmonkey.github.io/), you can install [violentmonkeyscript.user.js](https://github.com/Endle/fireSeqSearch/blob/master/fireSeqSearch_addon/violentmonkeyscript.user.js) + ### Install Local Server diff --git a/fireSeqSearch_addon/main.js b/fireSeqSearch_addon/main.js index 592435d..8b4c4a0 100644 --- a/fireSeqSearch_addon/main.js +++ b/fireSeqSearch_addon/main.js @@ -1,5 +1,5 @@ // MIT License -// Copyright (c) 2021-2022 Zhenbo Li +// Copyright (c) 2021-2023 Zhenbo Li const fireSeqSearchDomId = "fireSeqSearchDom"; @@ -73,7 +73,6 @@ const fireSeqSearchScriptCSS = ` function consoleLogForDebug(message) { console.log(message); //skipcq: JS-0002 - // Comment it in master branch, to make deepSource happy } @@ -140,7 +139,7 @@ async function appendResultToSearchResult(fetchResultArray, _container) { const rawSearchResult = fetchResultArray[1]; const firefoxExtensionUserOption = await checkUserOptions(); - consoleLogForDebug(firefoxExtensionUserOption); + consoleLogForDebug('Loaded user option: ' + JSON.stringify(firefoxExtensionUserOption)); function createTitleBarDom(count) { const titleBar = createElementWithText("div"); @@ -213,10 +212,13 @@ async function appendResultToSearchResult(fetchResultArray, _container) { function insertDivToWebpage(result) { let contextId = "rcnt"; - if (window.location.href.includes("duckduckgo.com")) { + if (window.location.host.includes("duckduckgo.com")) { contextId = "web_content_wrapper"; } - if (window.location.href.includes("searx")) { // https://github.com/Endle/fireSeqSearch/issues/103 + if (window.location.host.includes("searx")) { // https://github.com/Endle/fireSeqSearch/issues/103 + contextId = "results"; + } + if (window.location.host.includes("metager")) { // https://github.com/Endle/fireSeqSearch/issues/127 contextId = "results"; } document.getElementById(contextId).insertAdjacentElement("beforebegin", result); @@ -233,13 +235,18 @@ function getSearchParameterFromCurrentPage() { const inputBox = document.getElementById("q"); return inputBox.value; } + function getSearchParameterOfMetager() { + const urlParams = new URLSearchParams(window.location.search); + return urlParams.get('eingabe'); + } if (window.location.toString().includes("searx")) { searchParam = getSearchParameterOfSearx(); + } else if (window.location.toString().includes("metager")) { + searchParam = getSearchParameterOfMetager(); } else { // https://stackoverflow.com/a/901144/1166518 const urlParams = new URLSearchParams(window.location.search); - // consoleLogForDebug(urlParams); searchParam = urlParams.get('q'); } @@ -252,7 +259,7 @@ function getSearchParameterFromCurrentPage() { (function() { const searchParameter = getSearchParameterFromCurrentPage(); - consoleLogForDebug(searchParameter); + addGlobalStyle(fireSeqSearchScriptCSS); //https://gomakethings.com/waiting-for-multiple-all-api-responses-to-complete-with-the-vanilla-js-promise.all-method/ diff --git a/fireSeqSearch_addon/manifest.json b/fireSeqSearch_addon/manifest.json index c4bea04..d5b54d5 100644 --- a/fireSeqSearch_addon/manifest.json +++ b/fireSeqSearch_addon/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "fireSeqSearch", - "version": "0.1.3", + "version": "0.1.4", "description": "Everytime you use the search engine, this plugin will search against your personal logseq notes.", @@ -22,7 +22,8 @@ "*://www.google.com.hk/search*", "*://duckduckgo.com/*", "*://searx.prvcy.eu/search", - "*://searx.fmac.xyz/search" + "*://searx.fmac.xyz/search", + "*://metager.org/*" ], "js": ["main.js"] }, diff --git a/fireSeqSearch_addon/violentmonkeyscript.user.js b/fireSeqSearch_addon/violentmonkeyscript.user.js index 43dbd77..4314ee0 100644 --- a/fireSeqSearch_addon/violentmonkeyscript.user.js +++ b/fireSeqSearch_addon/violentmonkeyscript.user.js @@ -5,13 +5,14 @@ // @description Everytime you use the search engine, FireSeqSearch searches your personal logseq notes. // @author Zhenbo Li // @match https://www.google.com/search* -// @match https://duckduckgo.com/?q=* +// @match https://duckduckgo.com/* +// @match https://metager.org/* // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net // @grant GM.xmlHttpRequest // ==/UserScript== // MIT License -// Copyright (c) 2021-2022 Zhenbo Li +// Copyright (c) 2021-2023 Zhenbo Li /*global GM*/ @@ -87,7 +88,6 @@ const fireSeqSearchScriptCSS = ` function consoleLogForDebug(message) { console.log(message); //skipcq: JS-0002 - // Comment it in master branch, to make deepSource happy } @@ -115,7 +115,8 @@ function createHrefToLogseq(record, serverInfo) { const title = record.title; const prettyTitle = title.replaceAll("%2F", "/"); - const target = `logseq://graph/${name}?page=${title}`; + const target = record.logseq_uri || `logseq://graph/${name}?page=${title}`; + const logseqPageLink = document.createElement('a'); const text = document.createTextNode(prettyTitle); logseqPageLink.appendChild(text); @@ -139,13 +140,12 @@ function checkUserOptions() { } -async function appendResultToSearchResult(fetchResultArray, container) { +async function appendResultToSearchResult(fetchResultArray, _container) { const serverInfo = fetchResultArray[0]; const rawSearchResult = fetchResultArray[1]; const firefoxExtensionUserOption = await checkUserOptions(); - - consoleLogForDebug(firefoxExtensionUserOption); + consoleLogForDebug('Loaded user option: ' + JSON.stringify(firefoxExtensionUserOption)); function createTitleBarDom(count) { const titleBar = createElementWithText("div"); @@ -166,16 +166,9 @@ async function appendResultToSearchResult(fetchResultArray, container) { titleBar.appendChild(btn); return titleBar; } - - - function createFireSeqDom() { - const div = document.createElement("div"); - // div.appendChild(createElementWithText("p", "fireSeqSearch launched!")); div.setAttribute("id", fireSeqSearchDomId); - - return div; } @@ -222,12 +215,23 @@ async function appendResultToSearchResult(fetchResultArray, container) { dom.classList.add("experimentalLayout"); } - let contextId = "rcnt"; - if (window.location.href.includes("duckduckgo.com")) { - contextId = "web_content_wrapper"; + + function insertDivToWebpage(result) { + let contextId = "rcnt"; + if (window.location.host.includes("duckduckgo.com")) { + contextId = "web_content_wrapper"; + } + if (window.location.host.includes("searx")) { // https://github.com/Endle/fireSeqSearch/issues/103 + contextId = "results"; + } + if (window.location.host.includes("metager")) { // https://github.com/Endle/fireSeqSearch/issues/127 + contextId = "results"; + } + document.getElementById(contextId).insertAdjacentElement("beforebegin", result); + } - document.getElementById(contextId).insertAdjacentElement("beforebegin", dom); + insertDivToWebpage(dom); } function getSearchParameterFromCurrentPage() { @@ -237,13 +241,18 @@ function getSearchParameterFromCurrentPage() { const inputBox = document.getElementById("q"); return inputBox.value; } + function getSearchParameterOfMetager() { + const urlParams = new URLSearchParams(window.location.search); + return urlParams.get('eingabe'); + } if (window.location.toString().includes("searx")) { searchParam = getSearchParameterOfSearx(); + } else if (window.location.toString().includes("metager")) { + searchParam = getSearchParameterOfMetager(); } else { // https://stackoverflow.com/a/901144/1166518 const urlParams = new URLSearchParams(window.location.search); - // consoleLogForDebug(urlParams); searchParam = urlParams.get('q'); } @@ -256,7 +265,7 @@ function getSearchParameterFromCurrentPage() { (function() { const searchParameter = getSearchParameterFromCurrentPage(); - consoleLogForDebug(searchParameter); + addGlobalStyle(fireSeqSearchScriptCSS); GM.xmlHttpRequest({