ssborbis / ContextSearch-web-ext

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

no double-click event, trigger immediately #684

Open DandyClubs opened 9 months ago

DandyClubs commented 9 months ago

i add some scripts search

function openNewBackgroundTab(url){
    var a = document.createElement("a");
    a.href = url
    var evt = document.createEvent("MouseEvents");
    //the tenth parameter of initMouseEvent sets ctrl key
    evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,
                                true, false, false, false, 0, null);
    a.dispatchEvent(evt);
}

        let searchText = (Text) => {
            let SearchWord = Text.replace(/\s&\s/g, ' ').split(/\s-\s/)
            SearchWord = SearchWord.map(e => e.replace(/\n/g, '').trim())
            SearchWord[0] = SearchWord[0].replace(/[^[:alnum:]]/g, '').replace(/\s/g, '')
            SearchWord[0] = /\s-\s/.test(Text) ? SearchWord[0] : Text
            return SearchWord.join(' ')
        }
var url = 'https://therarbg.com/get-posts/keywords:' + searchText(searchTerms) 

function openInNewTab(href) {
  Object.assign(document.createElement('a'), {
    target: '_blank',
    rel: 'noopener noreferrer',
    href: href,
  }).click();
}

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(!is_chrome)
{
    openInNewTab(url)
} else {
    openNewBackgroundTab(url);
}

some add search script

text select

quick menu

script search click.... and new tab open.

and quick menu other script search icon click...

console

no double-click event, trigger immediately

i use firefox

edge not work open background tab

so i make script search

ssborbis commented 9 months ago

That message you are seeing no double-click event, trigger immediately is indicating that you don't have a double-click search action also assigned to the mouse button you are using, and therefore the addon won't wait to check for a second click event on the search engine. Instead, it will trigger the search immediately on the first click.

Did you have another question regarding your script? Also, is the background tab issue with Edge happening only with your script, or with this addon? I'll check also.

DandyClubs commented 9 months ago

A script search B script search

text select

quick menu A or B click

first script search icon click work

but not work when script search icon click until page reload

just console.log no double-click event, trigger immediately

Edge quick menu search icon new tab open and focus search tab

not work background tab open

so i try script

i try

 let searchText = (Text) => {
            let SearchWord = Text.replace(/\s&\s/g, ' ').split(/\s-\s/)
            SearchWord = SearchWord.map(e => e.replace(/\n/g, '').trim())
            SearchWord[0] = SearchWord[0].replace(/[^[:alnum:]]/g, '').replace(/\s/g, '')
            SearchWord[0] = /\s-\s/.test(Text) ? SearchWord[0] : Text
            return SearchWord.join(' ')
        }

to

function searchText(Text){
            let SearchWord = Text.replace(/\s&\s/g, ' ').split(/\s-\s/)
            SearchWord = SearchWord.map(e => e.replace(/\n/g, '').trim())
            SearchWord[0] = SearchWord[0].replace(/[^[:alnum:]]/g, '').replace(/\s/g, '')
            SearchWord[0] = /\s-\s/.test(Text) ? SearchWord[0] : Text
            return SearchWord.join(' ')
        }

so fine work