diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/settings/clipboard-popups-controller.js | 26 | ||||
-rw-r--r-- | ext/bg/settings.html | 2 | ||||
-rw-r--r-- | ext/bg/settings2.html | 139 | ||||
-rw-r--r-- | ext/mixed/css/material.css | 1 | ||||
-rw-r--r-- | ext/mixed/img/clipboard.svg | 1 |
5 files changed, 101 insertions, 68 deletions
diff --git a/ext/bg/js/settings/clipboard-popups-controller.js b/ext/bg/js/settings/clipboard-popups-controller.js index fcff444c..ab1a8288 100644 --- a/ext/bg/js/settings/clipboard-popups-controller.js +++ b/ext/bg/js/settings/clipboard-popups-controller.js @@ -15,14 +15,22 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/* global + * ObjectPropertyAccessor + */ + class ClipboardPopupsController { constructor(settingsController) { this._settingsController = settingsController; - this._checkbox = document.querySelector('#clipboard-enable-background-monitor'); + this._toggles = null; } async prepare() { - this._checkbox.addEventListener('change', this._onEnableBackgroundMonitorChanged.bind(this), false); + this._toggles = document.querySelectorAll('.clipboard-toggle'); + + for (const toggle of this._toggles) { + toggle.addEventListener('change', this._onClipboardToggleChange.bind(this), false); + } this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); const options = await this._settingsController.getOptions(); @@ -32,10 +40,20 @@ class ClipboardPopupsController { // Private _onOptionsChanged({options}) { - this._checkbox.checked = options.clipboard.enableBackgroundMonitor; + const accessor = new ObjectPropertyAccessor(options); + for (const toggle of this._toggles) { + const path = ObjectPropertyAccessor.getPathArray(toggle.dataset.clipboardSetting); + let value; + try { + value = accessor.get(path, path.length); + } catch (e) { + continue; + } + toggle.checked = !!value; + } } - async _onEnableBackgroundMonitorChanged(e) { + async _onClipboardToggleChange(e) { const checkbox = e.currentTarget; let value = checkbox.checked; diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 208ac27c..e09a180e 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -162,7 +162,7 @@ </div> <div class="checkbox options-advanced ignore-form-changes" data-hide-for-browser="firefox-mobile"> - <label><input type="checkbox" id="clipboard-enable-background-monitor"> Enable native popups when copying Japanese text</label> + <label><input type="checkbox" class="clipboard-toggle" data-clipboard-setting="clipboard.enableBackgroundMonitor"> Enable native popups when copying Japanese text</label> </div> <div class="checkbox options-advanced"> diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html index c8c35c3d..fce4d9a4 100644 --- a/ext/bg/settings2.html +++ b/ext/bg/settings2.html @@ -34,6 +34,7 @@ <a href="#!sentence-parsing" class="outline-item advanced-only"><span class="outline-item-left"><span class="outline-item-icon icon" data-icon="sentence-parsing"></span></span><span class="outline-item-label">Sentence Parsing</span></a> <a href="#!translation" class="outline-item"><span class="outline-item-left"><span class="outline-item-icon icon" data-icon="translation"></span></span><span class="outline-item-label">Translation</span></a> <a href="#!anki" class="outline-item"><span class="outline-item-left"><span class="outline-item-icon icon" data-icon="note-card"></span></span><span class="outline-item-label">Anki</span></a> + <a href="#!clipboard" class="outline-item"><span class="outline-item-left"><span class="outline-item-icon icon" data-icon="clipboard"></span></span><span class="outline-item-label">Clipboard</span></a> <a href="#!shortcuts" class="outline-item"><span class="outline-item-left"><span class="outline-item-icon icon" data-icon="keyboard"></span></span><span class="outline-item-label">Shortcuts</span></a> <a href="#!backup" class="outline-item"><span class="outline-item-left"><span class="outline-item-icon icon" data-icon="backup"></span></span><span class="outline-item-label">Backup</span></a> <a href="#!security" class="outline-item advanced-only"><span class="outline-item-left"><span class="outline-item-icon icon" data-icon="lock"></span></span><span class="outline-item-label">Security</span></a> @@ -951,69 +952,6 @@ </p> </div> </div> - <div class="settings-item"> - <div class="settings-item-inner"> - <div class="settings-item-left"> - <div class="settings-item-label"> - Open a native browser window when copying Japanese text - <a class="more-toggle more-only" data-parent-distance="4">(?)</a> - </div> - </div> - <div class="settings-item-right"> - <label class="toggle"><input type="checkbox" id="clipboard-enable-background-monitor"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label> - </div> - </div> - <div class="settings-item-children more" hidden> - <p> - When Japanese text is copied to the clipboard, a browser window popup searching for the clipboard - text will be opened. - This can be useful for using Yomichan to scan text from external applications. - </p> - <p> - This feature requires Yomichan to have clipboard reading permissions, and when this option is enabled, - the clipboard will be frequently polled for new text. - </p> - <p> - Alternatively, this feature can be enabled only on the search page, and clipboard contents polling will - only be performed when the search page is already open. - </p> - <p> - <a class="more-toggle" data-parent-distance="3">Less…</a> - </p> - </div> - </div> - <div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable"> - <div class="settings-item-left"> - <div class="settings-item-label">Maximum clipboard text search length</div> - <div class="settings-item-description">Limit the number of text characters used when searching clipboard content.</div> - </div> - <div class="settings-item-right"> - <input type="number" min="0" step="1" data-setting="clipboard.maximumSearchLength"> - </div> - </div></div> - <div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable"> - <div class="settings-item-left"> - <div class="settings-item-label">Clipboard text search mode</div> - <div class="settings-item-description">Change how the search page reacts to new text in the clipboard.</div> - </div> - <div class="settings-item-right"> - <select data-setting="clipboard.autoSearchContent" - data-transform='[ - { - "step": "pre", - "type": "toBoolean" - }, - { - "step": "post", - "type": "toString" - } - ]' - > - <option value="true">Search for definitions</option> - <option value="false">Update search query only</option> - </select> - </div> - </div></div> <div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable"> <div class="settings-item-left"> <div class="settings-item-label">Size</div> @@ -1605,6 +1543,81 @@ </div></div> </div> + <!-- Clipboard --> + <div> + <div class="heading-container"> + <div class="heading-container-icon"><span class="icon" data-icon="clipboard"></span></div> + <div class="heading-container-left"><h2 id="clipboard"><a href="#!clipboard">Clipboard</a></h2></div> + <div class="heading-container-right"><a class="more-toggle more-only heading-link-light" data-parent-distance="3">Info…</a></div> + </div> + <div class="heading-description more" hidden> + <p> + Yomichan can watch the system copy clipboard for Japanese text and automatically search the + text on the search page. + This can be useful for using Yomichan to scan text from external applications. + </p> + <p> + This feature requires Yomichan to have clipboard reading permissions, and when this option is enabled, + the clipboard will be frequently checked for new text. + </p> + <p> + <a class="more-toggle" data-parent-distance="3">Less…</a> + </p> + </div> + </div> + <div class="settings-group"> + <div class="settings-item"><div class="settings-item-inner"> + <div class="settings-item-left"> + <div class="settings-item-label">Enable background clipboard text monitoring</div> + <div class="settings-item-description">Open the search page in a new window when the clipboard contains Japanese text.</div> + </div> + <div class="settings-item-right"> + <label class="toggle"><input type="checkbox" class="clipboard-toggle" data-clipboard-setting="clipboard.enableBackgroundMonitor"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label> + </div> + </div></div> + <div class="settings-item"><div class="settings-item-inner"> + <div class="settings-item-left"> + <div class="settings-item-label">Enable search page clipboard text monitoring</div> + <div class="settings-item-description">The query on the search page will be automatically updated with text in the clipboard.</div> + </div> + <div class="settings-item-right"> + <label class="toggle"><input type="checkbox" class="clipboard-toggle" data-clipboard-setting="clipboard.enableSearchPageMonitor"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label> + </div> + </div></div> + <div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable"> + <div class="settings-item-left"> + <div class="settings-item-label">Maximum clipboard text search length</div> + <div class="settings-item-description">Limit the number of characters used when searching clipboard text.</div> + </div> + <div class="settings-item-right"> + <input type="number" min="0" step="1" data-setting="clipboard.maximumSearchLength"> + </div> + </div></div> + <div class="settings-item"><div class="settings-item-inner settings-item-inner-wrappable"> + <div class="settings-item-left"> + <div class="settings-item-label">Clipboard text search mode</div> + <div class="settings-item-description">Change how the search page reacts to new text in the clipboard.</div> + </div> + <div class="settings-item-right"> + <select data-setting="clipboard.autoSearchContent" + data-transform='[ + { + "step": "pre", + "type": "toBoolean" + }, + { + "step": "post", + "type": "toString" + } + ]' + > + <option value="true">Search for definitions</option> + <option value="false">Update query only</option> + </select> + </div> + </div></div> + </div> + <!-- Shortcuts --> <div class="heading-container"> <div class="heading-container-icon"><span class="icon" data-icon="keyboard"></span></div> diff --git a/ext/mixed/css/material.css b/ext/mixed/css/material.css index d144937b..2dd10791 100644 --- a/ext/mixed/css/material.css +++ b/ext/mixed/css/material.css @@ -214,6 +214,7 @@ .icon[data-icon=left-chevron] { --icon-image: url(/mixed/img/left-chevron.svg); } .icon[data-icon=right-chevron] { --icon-image: url(/mixed/img/right-chevron.svg); } .icon[data-icon=plus-thick] { --icon-image: url(/mixed/img/plus-thick.svg); } +.icon[data-icon=clipboard] { --icon-image: url(/mixed/img/clipboard.svg); } .icon[data-icon=material-down-arrow] { --icon-image: url(/mixed/img/material-down-arrow.svg); --icon-size: var(--material-arrow-dimension2) var(--material-arrow-dimension1); diff --git a/ext/mixed/img/clipboard.svg b/ext/mixed/img/clipboard.svg new file mode 100644 index 00000000..75545134 --- /dev/null +++ b/ext/mixed/img/clipboard.svg @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M8 .5c-.41421 0-.75.33579-.75.75 0 .25-.25.25-.75.25-.554 0-1 .446-1 1V3h5v-.5c0-.554-.446-1-1-1-.5 0-.75 0-.75-.25C8.75.83579 8.41421.5 8 .5zM2.5 2v13h11V2h-2.5938c.05663.15724.09375.32437.09375.5V3h1.5v11h-9V3h1.5v-.5c0-.17563.03712-.34276.09375-.5zm2 3v1h7V5zm0 2v1h7V7zm0 2v1h7V9zm0 2v1h5v-1z"/></svg>
\ No newline at end of file |