-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
googleLens.js
67 lines (51 loc) · 1.63 KB
/
googleLens.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {findNode, processNode, runOnce, sleep} from 'utils/common';
import {setFileInputData, initSearch, sendReceipt} from 'utils/engines';
const engine = 'googleLens';
async function search({session, search, image, storageIds}) {
const inputSelector = 'input[type="file"]';
async function clickButton() {
await processNode('div[data-base-lens-url]', async function (node) {
await sleep(1000);
if (!document.querySelector(inputSelector)) {
node.click();
}
});
}
// handle consent popup
processNode(
`//div[@role="dialog"
and contains(., "g.co/privacytools")
and .//a[starts-with(@href, "https://policies.google.com/technologies/cookies")]
and .//a[starts-with(@href, "https://policies.google.com/privacy")]
and .//a[starts-with(@href, "https://policies.google.com/terms")]
]`,
function (node) {
if (node) {
node.querySelectorAll('button')[2].click();
clickButton();
}
},
{throwError: false, selectorType: 'xpath'}
);
await clickButton();
if (search.assetType === 'image') {
const input = await findNode(inputSelector);
await setFileInputData(inputSelector, input, image);
await sendReceipt(storageIds);
input.dispatchEvent(new Event('change'));
} else {
const input = await findNode(
`//div[count(child::*)=2]/input[following-sibling::div[@role="button"]]`,
{selectorType: 'xpath'}
);
input.value = image.imageUrl;
await sendReceipt(storageIds);
input.nextElementSibling.click();
}
}
function init() {
initSearch(search, engine, taskId);
}
if (runOnce('search')) {
init();
}