-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
dreamstime.js
45 lines (34 loc) · 1.01 KB
/
dreamstime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {
findNode,
processNode,
isMobile,
executeScriptMainContext,
runOnce
} from 'utils/common';
import {setFileInputData, initSearch, sendReceipt} from 'utils/engines';
import {targetEnv} from 'utils/config';
const engine = 'dreamstime';
async function search({session, search, image, storageIds}) {
if (targetEnv === 'safari' && (await isMobile())) {
// hide noncritical upload error
executeScriptMainContext({func: 'hideAlert'});
}
const inputSelector = 'input[type="file"]';
processNode(inputSelector, function (node) {
node.addEventListener('click', ev => ev.preventDefault(), {
capture: true,
once: true
});
});
(await findNode('button.search-by-image__btn')).click();
const input = await findNode(inputSelector);
await setFileInputData(inputSelector, input, image, {patchInput: true});
await sendReceipt(storageIds);
input.dispatchEvent(new Event('change'));
}
function init() {
initSearch(search, engine, taskId);
}
if (runOnce('search')) {
init();
}