ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
354 stars 37 forks source link

searchTerms with multi lines selection problem? #707

Closed runningcheese closed 4 months ago

runningcheese commented 5 months ago

The problem is about "Javascript-Driven Search Engines". When the selections are single line, it works fine! But the selections are multi lines, It will not be executed.
Did i miss something? Thanks!

ssborbis commented 5 months ago

What is the script you are using?

runningcheese commented 5 months ago

The normal one. @ssborbis

(async() => { let input = document.querySelector('input'); input.value = searchTerms; input.dispatchEvent(new KeyboardEvent('keydown', {key:"Enter", keyCode:13, bubbles:true})); input.dispatchEvent(new KeyboardEvent('keyup', {key:"Enter", keyCode:13, bubbles:true})); })();

When i select multi lines as below, the js serach engin not be executed.

aaaa bbbb cccc

ssborbis commented 5 months ago

I'm not seeing that on the sites I've tested. Is there some issue with the website you're using and newline characters in the input? You might try removing newline chars from the searchTerms.

input.value = searchTerms.replace(/[\r\n]/gm, ' ');

runningcheese commented 5 months ago

What I'm trying to say is Searching with the searchTerms JS code, is wroking fine when only one line is selected, But more than one line is selected, the input.value command doesn't work.

Try to select these three lines below, and it doesn't work. @ssborbis

aaaa bbbb cccc

And the code you've just provided, still not working!

ssborbis commented 5 months ago

It's working for me. Are you trying to get 3 separate searches using the multilinesAsSeparateSearches option or are you trying to get all 3 lines as one line in the search field?

runningcheese commented 5 months ago

@ssborbis get all 3 lines as one line in the search field.

input.value = searchTerms.replace(/[\r\n]/gm, ' '); This code doesn't work for me, and i have restore ContextSearch web-ext to default settings.

ssborbis commented 5 months ago

What browser? Engine? It might be a peculiarity of the website you're using

runningcheese commented 5 months ago

@ssborbis Both Firefox and Chrome. Try https://gemini.google.com/app , and the codes are:

(async() => { let input = document.querySelector('[contenteditable]'); input.focus(); input.textContent = searchTerms.replace(/[\r\n]/gm, ' '); input.dispatchEvent(new Event("input", {bubbles:true})); input.dispatchEvent(new Event("change", {bubbles:true})); await new Promise(r => setTimeout(r, 500)); input.dispatchEvent(new KeyboardEvent('keydown', {key:"Enter", keyCode:13, bubbles:true})); })();

ssborbis commented 5 months ago

I'm not having any issues with multilines. I did, however, need to add a delay BEFORE populating the input field, or the searchTerms would be overwritten. Otherwise, it works as expected