blob: bbbce706be0b657da986c7126ab1037f8ba88e39 [file] [log] [blame]
// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
var bg = chrome.extension.getBackgroundPage();
function $(id) {
return document.getElementById(id);
}
function isHighVersion() {
var version = navigator.userAgent.match(/Chrome\/(\d+)/)[1];
return version > 9;
}
function init() {
i18nReplace('optionTitle', 'options');
i18nReplace('saveAndClose', 'save_and_close');
i18nReplace('screenshootQualitySetting', 'quality_setting');
i18nReplace('lossyScreenShot', 'lossy');
i18nReplace('losslessScreenShot', 'lossless');
if (isHighVersion()) {
$('lossyScreenShot').innerText += ' (JPEG)';
$('losslessScreenShot').innerText += ' (PNG)';
}
$('saveAndClose').addEventListener('click', saveAndClose);
initScreenCaptureQuality();
}
function save() {
localStorage.screenshootQuality =
$('lossy').checked ? 'jpeg' : '' ||
$('lossless').checked ? 'png' : '';
return true;
}
function saveAndClose() {
if (save())
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.remove(tab.id);
});
}
function initScreenCaptureQuality() {
$('lossy').checked = localStorage.screenshootQuality == 'jpeg';
$('lossless').checked = localStorage.screenshootQuality == 'png';
}
function i18nReplace(id, name) {
return $(id).innerText = chrome.i18n.getMessage(name);
}
const CURRENT_LOCALE = chrome.i18n.getMessage('@@ui_locale');
if (CURRENT_LOCALE != 'zh_CN') {
UI.addStyleSheet('./i18n_styles/en_options.css');
}
var ErrorInfo = (function() {
return {
show: function(msgKey) {
var infoWrapper = $('error-info');
var msg = chrome.i18n.getMessage(msgKey);
infoWrapper.innerText = msg;
UI.show(infoWrapper);
},
hide: function() {
var infoWrapper = $('error-info');
if (infoWrapper) {
UI.hide(infoWrapper);
}
}
};
})();
document.addEventListener('DOMContentLoaded', init);