<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1" />
        <title>Yomichan Options</title>
        <link rel="stylesheet" type="text/css" href="/mixed/lib/bootstrap/css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="/mixed/lib/bootstrap/css/bootstrap-theme.min.css">
        <link rel="stylesheet" type="text/css" href="/bg/css/settings.css">
    </head>
    <body>
        <div class="container">
            <div class="page-header">
                <h1>Yomichan Options</h1>
            </div>

            <div class="profile-form">
                <h3>Profiles</h3>

                <p class="help-block">
                    Profiles allow you to create multiple configurations and quickly switch between them or use them in different contexts.
                </p>

                <div class="form-group">
                    <label for="profile-active">Active profile</label>
                    <select class="form-control" id="profile-active"></select>
                </div>

                <div class="form-group">
                    <label for="profile-target">Modifying profile</label>
                    <div class="input-group">
                        <div class="input-group-btn">
                            <button class="btn btn-default" id="profile-add" title="Add"><span class="glyphicon glyphicon-plus"></span></button>
                            <button class="btn btn-default" id="profile-move-up" title="Move up"><span class="glyphicon glyphicon-arrow-up"></span></button>
                            <button class="btn btn-default" id="profile-move-down" title="Move down"><span class="glyphicon glyphicon-arrow-down"></span></button>
                            <button class="btn btn-default" id="profile-copy" title="Copy"><span class="glyphicon glyphicon-copy"></span></button>
                        </div>
                        <select class="form-control profile-form-manual" id="profile-target"></select>
                        <div class="input-group-btn">
                            <button class="btn btn-danger" id="profile-remove" title="Remove"><span class="glyphicon glyphicon-remove"></span></button>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label for="profile-name">Profile name</label>
                    <input type="text" id="profile-name" class="form-control">
                </div>

                <div class="form-group">
                    <label>Usage conditions</label>

                    <p class="help-block">
                        Usage conditions can be assigned such that certain profiles are automatically used in different contexts.
                        For example, when <a href="#popup-content-scanning">Popup Content Scanning</a> is enabled, different profiles can be used
                        depending on the level of the popup.
                    </p>

                    <p class="help-block">
                        Conditions are organized into groups which represent how the conditions are checked.
                        If all of the conditions in any group are met, then the profile will automatically be used for that context.
                        If no conditions are specified, the profile will only be used if it is selected as the <strong>Active profile</strong>.
                    </p>

                    <div class="condition-groups" id="profile-condition-groups"></div>
                </div>
                <div class="form-group">
                    <button class="btn btn-default" id="profile-add-condition-group">Add Condition Group</button>
                </div>

                <div class="modal fade" tabindex="-1" role="dialog" id="profile-copy-modal">
                    <div class="modal-dialog modal-dialog-centered">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title">Copy Profile</h4>
                            </div>
                            <div class="modal-body">
                                <p>Select which profile to copy options from:</p>
                                <select class="form-control" id="profile-copy-source"></select>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                                <button type="button" class="btn btn-primary" id="profile-copy-confirm">Copy Profile</button>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="modal fade" tabindex="-1" role="dialog" id="profile-remove-modal">
                    <div class="modal-dialog modal-dialog-centered">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title">Confirm profile removal</h4>
                            </div>
                            <div class="modal-body">
                                Are you sure you want to delete the profile <em id="profile-remove-modal-profile-name"></em>?
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                                <button type="button" class="btn btn-danger" id="profile-remove-confirm">Remove Profile</button>
                            </div>
                        </div>
                    </div>
                </div>

                <template id="condition-template"><div class="input-group condition">
                    <div class="input-group-addon condition-prefix"></div>
                    <div class="input-group-btn"><select class="form-control btn btn-default condition-type"><optgroup label="Type"></optgroup></select></div>
                    <div class="input-group-btn"><select class="form-control btn btn-default condition-operator"><optgroup label="Operator"></optgroup></select></div>
                    <div class="condition-line-break"></div>
                    <div class="condition-input"><input type="text" class="form-control" /></div>
                    <div class="input-group-btn"><button class="btn btn-danger condition-remove" title="Remove"><span class="glyphicon glyphicon-remove"></span></button></div>
                </div></template>
                <template id="condition-group-separator-template"><div class="input-group">
                    <div class="condition-group-separator-label">OR</div>
                </div></template>
                <template id="condition-group-options-template"><div class="condition-group-options">
                    <button class="btn btn-default condition-add"><span class="glyphicon glyphicon-plus"></span></button>
                </div></template>
            </div>

            <div>
                <h3>General Options</h3>

                <div class="checkbox">
                    <label><input type="checkbox" id="enable"> Enable content scanning</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="show-usage-guide"> Show usage guide on startup</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="compact-tags"> Compact tags</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="compact-glossaries"> Compact glossaries</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="auto-play-audio"> Play audio automatically</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="show-advanced-options"> Show advanced options</label>
                </div>

                <div class="checkbox options-advanced">
                    <label><input type="checkbox" id="show-debug-info"> Show debug information</label>
                </div>

                <div class="form-group">
                    <label for="result-output-mode">Result grouping</label>
                    <select class="form-control" id="result-output-mode">
                        <option value="group">Group results by term-reading pairs</option>
                        <option value="merge">Group results by main dictionary entry</option>
                        <option value="split">Split definitions to their own results</option>
                    </select>
                </div>

                <div class="form-group">
                    <label for="audio-playback-source">Audio playback source</label>
                    <select class="form-control" id="audio-playback-source">
                        <option value="disabled">Disabled</option>
                        <option value="jpod101">JapanesePod101</option>
                        <option value="jpod101-alternate">JapanesePod101 (alternate)</option>
                        <option value="jisho">Jisho.org</option>
                    </select>
                </div>

                <div class="form-group">
                    <label for="popup-display-mode">Popup display mode</label>
                    <select class="form-control" id="popup-display-mode">
                        <option value="default">Default</option>
                        <option value="full-width">Full width</option>
                    </select>
                </div>

                <div class="form-group options-advanced">
                    <label for="audio-playback-volume">Audio playback volume <span class="label-light">(percent)</span></label>
                    <input type="number" min="0" max="100" id="audio-playback-volume" class="form-control">
                </div>

                <div class="form-group options-advanced">
                    <label for="max-displayed-results">Maximum displayed results</label>
                    <input type="number" min="1" id="max-displayed-results" class="form-control">
                </div>

                <div class="form-group">
                    <div class="row">
                        <div class="col-xs-6">
                            <label for="popup-horizontal-text-position">Popup position for horizontal text</label>
                            <select class="form-control" id="popup-horizontal-text-position">
                                <option value="below">Below text</option>
                                <option value="above">Above text</option>
                            </select>
                        </div>
                        <div class="col-xs-6">
                            <label for="popup-vertical-text-position">Popup position for vertical text</label>
                            <select class="form-control" id="popup-vertical-text-position">
                                <option value="default">Same as for horizontal text</option>
                                <option value="before">Before text reading direction</option>
                                <option value="after">After text reading direction</option>
                                <option value="left">Left of text</option>
                                <option value="right">Right of text</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="form-group options-advanced">
                    <div class="row">
                        <div class="col-xs-6">
                            <label for="popup-width">Popup width <span class="label-light">(in pixels)</span></label>
                            <input type="number" min="1" id="popup-width" class="form-control">
                        </div>
                        <div class="col-xs-6">
                            <label for="popup-height">Popup height <span class="label-light">(in pixels)</span></label>
                            <input type="number" min="1" id="popup-height" class="form-control">
                        </div>
                    </div>
                </div>

                <div class="form-group options-advanced">
                    <div class="row">
                        <div class="col-xs-6">
                            <label for="popup-horizontal-offset">Horizontal popup offset <span class="label-light">(in pixels)</span></label>
                            <input type="number" min="0" id="popup-horizontal-offset" class="form-control">
                        </div>
                        <div class="col-xs-6">
                            <label for="popup-vertical-offset">Vertical popup offset <span class="label-light">(in pixels)</span></label>
                            <input type="number" min="0" id="popup-vertical-offset" class="form-control">
                        </div>
                    </div>
                </div>

                <div class="form-group options-advanced">
                    <div class="row">
                        <div class="col-xs-6">
                            <label for="popup-horizontal-offset2">Horizontal popup offset for vertical text <span class="label-light">(in pixels)</span></label>
                            <input type="number" min="0" id="popup-horizontal-offset2" class="form-control">
                        </div>
                        <div class="col-xs-6">
                            <label for="popup-vertical-offset2">Vertical popup offset for vertical text <span class="label-light">(in pixels)</span></label>
                            <input type="number" min="0" id="popup-vertical-offset2" class="form-control">
                        </div>
                    </div>
                </div>

                <div class="form-group options-advanced">
                    <label for="custom-popup-css">Custom popup CSS</label>
                    <div><textarea autocomplete="off" spellcheck="false" wrap="soft" id="custom-popup-css" class="form-control"></textarea></div>
                </div>
            </div>

            <div>
                <h3>Scanning Options</h3>

                <div class="checkbox">
                    <label><input type="checkbox" id="middle-mouse-button-scan"> Middle mouse button scans</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="touch-input-enabled"> Touch input enabled</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="select-matched-text"> Select matched text</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="search-alphanumeric"> Search alphanumeric text</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="auto-hide-results"> Automatically hide results</label>
                </div>

                <div class="checkbox options-advanced">
                    <label><input type="checkbox" id="deep-dom-scan"> Deep DOM scan</label>
                </div>

                <div class="form-group options-advanced">
                    <label for="scan-delay">Scan delay <span class="label-light">(in milliseconds)</span></label>
                    <input type="number" min="1" id="scan-delay" class="form-control">
                </div>

                <div class="form-group options-advanced">
                    <label for="scan-length">Scan length <span class="label-light">(in characters)</span></label>
                    <input type="number" min="1" id="scan-length" class="form-control">
                </div>

                <div class="form-group">
                    <label for="scan-modifier-key">Scan modifier key</label>
                    <select class="form-control" id="scan-modifier-key">
                        <option value="none">None</option>
                        <option value="alt">Alt</option>
                        <option value="ctrl">Ctrl</option>
                        <option value="shift">Shift</option>
                    </select>
                </div>
            </div>

            <div id="popup-content-scanning">
                <h3>Popup Content Scanning Options</h3>

                <p class="help-block">
                    Yomichan is able to create additional popups in order to scan the content of other popups.
                    This feature can be enabled if the <strong>Maximum number of additional popups</strong> option is set to a value greater than 0.
                </p>

                <div class="checkbox">
                    <label><input type="checkbox" id="enable-search-within-first-popup"> Enable search when clicking glossary entries</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="enable-scanning-on-search-page"> Enable scanning on search page</label>
                </div>

                <div class="checkbox">
                    <label><input type="checkbox" id="enable-scanning-of-popup-expressions"> Enable scanning of popup expressions</label>
                </div>

                <div class="form-group">
                    <label for="popup-nesting-max-depth">Maximum number of additional popups</label>
                    <input type="number" min="0" id="popup-nesting-max-depth" class="form-control">
                </div>
            </div>

            <div>
                <div>
                    <img src="/mixed/img/spinner.gif" class="pull-right" id="dict-spinner" alt>
                    <h3>Dictionaries</h3>
                </div>

                <p class="help-block">
                    Yomichan can import and use a variety of dictionary formats. Unneeded dictionaries can be disabled,
                    or you can simply <a href="#" id="dict-purge-link">purge the database</a> to delete everything.
                </p>
                <p class="help-block">
                    Deleting individual dictionaries is not currently feasible due to limitations of browser database technology.
                </p>

                <div class="form-group" id="dict-main-group">
                    <label for="dict-main">Main dictionary for merged mode</label>
                    <select class="form-control" id="dict-main"></select>
                </div>

                <div class="text-danger" id="dict-purge">Dictionary data is being purged, please be patient...</div>
                <div class="alert alert-warning" id="dict-warning">No dictionaries have been installed</div>
                <div class="alert alert-danger" id="dict-error"></div>

                <div id="dict-groups"></div>

                <div id="dict-import-progress">
                    Dictionary data is being imported, please be patient...
                    <div class="progress">
                        <div class="progress-bar progress-bar-striped" style="width: 0%"></div>
                    </div>
                </div>

                <div id="dict-importer">
                    <p class="help-block">
                        Select a dictionary to import for use below. Please visit the Yomichan homepage to
                        <a href="https://foosoft.net/projects/yomichan" target="_blank" rel="noopener">download free dictionaries</a>
                        for use with this extension and to learn about importing proprietary EPWING dictionaries.
                    </p>
                    <button class="btn btn-primary" id="dict-file-button">Import Dictionary</button>
                    <div hidden><input type="file" id="dict-file"></div>
                </div>
            </div>

            <div id="storage-info" class="storage-hidden">
                <div>
                    <img src="/mixed/img/spinner.gif" class="pull-right" id="storage-spinner" />
                    <h3>Storage</h3>
                </div>

                <div id="storage-use" class="storage-hidden">
                    <p class="help-block">
                        Yomichan is using approximately <strong id="storage-usage"></strong> of <strong id="storage-quota"></strong>.
                    </p>
                </div>

                <div id="storage-error" class="storage-hidden">
                    <p class="help-block">
                        Could not detect how much storage Yomichan is using.
                    </p>
                    <div data-show-for-browser="firefox firefox-mobile"><div class="alert alert-danger options-advanced">
                        On Firefox and Firefox for Android, the storage information feature may be hidden behind a browser flag.

                        If you would like to enable this flag, open <a href="about:config" target="_blank" rel="noopener">about:config</a> and search for the
                        <strong>dom.storageManager.enabled</strong> option. If this option has a value of <strong>false</strong>, toggling it to
                        <strong>true</strong> may allow storage information to be calculated.
                    </div></div>
                </div>

                <div data-show-for-browser="firefox-mobile"><div class="alert alert-warning">
                    If you are using Firefox for Android, you will have to make sure you have enough free space on your device to install dictionaries.
                </div></div>

                <div>
                    <button class="btn btn-default" id="storage-refresh">Refresh</button>
                </div>
            </div>

            <div>
                <div>
                    <img src="/mixed/img/spinner.gif" class="pull-right" id="anki-spinner" alt>
                    <h3>Anki Options</h3>
                </div>

                <p class="help-block">
                    Yomichan supports automatic flashcard creation for <a href="https://apps.ankiweb.net/" target="_blank" rel="noopener">Anki</a>, a free application
                    designed to help you remember. This feature requires installation of the
                    <a href="https://foosoft.net/projects/anki-connect/" target="_blank" rel="noopener">AnkiConnect</a> plugin.
                </p>

                <div class="alert alert-danger" id="anki-error"></div>

                <div class="checkbox">
                    <label><input type="checkbox" id="anki-enable"> Enable Anki integration</label>
                </div>

                <div id="anki-general">
                    <div class="form-group">
                        <label for="card-tags">Card tags <span class="label-light">(comma or space separated)</span></label>
                        <input type="text" id="card-tags" class="form-control">
                    </div>

                    <div class="form-group options-advanced">
                        <label for="sentence-detection-extent">Sentence detection extent <span class="label-light">(in characters)</span></label>
                        <input type="number" min="1" id="sentence-detection-extent" class="form-control">
                    </div>

                    <div class="form-group options-advanced">
                        <label for="interface-server">Interface server</label>
                        <input type="text" id="interface-server" class="form-control">
                    </div>

                    <div class="form-group options-advanced">
                        <label for="screenshot-format">Screenshot format</label>
                        <select class="form-control" id="screenshot-format">
                            <option value="png">PNG</option>
                            <option value="jpeg">JPEG</option>
                        </select>
                    </div>

                    <div class="form-group options-advanced">
                        <label for="screenshot-quality">Screenshot quality <span class="label-light">(JPEG only)</span></label>
                        <input type="number" min="0" max="100" step="1" id="screenshot-quality" class="form-control">
                    </div>

                    <div id="anki-format">
                        <p class="help-block">
                            Specify the information you would like included in your flashcards in the field editor below.
                            As Anki requires the first field in the model to be unique, it is recommended
                            that you set it to <code>{expression}</code> for term flashcards and <code>{character}</code> for
                            Kanji flashcards. You can use multiple markers per field by typing them in directly.
                        </p>

                        <ul class="nav nav-tabs">
                            <li class="active"><a href="#terms" data-toggle="tab">Terms</a></li>
                            <li><a href="#kanji" data-toggle="tab">Kanji</a></li>
                        </ul>

                        <div class="tab-content">
                            <div id="terms" class="tab-pane fade in active">
                                <div class="row">
                                    <div class="form-group col-xs-6">
                                        <label for="anki-terms-deck">Deck</label>
                                        <select class="form-control anki-deck" id="anki-terms-deck"></select>
                                    </div>

                                    <div class="form-group col-xs-6">
                                        <label for="anki-terms-model">Model</label>
                                        <select class="form-control anki-model" id="anki-terms-model"></select>
                                    </div>
                                </div>

                                <table class="table table-bordered anki-fields">
                                    <thead><tr><th>Field</th><th>Value</th></tr></thead>
                                    <tbody></tbody>
                                </table>
                            </div>

                            <div id="kanji" class="tab-pane fade">
                                <div class="row">
                                    <div class="form-group col-xs-6">
                                        <label for="anki-kanji-deck">Deck</label>
                                        <select class="form-control anki-deck" id="anki-kanji-deck"></select>
                                    </div>

                                    <div class="form-group col-xs-6">
                                        <label for="anki-kanji-model">Model</label>
                                        <select class="form-control anki-model" id="anki-kanji-model"></select>
                                    </div>
                                </div>

                                <table class="table table-bordered anki-fields">
                                    <thead><tr><th>Field</th><th>Value</th></tr></thead>
                                    <tbody></tbody>
                                </table>
                            </div>
                        </div>

                        <div class="options-advanced">
                            <p class="help-block">
                                Fields are formatted using the <a href="https://handlebarsjs.com/" target="_blank" rel="noopener">Handlebars.js</a> template rendering
                                engine. Advanced users can modify these templates for ultimate control of what information gets included in
                                their Anki cards. If you encounter problems with your changes you can always <a href="#" id="field-templates-reset">reset to default</a>
                                template settings.
                            </p>
                            <textarea autocomplete="off" spellcheck="false" wrap="soft" class="form-control" rows="10" id="field-templates"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div>
                <h3>Keyboard Shortcuts</h3>

                <p class="help-block">
                    Yomichan includes keyboard shortcuts for common actions which can be adjusted
                    using the web browser's settings.
                    Instructions on how to access this settings page are listed below for a few browsers.
                </p>

                <h4>Chrome</h4>
                <ul class="help-block">
                    <li>Open the settings page (<a href="chrome://settings/">chrome://settings/</a>)</li>
                    <li>Click the "Extensions" link in the left sidebar (<a href="chrome://extensions/">chrome://extensions/</a>)</li>
                    <li>Open the left side panel using the hamburger (<strong>&#8801;</strong>) menu button, then click "Keyboard shortcuts"</li>
                </ul>

                <h4>Firefox</h4>
                <ul class="help-block">
                    <li>Open the extensions page (<a href="about:addons">about:addons</a>)</li>
                    <li>Click the button on the right with the gear icon, then click "Manage Extension Shortcuts"</li>
                </ul>
            </div>

            <div>
                <h3>Support Development</h3>

                <p class="help-block">
                    Yomichan is provided to you <em>completely free</em> of charge. Unlike numerous other "free" services, you are not
                    shown ads, pestered with "offers", or have your browser usage information analyzed and sold to third parties.
                </p>
                <p class="help-block">
                    If you find Yomichan useful, please consider making a small donation as a way to show your appreciation for the
                    countless hours that I have devoted to this extension.
                </p>
                <p>
                    <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4DBTN9A3CUAFN" target="_blank" rel="noopener"><img src="/bg/img/paypal.gif" alt></a>
                </p>
            </div>

            <pre id="debug"></pre>

            <div class="pull-right bottom-links">
                <small><span id="extension-info"></span> &bull; <a href="search.html">Search</a> &bull; <a href="https://foosoft.net/projects/yomichan/" target="_blank" rel="noopener">Homepage</a> &bull; <a href="legal.html">Legal</a></small>
            </div>
        </div>

        <script src="/mixed/lib/jquery.min.js"></script>
        <script src="/mixed/lib/bootstrap/js/bootstrap.min.js"></script>
        <script src="/mixed/lib/handlebars.min.js"></script>

        <script src="/mixed/js/extension.js"></script>

        <script src="/bg/js/anki.js"></script>
        <script src="/bg/js/api.js"></script>
        <script src="/bg/js/conditions.js"></script>
        <script src="/bg/js/conditions-ui.js"></script>
        <script src="/bg/js/dictionary.js"></script>
        <script src="/bg/js/handlebars.js"></script>
        <script src="/bg/js/options.js"></script>
        <script src="/bg/js/profile-conditions.js"></script>
        <script src="/bg/js/templates.js"></script>
        <script src="/bg/js/util.js"></script>

        <script src="/bg/js/settings-profiles.js"></script>
        <script src="/bg/js/settings.js"></script>
    </body>
</html>