avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
|
| 2 | // source code is governed by a BSD-style license that can be found in the
|
| 3 | // LICENSE file.
|
| 4 |
|
| 5 | var bg = chrome.extension.getBackgroundPage();
|
| 6 |
|
| 7 | function $(id) {
|
| 8 | return document.getElementById(id);
|
| 9 | }
|
| 10 |
|
| 11 | function isHighVersion() {
|
| 12 | var version = navigator.userAgent.match(/Chrome\/(\d+)/)[1];
|
| 13 | return version > 9;
|
| 14 | }
|
| 15 |
|
| 16 | function init() {
|
| 17 | i18nReplace('optionTitle', 'options');
|
| 18 | i18nReplace('saveAndClose', 'save_and_close');
|
| 19 | i18nReplace('screenshootQualitySetting', 'quality_setting');
|
| 20 | i18nReplace('lossyScreenShot', 'lossy');
|
| 21 | i18nReplace('losslessScreenShot', 'lossless');
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 22 | if (isHighVersion()) {
|
| 23 | $('lossyScreenShot').innerText += ' (JPEG)';
|
| 24 | $('losslessScreenShot').innerText += ' (PNG)';
|
| 25 | }
|
| 26 | $('saveAndClose').addEventListener('click', saveAndClose);
|
| 27 | initScreenCaptureQuality();
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 28 | }
|
| 29 |
|
| 30 | function save() {
|
| 31 | localStorage.screenshootQuality =
|
| 32 | $('lossy').checked ? 'jpeg' : '' ||
|
| 33 | $('lossless').checked ? 'png' : '';
|
| 34 |
|
avm99963 | 873bf6f | 2021-02-07 00:01:31 +0100 | [diff] [blame^] | 35 | return true;
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 36 | }
|
| 37 |
|
| 38 | function saveAndClose() {
|
| 39 | if (save())
|
| 40 | chrome.tabs.getSelected(null, function(tab) {
|
| 41 | chrome.tabs.remove(tab.id);
|
| 42 | });
|
| 43 | }
|
| 44 |
|
| 45 | function initScreenCaptureQuality() {
|
| 46 | $('lossy').checked = localStorage.screenshootQuality == 'jpeg';
|
| 47 | $('lossless').checked = localStorage.screenshootQuality == 'png';
|
| 48 | }
|
| 49 |
|
| 50 | function i18nReplace(id, name) {
|
| 51 | return $(id).innerText = chrome.i18n.getMessage(name);
|
| 52 | }
|
| 53 |
|
| 54 | const CURRENT_LOCALE = chrome.i18n.getMessage('@@ui_locale');
|
| 55 | if (CURRENT_LOCALE != 'zh_CN') {
|
| 56 | UI.addStyleSheet('./i18n_styles/en_options.css');
|
| 57 | }
|
| 58 |
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 59 | var ErrorInfo = (function() {
|
| 60 | return {
|
| 61 | show: function(msgKey) {
|
| 62 | var infoWrapper = $('error-info');
|
| 63 | var msg = chrome.i18n.getMessage(msgKey);
|
| 64 | infoWrapper.innerText = msg;
|
| 65 | UI.show(infoWrapper);
|
| 66 | },
|
| 67 |
|
| 68 | hide: function() {
|
| 69 | var infoWrapper = $('error-info');
|
| 70 | if (infoWrapper) {
|
| 71 | UI.hide(infoWrapper);
|
| 72 | }
|
| 73 | }
|
| 74 | };
|
| 75 | })();
|
| 76 |
|
| 77 | document.addEventListener('DOMContentLoaded', init);
|