From 5880ee918b9fdb8a171802fac2c5e8476bd5a984 Mon Sep 17 00:00:00 2001 From: Joe Jarvis Date: Tue, 24 Jul 2018 17:33:52 -0400 Subject: [PATCH] Open in tab button next to list, false positive badges fixed --- extension/notes.css | 4 +++ extension/notes.js | 38 ++++++++++++++++------- extension/setup.js | 76 ++++++++++++++++++++++----------------------- 3 files changed, 68 insertions(+), 50 deletions(-) diff --git a/extension/notes.css b/extension/notes.css index aead335..08cb012 100644 --- a/extension/notes.css +++ b/extension/notes.css @@ -183,3 +183,7 @@ select { flex: 0 1 20px; overflow-y: hidden; } + +.bold { + font-weight: bold; +} diff --git a/extension/notes.js b/extension/notes.js index 016bac9..a09a21b 100644 --- a/extension/notes.js +++ b/extension/notes.js @@ -106,22 +106,32 @@ async function deleteNote() { async function loadCustomNote(e) { var tabs = await browser.tabs.query({active: true, currentWindow: true}); - console.log(e.target.innerText) - if (e.target.innerText !== back.innerText && e.target.className !== "mdi mdi-delete") { - back.dataset[tabs[0].id] = e.target.innerText; - } else { - delete back.dataset[tabs[0].id]; - loadSiteNotes(); + if (e.target.className === "name") { + if (e.target.innerText !== back.innerText) { + back.dataset[tabs[0].id] = e.target.innerText; + } else if (e.target.innerText === back.innerText) { + delete back.dataset[tabs[0].id]; + loadSiteNotes(); + } } if (e.target.innerText === "General Notes") { loadGeneralNotes(); - } else if (e.target.className === "mdi mdi-delete") { + } + switch (e.target.className) { + case "mdi mdi-delete": confirmDelete.style.width = "100%"; siteName.innerText = e.target.dataset.deleteSite; return; - } else if (e.target.className === "name") { - siteNoteSetup(e.target.innerText); - } else { + case "mdi mdi-open-in-new": + browser.tabs.create({ + active: true, + url: "https://" + e.target.dataset.open + }); + break; + case "name": + siteNoteSetup(back.dataset[tabs[0].id]); + break; + default: return; } closeList(); @@ -210,10 +220,16 @@ function addNoteToList(site) { name.innerText = site; name.title = site; name.className = "name"; + cont.append(name); + if (site.indexOf("about:") === -1) { + var open = document.createElement("span"); + open.dataset.open = site; + open.className = "mdi mdi-open-in-new"; + cont.append(open); + } var del = document.createElement("span"); del.dataset.deleteSite = site; del.className = "mdi mdi-delete"; - cont.append(name); cont.append(del); noteList.append(cont); } diff --git a/extension/setup.js b/extension/setup.js index 3d37368..4d2eacc 100644 --- a/extension/setup.js +++ b/extension/setup.js @@ -1,41 +1,40 @@ -function setOpts() { - browser.storage.local.get().then((res) => { - res.options = res.hasOwnProperty("options") ? res.options : {}; - res.options.theme = res.options.hasOwnProperty("theme") ? res.options.theme : "light"; - res.options.background_color = res.options.hasOwnProperty("background_color") ? res.options.background_color : "ffffff"; - res.options.font_color = res.options.hasOwnProperty("font_color") ? res.options.font_color : "000000"; - res.options.background_color_dark = res.options.hasOwnProperty("background_color_dark") ? res.options.background_color_dark : "000000"; - res.options.font_color_dark = res.options.hasOwnProperty("font_color_dark") ? res.options.font_color_dark : "ffffff"; - res.options.width = res.options.hasOwnProperty("width") ? res.options.width : 400; - res.options.height = res.options.hasOwnProperty("height") ? res.options.height : 300; - res.options.font_family = res.options.hasOwnProperty("font_family") ? res.options.font_family : "default"; - res.options.font_size = res.options.hasOwnProperty("font_size") ? res.options.font_size : 16; - res.options.font_css = res.options.hasOwnProperty("font_css") ? res.options.font_css : ""; - res.options.default_display = res.options.hasOwnProperty("default_display") ? res.options.default_display : "general_notes"; - if (res.options.default_display === "site_notes") { - res.options.default_display = res.options.per_site; - } - // res.options.per_site = res.options.hasOwnProperty("per_site") ? res.options.per_site : "domain"; - res.options.private_browsing = res.options.hasOwnProperty("private_browsing") ? res.options.private_browsing : false; - res.options.subdomains_mode = res.options.hasOwnProperty("subdomains_mode") ? res.options.subdomains_mode : "blacklist"; - res.options.subdomains = res.options.hasOwnProperty("subdomains") ? res.options.subdomains : []; - res.options.notification_badge = res.options.hasOwnProperty("notification_badge") ? res.options.notification_badge : "disabled"; - res.options.notification_badge_color = res.options.hasOwnProperty("notification_badge_color") ? res.options.notification_badge_color : "d90000"; - res.options.bullet_types = res.options.hasOwnProperty("bullet_types") ? res.options.bullet_types : ["*", "-", "+"]; - res.options.get_params = res.options.hasOwnProperty("get_params") ? res.options.get_params : ["q", "v"]; - res.options.tabnos = res.options.hasOwnProperty("tabnos") ? res.options.tabnos : 1; - res.options.padding = res.options.hasOwnProperty("padding") ? res.options.padding : 5; - res.site_notes = res.hasOwnProperty("site_notes") ? res.site_notes : {}; - if (!Array.isArray(res.general_notes)) { - res.general_notes = [res.general_notes]; - } - for (var site in res.site_notes) { - if (!Array.isArray(res.site_notes[site])) { - res.site_notes[site] = [res.site_notes[site]]; - } +async function setOpts() { + var res = await browser.storage.local.get(); + res.options = res.hasOwnProperty("options") ? res.options : {}; + res.options.theme = res.options.hasOwnProperty("theme") ? res.options.theme : "light"; + res.options.background_color = res.options.hasOwnProperty("background_color") ? res.options.background_color : "ffffff"; + res.options.font_color = res.options.hasOwnProperty("font_color") ? res.options.font_color : "000000"; + res.options.background_color_dark = res.options.hasOwnProperty("background_color_dark") ? res.options.background_color_dark : "000000"; + res.options.font_color_dark = res.options.hasOwnProperty("font_color_dark") ? res.options.font_color_dark : "ffffff"; + res.options.width = res.options.hasOwnProperty("width") ? res.options.width : 400; + res.options.height = res.options.hasOwnProperty("height") ? res.options.height : 300; + res.options.font_family = res.options.hasOwnProperty("font_family") ? res.options.font_family : "default"; + res.options.font_size = res.options.hasOwnProperty("font_size") ? res.options.font_size : 16; + res.options.font_css = res.options.hasOwnProperty("font_css") ? res.options.font_css : ""; + res.options.default_display = res.options.hasOwnProperty("default_display") ? res.options.default_display : "general_notes"; + if (res.options.default_display === "site_notes") { + res.options.default_display = res.options.per_site; + } + // res.options.per_site = res.options.hasOwnProperty("per_site") ? res.options.per_site : "domain"; + res.options.private_browsing = res.options.hasOwnProperty("private_browsing") ? res.options.private_browsing : false; + res.options.subdomains_mode = res.options.hasOwnProperty("subdomains_mode") ? res.options.subdomains_mode : "blacklist"; + res.options.subdomains = res.options.hasOwnProperty("subdomains") ? res.options.subdomains : []; + res.options.notification_badge = res.options.hasOwnProperty("notification_badge") ? res.options.notification_badge : "disabled"; + res.options.notification_badge_color = res.options.hasOwnProperty("notification_badge_color") ? res.options.notification_badge_color : "d90000"; + res.options.bullet_types = res.options.hasOwnProperty("bullet_types") ? res.options.bullet_types : ["*", "-", "+"]; + res.options.get_params = res.options.hasOwnProperty("get_params") ? res.options.get_params : ["q", "v"]; + res.options.tabnos = res.options.hasOwnProperty("tabnos") ? res.options.tabnos : 1; + res.options.padding = res.options.hasOwnProperty("padding") ? res.options.padding : 5; + res.site_notes = res.hasOwnProperty("site_notes") ? res.site_notes : {}; + if (!Array.isArray(res.general_notes)) { + res.general_notes = [res.general_notes]; + } + for (var site in res.site_notes) { + if (!Array.isArray(res.site_notes[site])) { + res.site_notes[site] = [res.site_notes[site]]; } - browser.storage.local.set(res); - }); + } + browser.storage.local.set(res); } function escapeRegex(regex) { @@ -55,7 +54,7 @@ function bulletCounter(bulletTypes, note) { } function setBadge(bullet_types, notification_badge, notes, tabId) { - if (notes !== "") { + if (notes !== null && notes !== "") { if (notification_badge.indexOf("enabled") > -1) { browser.browserAction.setBadgeText({text: "!", tabId: tabId}); } @@ -79,7 +78,6 @@ async function setBadgeSite(tab) { setBadgeGeneral(tab); } else if (!tab.incognito || (res.options.private_browsing && tab.incognito)) { if (res.site_notes.hasOwnProperty(site)) { - console.log(res.site_notes[site][0]) setBadge(res.options.bullet_types, res.options.notification_badge, res.site_notes[site][0], tab.id); } else { browser.browserAction.setBadgeText({text: "", tabId: tab.id});