From 2c752fd89d3427da855704406e34c9458d33e832 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 May 2021 16:30:33 -0400 Subject: Popup action search (#1678) * Set up search page in the action popup * Fix a style causing incorrect overflow * Fix error when trying to take a screenshot * Fix popup size on Firefox --- ext/js/pages/action-popup-main.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'ext/js/pages') diff --git a/ext/js/pages/action-popup-main.js b/ext/js/pages/action-popup-main.js index 4934802b..b3198676 100644 --- a/ext/js/pages/action-popup-main.js +++ b/ext/js/pages/action-popup-main.js @@ -31,7 +31,7 @@ class DisplayController { this._showExtensionInfo(manifest); this._setupEnvironment(); - this._setupButtonEvents('.action-open-search', 'openSearchPage', chrome.runtime.getURL('/search.html')); + this._setupButtonEvents('.action-open-search', 'openSearchPage', chrome.runtime.getURL('/search.html'), this._onSearchClick.bind(this)); this._setupButtonEvents('.action-open-info', 'openInfoPage', chrome.runtime.getURL('/info.html')); const optionsFull = await yomichan.api.optionsGetFull(); @@ -60,6 +60,13 @@ class DisplayController { // Private + _onSearchClick(e) { + if (!e.shiftKey) { return; } + e.preventDefault(); + location.href = '/search.html?action-popup=true'; + return false; + } + _showExtensionInfo(manifest) { const node = document.getElementById('extension-info'); if (node === null) { return; } @@ -67,12 +74,16 @@ class DisplayController { node.textContent = `${manifest.name} v${manifest.version}`; } - _setupButtonEvents(selector, command, url) { + _setupButtonEvents(selector, command, url, customHandler) { const nodes = document.querySelectorAll(selector); for (const node of nodes) { if (typeof command === 'string') { node.addEventListener('click', (e) => { if (e.button !== 0) { return; } + if (typeof customHandler === 'function') { + const result = customHandler(e); + if (typeof result !== 'undefined') { return; } + } yomichan.api.commandExec(command, {mode: e.ctrlKey ? 'newTab' : 'existingOrNewTab'}); e.preventDefault(); }, false); -- cgit v1.2.3