Skip to content

Commit

Permalink
fix: update Taobao and Alibaba China
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Dec 11, 2024
1 parent 32866a2 commit 6258519
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
12 changes: 4 additions & 8 deletions src/engines/alibabaChina.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
17 changes: 10 additions & 7 deletions src/engines/taobao.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {
Expand Down
28 changes: 27 additions & 1 deletion src/utils/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -203,6 +228,7 @@ const scriptFunctions = {
setFileInputData: setFileInputDataScript,
hideAlert: hideAlertScript,
lexicaOverrideEventDispatch: lexicaOverrideEventDispatchScript,
alibabaChinaPatchContextScript: alibabaChinaPatchContextScript,
taobaoPatchContext: taobaoPatchContextScript,
yandexServiceObserver: yandexServiceObserverScript
};
Expand Down

0 comments on commit 6258519

Please sign in to comment.