chatgpt-google-extension icon indicating copy to clipboard operation
chatgpt-google-extension copied to clipboard

Fix baidu support

Open wong2 opened this issue 2 years ago • 10 comments

@josStorer since baidu loads search result page without a page load, the extension will not be triggered.

wong2 avatar Dec 09 '22 12:12 wong2

yes, currently have to make a refresh after a search

josStorer avatar Dec 09 '22 12:12 josStorer

i think we can add action to the search engine config file like

baidu: {
    inputQuery: [],
    sidebarContainerQuery: [],
    appendContainerQuery: [],
    action: {
        beforeMount: someFunction1, // add some listener
        onMount: someFunction2, // add some listener, and we can also implement custom styles here
        ..... // not sure if the other life cycle functions is necessary, like onFailedMount, onResponse, onResponseSuccess, onResponseUnauth, onResponseError
    }
},

function someFunction1(container, parent){ // parent is null if not found
}

function someFunction2(container, parent){
}

I didn't add this to PR, cause it will make a big impact on index.mjs

josStorer avatar Dec 09 '22 12:12 josStorer

i think we can add action to the search engine config file like

should i create another issue for that?

josStorer avatar Dec 09 '22 13:12 josStorer

No, we can discuss in this issue

wong2 avatar Dec 09 '22 13:12 wong2

may i create a pull request to fix this with the above lifecycle actions, and then ask you to do a code review?

josStorer avatar Dec 09 '22 14:12 josStorer

I don't we need general apis for beforeMount, onMount etc, what we need is run run after location changed for any reasons

wong2 avatar Dec 09 '22 14:12 wong2

i don't think that will work, because location will change first, and then components update, setTimeout will also not work, because we cannot know users' network status

so as an example, for baidu, we have to use MutationObserver, to observe #wrapper_wrapper, which means that it makes more sense to set in the config file for different search engines, and also for possible style adaptations in future

josStorer avatar Dec 09 '22 15:12 josStorer

Makes sense. i think we can put baidu support on hold temporarily

wong2 avatar Dec 09 '22 15:12 wong2

I'll try to add the support in a generic way in my fork, maybe I can create a PR then and ask you to make a review, but of course, I won't have time today

josStorer avatar Dec 09 '22 15:12 josStorer

fixed in #93

josStorer avatar Dec 10 '22 07:12 josStorer