From 7a71340b5f491bb5c18d7cf2e3411901848d6915 Mon Sep 17 00:00:00 2001 From: Danilo Novakovic Date: Thu, 29 Aug 2019 23:36:01 +0200 Subject: [PATCH] Made bookmark manager as it's own separate page which can be easily found in popup --- package.json | 2 +- src/css/popup.css | 18 +++++-- src/js/popup/index.js | 36 +++++++------- src/manifest.json | 3 -- src/popup.html | 107 ++++++++++++++++++++++++++---------------- 5 files changed, 99 insertions(+), 67 deletions(-) diff --git a/package.json b/package.json index 0377912..aa1fd21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chrome-dynamic-bookmarks", - "version": "2.6.0", + "version": "2.7.0", "description": "Chrome extension which dynamically updates bookmarks based on the specified regular expression.", "scripts": { "dev": "webpack --mode development", diff --git a/src/css/popup.css b/src/css/popup.css index 7cd4397..f7ded79 100644 --- a/src/css/popup.css +++ b/src/css/popup.css @@ -1,6 +1,14 @@ -#popup-form { - min-width: 320px; - min-height: 260px; - padding-right: 2em; - padding-bottom: 1em; +.popup-wrapper { + min-width: 400px; + min-height: 200px; + margin: 0; + overflow: hidden; +} + +.popup-form { + padding-top: 1.5em; +} + +.popup-form-btn-wrapper { + padding: 1em 0; } diff --git a/src/js/popup/index.js b/src/js/popup/index.js index 0ad4071..6e9d111 100644 --- a/src/js/popup/index.js +++ b/src/js/popup/index.js @@ -1,17 +1,17 @@ -import * as dynBookmarks from '../lib/dynBookmarks'; +import * as dynBookmarks from "../lib/dynBookmarks"; -document.addEventListener('DOMContentLoaded', function() { +document.addEventListener("DOMContentLoaded", function() { // materializecss modal - const popupModalEl = document.querySelector('#popup-modal'); + const popupModalEl = document.querySelector("#popup-modal"); const popupModalInstance = M.Modal.init(popupModalEl, { dismissible: true }); - const formResponse = document.getElementById('form-response'); + const formResponse = document.getElementById("form-response"); // update storage on form submit - const popupForm = document.getElementById('popup-form'); - popupForm.addEventListener('submit', popupSubmit); + const popupForm = document.getElementById("popup-form"); + popupForm.addEventListener("submit", popupSubmit); // url to use in case of error - const defaultUrl = 'https://www.google.com'; + const defaultUrl = "https://www.google.com"; chrome.tabs.query( { @@ -20,12 +20,12 @@ document.addEventListener('DOMContentLoaded', function() { }, function(tabs) { const url = tabs[0].url || defaultUrl; - const title = tabs[0].title || ''; + const title = tabs[0].title || ""; // fill form - const bookmarkNameInput = document.getElementById('bookmark-name-input'); - const urlInput = document.getElementById('url-input'); - const regExpInput = document.getElementById('regexp-input'); + const bookmarkNameInput = document.getElementById("bookmark-name-input"); + const urlInput = document.getElementById("url-input"); + const regExpInput = document.getElementById("regexp-input"); if (bookmarkNameInput) { bookmarkNameInput.value = title; @@ -39,7 +39,7 @@ document.addEventListener('DOMContentLoaded', function() { } else { const regExpString = url.replace( /(^(http[s]?:\/\/)?(www\.)?)|(\/[^/]*?(\?.*)?$)|(\/[^/?]+\/$)/g, - '' + "" ); regExpInput.value = regExpString.replace(/\./g, `\\.`); } @@ -51,23 +51,23 @@ document.addEventListener('DOMContentLoaded', function() { event.preventDefault(); // extract values from form - const url = event.target['url'].value; - const title = event.target['bookmark_name'].value; + const url = event.target["url"].value; + const title = event.target["bookmark_name"].value; let regExpString = event.target.regexp.value; try { new RegExp(event.target.regexp.value); } catch { - formResponse.textContent = 'Invalid regular expression'; + formResponse.textContent = "Invalid regular expression"; popupModalInstance.open(); return false; } - handleBookmarkSubmit(title, url, regExpString, (err) => { + handleBookmarkSubmit(title, url, regExpString, err => { if (err) { console.warn(err); formResponse.textContent = err; } else { - formResponse.textContent = 'Bookmark has been submitted successfully.!'; + formResponse.textContent = "Bookmark has been submitted successfully.!"; } popupModalInstance.open(); }); @@ -75,7 +75,7 @@ document.addEventListener('DOMContentLoaded', function() { function handleBookmarkSubmit(title, url, regExp, done) { const newUrl = url || defaultUrl; - chrome.bookmarks.create({ title, url: newUrl }, (newBookmark) => { + chrome.bookmarks.create({ title, url: newUrl }, newBookmark => { if (chrome.runtime.lastError) { done(chrome.runtime.lastError.message); } else { diff --git a/src/manifest.json b/src/manifest.json index 518c7c9..243c344 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -24,8 +24,5 @@ "64": "icons8_Books_64.png", "128": "icons8_Books_128.png" }, - "chrome_url_overrides": { - "bookmarks": "bookmarkManager.html" - }, "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'" } diff --git a/src/popup.html b/src/popup.html index 8d30ff4..27ac46e 100644 --- a/src/popup.html +++ b/src/popup.html @@ -1,49 +1,76 @@ - + + + + + + DynBookmark Popup Form + - - - - - DynBookmark Popup Form - - - -
-