diff --git a/browserAction/browserAction.css b/browserAction/browserAction.css index 05d3aa0..ed90c00 100644 --- a/browserAction/browserAction.css +++ b/browserAction/browserAction.css @@ -46,4 +46,10 @@ div { background-color: currentColor; mask-size: 100%; display: inline-block; +} + +.search { + box-sizing: border-box; + padding-left: calc(0.5em + 19px + 0.25em); + cursor: initial; } \ No newline at end of file diff --git a/browserAction/browserAction.js b/browserAction/browserAction.js index 834e9c4..4c13ab0 100644 --- a/browserAction/browserAction.js +++ b/browserAction/browserAction.js @@ -79,5 +79,21 @@ actionButton.addEventListener("click", action.action); actions.appendChild(actionButton); }); + + var search = document.createElement("input"); + search.placeholder = browser.i18n.getMessage("search"); + search.className = "search action"; + actions.appendChild(search); + search.focus(); + + search.addEventListener("keyup", function(event){ + if ([10, 13].indexOf(event.keyCode) !== -1){ + window.open(browser.extension.getURL( + "options/options.html" + + "?search=" + + encodeURIComponent(this.value) + )); + } + }); }); }()); \ No newline at end of file diff --git a/lib/main.js b/lib/main.js index 7bb81d9..b69f08c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -148,7 +148,7 @@ !browser.pageAction.openPopup ){ browser.tabs.create({ - url: browser.extension.getURL("options/options.html?" + reason) + url: browser.extension.getURL("options/options.html?notice=" + reason) }); } } diff --git a/lib/search.js b/lib/search.js index 0371fd0..840d633 100644 --- a/lib/search.js +++ b/lib/search.js @@ -57,13 +57,16 @@ window.setTimeout(() => node.focus(), 1); let lastResults = []; node.addEventListener("input", function(){ + this.search(); + }); + node.search = function(){ const search = this.value; const results = search? scope.search(search): []; searchListeners.forEach(function(callback){ callback({search, results, lastResults}); }); lastResults = results; - }); + }; return node; }; scope.on = function(callback){ diff --git a/options/options.js b/options/options.js index 4ef0cce..e4a2844 100644 --- a/options/options.js +++ b/options/options.js @@ -12,7 +12,8 @@ const settingsDisplay = require("./settingsDisplay"); const search = require("./search"); const settingStrings = require("./settingStrings"); - + const searchParameters = new URLSearchParams(window.location.search); + var callbacks = { showReleaseNotes: function(){ logging.verbose("open release notes"); @@ -118,8 +119,8 @@ introduction.textContent = browser.i18n.getMessage("optionsIntroduction"); head.appendChild(introduction); - if (window.location.search){ - let noticeName = window.location.search.substr(1).trim() + "Notice"; + if (searchParameters.has("notice")){ + let noticeName = searchParameters.get("notice") + "Notice"; let notice = browser.i18n.getMessage(noticeName); if (notice){ let bookmarkingNotice = document.createElement("div"); @@ -174,16 +175,20 @@ document.body.appendChild(table); const displayHidden = settings.getDefinition(settingsDisplay.displayHidden); + const searchInput = search.init(); table.appendChild( optionsGui.createThead( displayHidden, - search.init() + searchInput ) ); - const searchOnly = window.location.search === "?searchOnly"; + const searchOnly = searchParameters.has("searchOnly"); if (searchOnly){ document.body.classList.add("searching"); } + if (searchParameters.has("search")){ + searchInput.value = searchParameters.get("search"); + } search.on(function({search, results, lastResults}){ lastResults.forEach(function(node){ node.classList.remove("found"); @@ -412,4 +417,6 @@ } }); }); + + searchInput.search(); }()); diff --git a/releaseNotes.txt b/releaseNotes.txt index 94a89b6..f3f6fa3 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -4,6 +4,7 @@ Version 0.5.5: new features: - added settings sanitation page + - added search field to browser action popup fixes: - Google images did not work for some users