Skip to content

Commit

Permalink
add update notification
Browse files Browse the repository at this point in the history
  • Loading branch information
waymondrang committed Sep 19, 2022
1 parent a6eafc6 commit 91f5a8d
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/chrome/word.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
const version = chrome.runtime.getManifest().version;

var theme = `#90caf9`;
var warning = `#90caf9`;
Expand Down Expand Up @@ -94,9 +95,10 @@ function set_up() {
var grayscale;
var show_border;
var raise_button;
var updates;

console.log("GETTING FROM STORAGE");
chrome.storage.local.get(["doc_bg", "custom_bg", "invert", "raise_button", "show_border"], function (data) {
chrome.storage.local.get(["doc_bg", "custom_bg", "invert", "raise_button", "show_border", "updates"], function (data) {
console.log(data);
if (Object.keys(data).includes("doc_bg")) {
let option = data.doc_bg;
Expand Down Expand Up @@ -144,6 +146,45 @@ function set_up() {
// Insert Button
default_style.textContent = get_default_style(raise_button);
document.body.insertBefore(default_style, document.body.lastChild);

var update_notification = document.createElement("div");
update_notification.id = "update-notification";
update_notification.style = "top: 0; left: 0; right: 0; background-color: #212121; color: #cecece; padding: 0.5em; text-align: center; z-index: 2500000000;";
update_notification.textContent = "DocsAfterDark has been updated to version " + chrome.runtime.getManifest().version + ". Read update notes on ";
var update_link = document.createElement("a");
update_link.href = "https://github.com/waymondrang/docsafterdark/releases";
update_link.target = "_blank";
update_link.textContent = "GitHub";
update_link.style = "color: #cecece; text-decoration: underline;";
update_notification.appendChild(update_link);
update_notification.appendChild(document.createTextNode("."));
var close_button = document.createElement("button");
close_button.textContent = "Close";
close_button.style = "background-color: #4d4d4d; border-radius: 2px; color: #64b5f6; border: none; cursor: pointer; margin-left: 1em;";
close_button.onclick = function () {
update_notification.style.display = "none";
if (updates) {
if (!updates.includes(version)) {
updates.push(version);
chrome.storage.local.set({ "updates": updates });
}
} else {
chrome.storage.local.set({ "updates": [version] });
}
}
update_notification.appendChild(close_button);

// User must be on page for 10 seconds or manually close notification
if (Object.keys(data).includes("updates")) {
updates = data.updates;
if (!updates.includes(version)) {
// Extension updated
document.body.prepend(update_notification);
}
} else {
// Extension updated
document.body.prepend(update_notification);
}
});

chrome.storage.onChanged.addListener(function (changes, area) {
Expand Down

0 comments on commit 91f5a8d

Please sign in to comment.