Skip to content

Commit

Permalink
Add support for Metger (#129) (Feature request #127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Endle authored Jul 9, 2023
1 parent ee0eb27 commit f481045
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ fireSeqSearch has a server-side app and a browser extension.

### Install Browser Extension
1. Install latest web extension <https://addons.mozilla.org/en-US/firefox/addon/fireseqsearch/>
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

Expand Down
21 changes: 14 additions & 7 deletions fireSeqSearch_addon/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// MIT License
// Copyright (c) 2021-2022 Zhenbo Li
// Copyright (c) 2021-2023 Zhenbo Li

const fireSeqSearchDomId = "fireSeqSearchDom";

Expand Down Expand Up @@ -73,7 +73,6 @@ const fireSeqSearchScriptCSS = `

function consoleLogForDebug(message) {
console.log(message); //skipcq: JS-0002
// Comment it in master branch, to make deepSource happy
}


Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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');
}

Expand All @@ -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/
Expand Down
5 changes: 3 additions & 2 deletions fireSeqSearch_addon/manifest.json
Original file line number Diff line number Diff line change
@@ -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.",

Expand All @@ -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"]
},
Expand Down
49 changes: 29 additions & 20 deletions fireSeqSearch_addon/violentmonkeyscript.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*/

Expand Down Expand Up @@ -87,7 +88,6 @@ const fireSeqSearchScriptCSS = `

function consoleLogForDebug(message) {
console.log(message); //skipcq: JS-0002
// Comment it in master branch, to make deepSource happy
}


Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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;
}

Expand Down Expand Up @@ -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() {
Expand All @@ -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');
}

Expand All @@ -256,7 +265,7 @@ function getSearchParameterFromCurrentPage() {
(function() {
const searchParameter = getSearchParameterFromCurrentPage();

consoleLogForDebug(searchParameter);

addGlobalStyle(fireSeqSearchScriptCSS);

GM.xmlHttpRequest({
Expand Down

0 comments on commit f481045

Please sign in to comment.