blob: abb2efc5bdbadbd0bc94f49e1c097947ecb537b2 [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() {
avm99963476a2a62021-02-07 00:40:02 +010031 chrome.storage.local.set({
32 'screenshootQuality':
avm9996304def3e2016-11-27 22:53:05 +010033 $('lossy').checked ? 'jpeg' : '' ||
avm99963476a2a62021-02-07 00:40:02 +010034 $('lossless').checked ? 'png' : '',
35 });
avm9996304def3e2016-11-27 22:53:05 +010036
avm99963873bf6f2021-02-07 00:01:31 +010037 return true;
avm9996304def3e2016-11-27 22:53:05 +010038}
39
40function saveAndClose() {
41 if (save())
42 chrome.tabs.getSelected(null, function(tab) {
43 chrome.tabs.remove(tab.id);
44 });
45}
46
47function initScreenCaptureQuality() {
avm99963476a2a62021-02-07 00:40:02 +010048 chrome.storage.local.get('screenshotQuality', value => {
49 $('lossy').checked = value == 'jpeg';
50 $('lossless').checked = value == 'png';
51 });
avm9996304def3e2016-11-27 22:53:05 +010052}
53
54function i18nReplace(id, name) {
55 return $(id).innerText = chrome.i18n.getMessage(name);
56}
57
58const CURRENT_LOCALE = chrome.i18n.getMessage('@@ui_locale');
59if (CURRENT_LOCALE != 'zh_CN') {
60 UI.addStyleSheet('./i18n_styles/en_options.css');
61}
62
avm9996304def3e2016-11-27 22:53:05 +010063var ErrorInfo = (function() {
64 return {
65 show: function(msgKey) {
66 var infoWrapper = $('error-info');
67 var msg = chrome.i18n.getMessage(msgKey);
68 infoWrapper.innerText = msg;
69 UI.show(infoWrapper);
70 },
71
72 hide: function() {
73 var infoWrapper = $('error-info');
74 if (infoWrapper) {
75 UI.hide(infoWrapper);
76 }
77 }
78 };
79})();
80
81document.addEventListener('DOMContentLoaded', init);