-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
saucenao.js
39 lines (28 loc) · 941 Bytes
/
saucenao.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
import {findNode, runOnce} from 'utils/common';
import {setFileInputData, initSearch, sendReceipt} from 'utils/engines';
const engine = 'saucenao';
async function search({session, search, image, storageIds}) {
const autoSubmit = await findNode('input#auto-cb');
if (!autoSubmit.checked) {
autoSubmit.click();
}
if (search.assetType === 'image') {
const inputSelector = 'input#fileInput';
const input = await findNode(inputSelector);
await setFileInputData(inputSelector, input, image);
await sendReceipt(storageIds);
input.dispatchEvent(new Event('change'));
} else {
const input = await findNode('input#urlInput');
await sendReceipt(storageIds);
input.value = image.imageUrl;
// input.blur() is only dispatched when the tab is active
input.dispatchEvent(new Event('blur'));
}
}
function init() {
initSearch(search, engine, taskId);
}
if (runOnce('search')) {
init();
}