blob: f56bc7a8b2df4ff3c8e4fba8abdd514f5287a57f [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
avm999638044b402021-02-07 14:24:12 +010030function save(callback) {
31 var screenshotQuality = $('lossy').checked ? 'jpeg' : '' ||
32 $('lossless').checked ? 'png' : '';
avm99963476a2a62021-02-07 00:40:02 +010033 chrome.storage.local.set({
avm999638044b402021-02-07 14:24:12 +010034 screenshotQuality,
35 }, _ => {
36 callback(true);
avm99963476a2a62021-02-07 00:40:02 +010037 });
avm9996304def3e2016-11-27 22:53:05 +010038}
39
40function saveAndClose() {
avm999638044b402021-02-07 14:24:12 +010041 save(_ => {
avm9996304def3e2016-11-27 22:53:05 +010042 chrome.tabs.getSelected(null, function(tab) {
43 chrome.tabs.remove(tab.id);
44 });
avm999638044b402021-02-07 14:24:12 +010045 });
avm9996304def3e2016-11-27 22:53:05 +010046}
47
48function initScreenCaptureQuality() {
avm99963476a2a62021-02-07 00:40:02 +010049 chrome.storage.local.get('screenshotQuality', value => {
avm999638044b402021-02-07 14:24:12 +010050 $('lossy').checked = value['screenshotQuality'] == 'jpeg';
51 $('lossless').checked = value['screenshotQuality'] == 'png';
avm99963476a2a62021-02-07 00:40:02 +010052 });
avm9996304def3e2016-11-27 22:53:05 +010053}
54
55function i18nReplace(id, name) {
56 return $(id).innerText = chrome.i18n.getMessage(name);
57}
58
59const CURRENT_LOCALE = chrome.i18n.getMessage('@@ui_locale');
60if (CURRENT_LOCALE != 'zh_CN') {
61 UI.addStyleSheet('./i18n_styles/en_options.css');
62}
63
avm9996304def3e2016-11-27 22:53:05 +010064var ErrorInfo = (function() {
65 return {
66 show: function(msgKey) {
67 var infoWrapper = $('error-info');
68 var msg = chrome.i18n.getMessage(msgKey);
69 infoWrapper.innerText = msg;
70 UI.show(infoWrapper);
71 },
72
73 hide: function() {
74 var infoWrapper = $('error-info');
75 if (infoWrapper) {
76 UI.hide(infoWrapper);
77 }
78 }
79 };
80})();
81
82document.addEventListener('DOMContentLoaded', init);