From 62585192f3281d7c3b6cec914243ba5e7a0f9d3b Mon Sep 17 00:00:00 2001 From: dessant Date: Wed, 11 Dec 2024 19:13:38 +0200 Subject: [PATCH] fix: update Taobao and Alibaba China --- src/engines/alibabaChina.js | 12 ++++-------- src/engines/taobao.js | 17 ++++++++++------- src/utils/scripts.js | 28 +++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/engines/alibabaChina.js b/src/engines/alibabaChina.js index d5071ba..3a74edb 100644 --- a/src/engines/alibabaChina.js +++ b/src/engines/alibabaChina.js @@ -1,19 +1,15 @@ -import {findNode, runOnce} from 'utils/common'; +import {findNode, executeScriptMainContext, runOnce} from 'utils/common'; import {setFileInputData, initSearch, sendReceipt} from 'utils/engines'; const engine = 'alibabaChina'; async function search({session, search, image, storageIds}) { - const button = await findNode('#img-search-upload', {timeout: 120000}); + await executeScriptMainContext({func: 'alibabaChinaPatchContextScript'}); - const inputSelector = 'input.react-file-reader-input'; + const inputSelector = 'input.image-file-reader-wrapper'; const input = await findNode(inputSelector); - input.addEventListener('click', ev => ev.preventDefault(), { - capture: true, - once: true - }); - button.click(); + input.click(); await setFileInputData(inputSelector, input, image); diff --git a/src/engines/taobao.js b/src/engines/taobao.js index 7bb477d..46a24a8 100644 --- a/src/engines/taobao.js +++ b/src/engines/taobao.js @@ -6,12 +6,7 @@ const engine = 'taobao'; async function search({session, search, image, storageIds}) { await executeScriptMainContext({func: 'taobaoPatchContext'}); - ( - await findNode( - '.searchbar-camera-icon div.component-search-icon-container', - {timeout: 120000} - ) - ).click(); + (await findNode('div.image-search-icon-wrapper', {timeout: 120000})).click(); const inputSelector = 'input[type="file"]'; const input = await findNode(inputSelector); @@ -20,7 +15,15 @@ async function search({session, search, image, storageIds}) { await sendReceipt(storageIds); - input.dispatchEvent(new Event('change')); + window.setTimeout(() => { + input.dispatchEvent(new Event('change', {bubbles: true})); + }, 100); + + ( + await findNode('div#image-search-upload-button.upload-button-active', { + observerOptions: {attributes: true, attributeFilter: ['class']} + }) + ).click(); } function init() { diff --git a/src/utils/scripts.js b/src/utils/scripts.js index 6b4b553..88f4317 100644 --- a/src/utils/scripts.js +++ b/src/utils/scripts.js @@ -154,6 +154,31 @@ function lexicaOverrideEventDispatchScript() { }; } +function alibabaChinaPatchContextScript() { + const appendChildFn = Element.prototype.appendChild; + Element.prototype.appendChild = function (node) { + if (node.type === 'file') { + node.addEventListener('click', ev => ev.preventDefault(), { + capture: true, + once: true + }); + + Element.prototype.appendChild = appendChildFn; + } + + return appendChildFn.apply(this, arguments); + }; + + const openFn = window.open; + window.open = function (url) { + if (url.includes('tab=imageSearch')) { + window.location.replace(url); + } else { + return openFn.apply(this, arguments); + } + }; +} + function taobaoPatchContextScript() { const appendChildFn = Element.prototype.appendChild; Element.prototype.appendChild = function (node) { @@ -171,7 +196,7 @@ function taobaoPatchContextScript() { const openFn = window.open; window.open = function (url) { - if (url.includes('/tmw/search_image')) { + if (url.includes('imgSearchOrigin=')) { window.location.replace(url); } else { return openFn.apply(this, arguments); @@ -203,6 +228,7 @@ const scriptFunctions = { setFileInputData: setFileInputDataScript, hideAlert: hideAlertScript, lexicaOverrideEventDispatch: lexicaOverrideEventDispatchScript, + alibabaChinaPatchContextScript: alibabaChinaPatchContextScript, taobaoPatchContext: taobaoPatchContextScript, yandexServiceObserver: yandexServiceObserverScript };