blob: 7a276ae57e0062061a54b85b81d81c198833901d [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
avm9996304def3e2016-11-27 22:53:05 +01005function $(id) {
6 return document.getElementById(id);
7}
8
9function isHighVersion() {
10 var version = navigator.userAgent.match(/Chrome\/(\d+)/)[1];
11 return version > 9;
12}
13
14function init() {
15 i18nReplace('optionTitle', 'options');
16 i18nReplace('saveAndClose', 'save_and_close');
17 i18nReplace('screenshootQualitySetting', 'quality_setting');
18 i18nReplace('lossyScreenShot', 'lossy');
19 i18nReplace('losslessScreenShot', 'lossless');
avm9996304def3e2016-11-27 22:53:05 +010020 if (isHighVersion()) {
21 $('lossyScreenShot').innerText += ' (JPEG)';
22 $('losslessScreenShot').innerText += ' (PNG)';
23 }
24 $('saveAndClose').addEventListener('click', saveAndClose);
25 initScreenCaptureQuality();
avm9996304def3e2016-11-27 22:53:05 +010026}
27
avm999638044b402021-02-07 14:24:12 +010028function save(callback) {
29 var screenshotQuality = $('lossy').checked ? 'jpeg' : '' ||
30 $('lossless').checked ? 'png' : '';
avm99963476a2a62021-02-07 00:40:02 +010031 chrome.storage.local.set({
avm999638044b402021-02-07 14:24:12 +010032 screenshotQuality,
33 }, _ => {
34 callback(true);
avm99963476a2a62021-02-07 00:40:02 +010035 });
avm9996304def3e2016-11-27 22:53:05 +010036}
37
38function saveAndClose() {
avm999638044b402021-02-07 14:24:12 +010039 save(_ => {
avm9996304def3e2016-11-27 22:53:05 +010040 chrome.tabs.getSelected(null, function(tab) {
41 chrome.tabs.remove(tab.id);
42 });
avm999638044b402021-02-07 14:24:12 +010043 });
avm9996304def3e2016-11-27 22:53:05 +010044}
45
46function initScreenCaptureQuality() {
avm99963476a2a62021-02-07 00:40:02 +010047 chrome.storage.local.get('screenshotQuality', value => {
avm999638044b402021-02-07 14:24:12 +010048 $('lossy').checked = value['screenshotQuality'] == 'jpeg';
49 $('lossless').checked = value['screenshotQuality'] == 'png';
avm99963476a2a62021-02-07 00:40:02 +010050 });
avm9996304def3e2016-11-27 22:53:05 +010051}
52
53function i18nReplace(id, name) {
54 return $(id).innerText = chrome.i18n.getMessage(name);
55}
56
57const CURRENT_LOCALE = chrome.i18n.getMessage('@@ui_locale');
58if (CURRENT_LOCALE != 'zh_CN') {
59 UI.addStyleSheet('./i18n_styles/en_options.css');
60}
61
avm9996304def3e2016-11-27 22:53:05 +010062var ErrorInfo = (function() {
63 return {
64 show: function(msgKey) {
65 var infoWrapper = $('error-info');
66 var msg = chrome.i18n.getMessage(msgKey);
67 infoWrapper.innerText = msg;
68 UI.show(infoWrapper);
69 },
70
71 hide: function() {
72 var infoWrapper = $('error-info');
73 if (infoWrapper) {
74 UI.hide(infoWrapper);
75 }
76 }
77 };
78})();
79
80document.addEventListener('DOMContentLoaded', init);