blob: bbbce706be0b657da986c7126ab1037f8ba88e39 [file] [log] [blame]
avm9996304def3e2016-11-27 22:53:05 +01001// 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
5var bg = chrome.extension.getBackgroundPage();
6
7function $(id) {
8 return document.getElementById(id);
9}
10
11function isHighVersion() {
12 var version = navigator.userAgent.match(/Chrome\/(\d+)/)[1];
13 return version > 9;
14}
15
16function init() {
17 i18nReplace('optionTitle', 'options');
18 i18nReplace('saveAndClose', 'save_and_close');
19 i18nReplace('screenshootQualitySetting', 'quality_setting');
20 i18nReplace('lossyScreenShot', 'lossy');
21 i18nReplace('losslessScreenShot', 'lossless');
avm9996304def3e2016-11-27 22:53:05 +010022 if (isHighVersion()) {
23 $('lossyScreenShot').innerText += ' (JPEG)';
24 $('losslessScreenShot').innerText += ' (PNG)';
25 }
26 $('saveAndClose').addEventListener('click', saveAndClose);
27 initScreenCaptureQuality();
avm9996304def3e2016-11-27 22:53:05 +010028}
29
30function save() {
31 localStorage.screenshootQuality =
32 $('lossy').checked ? 'jpeg' : '' ||
33 $('lossless').checked ? 'png' : '';
34
avm99963873bf6f2021-02-07 00:01:31 +010035 return true;
avm9996304def3e2016-11-27 22:53:05 +010036}
37
38function saveAndClose() {
39 if (save())
40 chrome.tabs.getSelected(null, function(tab) {
41 chrome.tabs.remove(tab.id);
42 });
43}
44
45function initScreenCaptureQuality() {
46 $('lossy').checked = localStorage.screenshootQuality == 'jpeg';
47 $('lossless').checked = localStorage.screenshootQuality == 'png';
48}
49
50function i18nReplace(id, name) {
51 return $(id).innerText = chrome.i18n.getMessage(name);
52}
53
54const CURRENT_LOCALE = chrome.i18n.getMessage('@@ui_locale');
55if (CURRENT_LOCALE != 'zh_CN') {
56 UI.addStyleSheet('./i18n_styles/en_options.css');
57}
58
avm9996304def3e2016-11-27 22:53:05 +010059var 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
77document.addEventListener('DOMContentLoaded', init);