-
Notifications
You must be signed in to change notification settings - Fork 1
/
override.js
34 lines (24 loc) · 873 Bytes
/
override.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
const pattern =
/\/w (?<name>.+) Hi! I want to (?<action>buy|sell): (?<item>.+) for (?<cost>[0-9]+) platinum\. \(warframe\.market\)/;
document.addEventListener("copy", async (event) => {
const saved = await browser.storage.local.get("templates");
const templates = saved.templates;
const contents = document.activeElement?.value;
if (!contents) {
return;
}
match = contents.match(pattern);
if (match) {
event.preventDefault();
let template =
match.groups.action == "buy" ? templates.buy : templates.sell;
if (!template) {
return;
}
whisper = `/w {name} ${template}`;
for (const name in match.groups) {
whisper = whisper.replaceAll(`{${name}}`, match.groups[name]);
}
await navigator.clipboard.writeText(whisper);
}
});