Fivefold/linkding-injector

Theme option in settings / SearX support

Closed this issue · 10 comments

It would be great if there could be a dark/light theme option in the addon settings.
Additionally how much work would it be to support a search engine like SearX?

It would be great if there could be a dark/light theme option in the addon settings.

I will try to add dark/light/automatic theme options for the next update.

Additionally how much work would it be to support a search engine like SearX?

I'm not familiar with SearX but from what I see it's mainly intended to be self-hosted. There are lots of public instances too. The problem is that I need to specify the pages the content script is injected into in the extension's manifest.json. This can't be changed at runtime, e.g. for specifying the URL of your SearX instance yourself.

Since a SearX instance could be hosted at any URL and public instances found here also vary wildly in their URLs (and even use different themes) I don't see a way of properly supporting SearX.

If you know basic javascript and css you could add support for your instance yourself by forking the project and putting the URL of your own SearX instance into the manifest.json. I can give you further instructions if interested.

Hmm yes I can see the code.

This can't be changed at runtime, e.g. for specifying the URL of your SearX instance yourself.

So we couldn't make an option in preferences to add URLS to inject the link into?
Thanks for the awesome extension!

So we couldn't make an option in preferences to add URLS to inject the link into?

I'm afraid not. The content script (which injects/creates the results box in the search page) can only be injected into pages pre-defined in the manifest.json (see here)

The only way I can think of is injecting the content script into all pages and then actually do someting within the script depending on the current URL. I don't think this is worth it though due to security concerns.


Regarding adding a URL yourself by forking the extension:

You need to add a block like this containing your SearX URL. You could also just add it in line 22. See the link above for a match pattern reference.

{
"matches": ["*://duckduckgo.com/*"],
"css": ["build/searchInjection.css"],
"js": ["build/searchInjection.js"]
},

Then you'd need to add relevant code in the content script:

if (document.location.hostname.match(/duckduckgo/)) {
searchEngine = "duckduckgo";
} else if (document.location.hostname.match(/google/)) {
searchEngine = "google";
}

As well as here:

// querySelectors for finding the sidebar in the search engine websites
if (searchEngine == "duckduckgo") {
sidebar = document.querySelector(".sidebar-modules");
} else if (searchEngine == "google") {
sidebar = document.querySelector("#rhs");
}

For the querySelector you'd need to find the relevant sidebar div css class or ideally id to inject into (easily found using right-click and inspect on your SearX page).

Since SearX doesn't seem to put the search term in the URL parameters you need to extract it otherwise. An option would be this:

let searchTerm = document.querySelector("#q").value     // get the search term from the search box form

instead of

let searchTerm = urlParams.get("q");

Of course this would break injection for other search engines, but you could fix that with a simple if-expression selecting for search engine.

This should get the injection working, the rest is CSS styling.

To test or use your personalized extension see here.

Sure! If you get stuck feel free to ask.

So I have successfully got the extension working inside brave (through load unpacked) but I'm not sure how to load it into firefox. If I load the web-ext-artifacts/linkding_injector-1.1.0.zip as an addon file it fails (corrupt). I tried with both the build script and web-ext build --overwrite-dest zip file.

For testing and development in firefox you can also just open the manifest.json in the source directory via about:debugging and "Load Temporary Add-on" and selecting the manifest.json.

Loading the packaged extension (zip file) should work just as well though. I attached the zip I get via ./build.ps1 (on a Windows machine). See if you can load this and if you have any differences. If you are on Linux it might be a permission issue.

linkding_injector-1.1.0.zip


Edit: I think you tried loading the zip via the regular add-on page in firefox. You need to enter "about:debugging" into the address field and go there for developing. There you can also reload a temporary add-on if you change any files.

When you are satisfied with your changes, pack the extension via the build script, and get it signed by firefox to receive an .xpi file. This one you can load as a regular add-on and use indefinitely.

Manual dark/light theme selection added in v1.2.0

Opened a new issue just for SearX support. It might happen after all. Watch this issue for any news:

Thanks for your help. I did manage to get the Firefox addon working and I was using that until now :)