-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransformer.js
More file actions
53 lines (45 loc) · 1.83 KB
/
transformer.js
File metadata and controls
53 lines (45 loc) · 1.83 KB
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
browser._userValues = {
host: null
}
function setOverwrittenHost(hostname) {
browser._userValues.host = hostname;
}
function getOverwrittenHost() {
return browser._userValues.host;
}
async function getHostOfCurrentTab() {
// Get the page title and URL
return new Promise((resolve, reject) => {
browser.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
let tab = tabs[0];
const pageURL = tab.url;
resolve(getHostOfURL(pageURL));
});
});
}
async function updateTransformerInput(hostname) {
document.getElementById(`transformer-hostname`).innerHTML = hostname;
getTransformer(hostname).then((transformer) => {
document.getElementById(`transformer-controller-regex`).value = transformer.regex.toString();
document.getElementById(`transformer-controller-output`).value = transformer.output;
}).catch((err) => {
})
}
async function loadTransformerInputs() {
getHostOfCurrentTab().then(async (hostname) => {
updateTransformerInput(hostname);
})
}
document.getElementById(`applyTransformerBtn`).onclick = async () => {
let hostname = getOverwrittenHost() || await getHostOfCurrentTab();
let regex = RegExpFromStr(document.getElementById(`transformer-controller-regex`).value);
let output = document.getElementById(`transformer-controller-output`).value;
let updated_transformers = await updateTransformer(hostname, regex, output);
browser.storage.local.set({transformers: JSON.stringify(updated_transformers)}, async () => {
loadTransformerInputs();
await loadDataTable();
showModal(`Transformer saved`, [`The transformer you have set for ${hostname} has been ` +
`applied. The next output for ${hostname} will be transformed.`], `success`);
});
}
loadTransformerInputs();