-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagile-trello-setup.js
42 lines (38 loc) · 1.2 KB
/
agile-trello-setup.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
// Setup dynamic import
const script = document.createElement("script");
script.setAttribute("type", "module");
script.setAttribute("src", chrome.extension.getURL("agile-trello.js"));
const head =
document.head ||
document.getElementsByTagName("head")[0] ||
document.documentElement;
head.insertBefore(script, head.lastChild);
chrome.storage.sync.get(
{
trelloToken: ""
},
function(items) {
const globals = document.createElement("script");
globals.setAttribute("type", "text/javascript");
globals.innerText = `window.trelloToken = '${items.trelloToken}';`;
head.insertBefore(globals, head.lastChild);
}
);
chrome.runtime.onMessage.addListener(function(request, sender, _sendResponse) {
if (request.action === "historyChange") {
boardChanged();
} else {
configChanged(request);
}
});
let lastHistoryChangeFired;
function boardChanged() {
if (!lastHistoryChangeFired || new Date() - lastHistoryChangeFired > 500) {
lastHistoryChangeFired = new Date();
document.body.dispatchEvent(new CustomEvent("board-change", {}));
}
}
function configChanged(request) {
var event = new CustomEvent("agile-popup-form", { detail: request });
document.body.dispatchEvent(event);
}