ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
321 stars 36 forks source link

Problems with Adding Search #613

Closed AnnaS82 closed 1 year ago

AnnaS82 commented 1 year ago

Hello,

I try to add this page with right-clicking the search bar on the website and select "Add To ContextSearch" from the context menu. And I also tried the same with the mycroftproject.

What happens is, a new entry appears in the menu, but the search does not work. The page gives an error message.

This is the page: https://fmovies.to

Can someone help me with this?

ssborbis commented 1 year ago

You'll need to run the search using the javascript field and change your template.

Template: https://fmovies.to/

Post-search Script:

(() => {
    let input = document.querySelector('input');
    input.value = searchTerms;
    input.dispatchEvent(new KeyboardEvent('keyup'));
    input.form.submit();
})();
AnnaS82 commented 1 year ago

Thank you ssborbis, this works great! :-)

Another problemchild for me is this:

https://burningseries.co/andere-serien/

Is there a solution for this too?

ssborbis commented 1 year ago

I can't load that website

AnnaS82 commented 1 year ago

Oh, then you are being blocked by your provider.

Does this one work for you: https://burningseries.tw/andere-serien

ssborbis commented 1 year ago

Something like...

document.querySelector('#serInput').value = searchTerms;
searchSeries();
AnnaS82 commented 1 year ago

Hm, this fills in the search term already, but doesn't trigger the search itself. Only one more keypress is needed.

So similar to your above code I tried:

(() => {
let input = document.querySelector('#serInput');
input.value = searchTerms;   
input.dispatchEvent(new KeyboardEvent('keyup'));
})();

But that is not doing the trick either.

I read through this thread and tried a few things: https://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programmatically

But I suppose the problem lies with React, as described here: https://stackoverflow.com/questions/40894637/how-to-programmatically-fill-input-elements-built-with-react/70848568

Unfortunately this is way above my programming abilities.

Do you have an idea?

ssborbis commented 1 year ago

The scripts are working through the console once the page is open, but not through the addon. I'm wondering if there's some page-level event you need to trigger before the search is allowed, like a focus event or something. I'm looking but nothing is popping out.

ssborbis commented 1 year ago

Nevermind, it was simpler than that. Just needed to bubble the event up

(() => {
let input = document.querySelector('#serInput');
input.value = searchTerms;   
input.dispatchEvent(new KeyboardEvent('keyup', {bubbles:true}));
})();
AnnaS82 commented 1 year ago

Ahhh, this works mega nice! :-) Thank you a lot!

ssborbis commented 1 year ago

Glad to help

AnnaS82 commented 1 year ago

Dear Ssborbis, ... I have another site, which makes problems.

https://myflixer.pw

The code that ContextSearch adds is a simple: https://myflixer.pw/search/{searchTerms}. It works fine for single words as searchterms. ... But with more words the page needs a "-" between the words in the url, whereas ContextSearch adds a " ".

Is there an easy fix for that? And also, is there a place in the documentation, where things like this are explained, so I don't need to bother you all the time? ... I couldn't find it.

ssborbis commented 1 year ago

Is there an easy fix for that?

That's what the Modify Terms Regex field is for.

/\s+/-/g I believe gets the job done. It might be in the readme on the support site ( github ). I'll freely admit, documentation is not my forte, but there's probably mention of it somewhere.

https://github.com/ssborbis/ContextSearch-web-ext#modifyingterms

AnnaS82 commented 1 year ago

Ah, thank you, Ssborbis! This works!

And oh yes, it is all explained in the readme. I don't know how I did miss that. I'm sorry!

Thank you! :-)

ssborbis commented 1 year ago

No problem