Fivefold / linkding-injector

Injects search results from the linkding bookmark service into search pages like google and duckduckgo
MIT License
216 stars 8 forks source link

Theme option in settings / SearX support #2

Closed danielyrovas closed 2 years ago

danielyrovas commented 2 years ago

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?

Fivefold commented 2 years ago

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.

danielyrovas commented 2 years ago

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!

Fivefold commented 2 years ago

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. https://github.com/Fivefold/linkding-injector/blob/fdb713bd3af7f47497dd561a54d4d94ca5e3f8b8/manifest.json#L21-L25

Then you'd need to add relevant code in the content script: https://github.com/Fivefold/linkding-injector/blob/fdb713bd3af7f47497dd561a54d4d94ca5e3f8b8/src/searchInjection.js#L22-L26

As well as here:

https://github.com/Fivefold/linkding-injector/blob/fdb713bd3af7f47497dd561a54d4d94ca5e3f8b8/src/searchInjection.js#L117-L122

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 https://github.com/Fivefold/linkding-injector/blob/fdb713bd3af7f47497dd561a54d4d94ca5e3f8b8/src/searchInjection.js#L139

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.

danielyrovas commented 2 years ago

Thanks for your help, I will try out the fork route.

Fivefold commented 2 years ago

Sure! If you get stuck feel free to ask.

danielyrovas commented 2 years ago

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.

Fivefold commented 2 years ago

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.

Fivefold commented 2 years ago

Manual dark/light theme selection added in v1.2.0

Fivefold commented 1 year ago

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

danielyrovas commented 1 year ago

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