-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (41 loc) · 1014 Bytes
/
Copy pathscript.js
File metadata and controls
49 lines (41 loc) · 1014 Bytes
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
const focusBy = selector => {
const input = document.querySelector(selector);
if (input) {
input.focus();
const endCursor = input.value.length
input.setSelectionRange(endCursor, endCursor)
return true
}
}
const main = async () => {
try {
const { patterns } = await browser.storage.sync.get('patterns')
if (!patterns) {
return
}
const currentPattern = patterns.find(pattern => {
const re = new RegExp(pattern.url);
return document.location.href.match(re);
})
if (currentPattern) {
const selector = currentPattern.selector;
if (selector && focusBy(selector)) {
return
}
}
const defaultSelectors = [
"input[tabIndex='1']",
"input[class*='search']",
"input[id*='search']",
"input[type='search']",
"input[type='text']"
];
for (const selector of defaultSelectors) {
if (focusBy(selector))
break;
}
} catch (error) {
console.error(error)
}
}
main()