avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 1 | // 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 |
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 5 | function $(id) {
|
| 6 | return document.getElementById(id);
|
| 7 | }
|
| 8 |
|
| 9 | function isHighVersion() {
|
| 10 | var version = navigator.userAgent.match(/Chrome\/(\d+)/)[1];
|
| 11 | return version > 9;
|
| 12 | }
|
| 13 |
|
| 14 | function init() {
|
| 15 | i18nReplace('optionTitle', 'options');
|
| 16 | i18nReplace('saveAndClose', 'save_and_close');
|
| 17 | i18nReplace('screenshootQualitySetting', 'quality_setting');
|
| 18 | i18nReplace('lossyScreenShot', 'lossy');
|
| 19 | i18nReplace('losslessScreenShot', 'lossless');
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 20 | if (isHighVersion()) {
|
| 21 | $('lossyScreenShot').innerText += ' (JPEG)';
|
| 22 | $('losslessScreenShot').innerText += ' (PNG)';
|
| 23 | }
|
| 24 | $('saveAndClose').addEventListener('click', saveAndClose);
|
| 25 | initScreenCaptureQuality();
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 26 | }
|
| 27 |
|
avm99963 | 8044b40 | 2021-02-07 14:24:12 +0100 | [diff] [blame] | 28 | function save(callback) {
|
| 29 | var screenshotQuality = $('lossy').checked ? 'jpeg' : '' ||
|
| 30 | $('lossless').checked ? 'png' : '';
|
avm99963 | 476a2a6 | 2021-02-07 00:40:02 +0100 | [diff] [blame] | 31 | chrome.storage.local.set({
|
avm99963 | 8044b40 | 2021-02-07 14:24:12 +0100 | [diff] [blame] | 32 | screenshotQuality,
|
| 33 | }, _ => {
|
| 34 | callback(true);
|
avm99963 | 476a2a6 | 2021-02-07 00:40:02 +0100 | [diff] [blame] | 35 | });
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 36 | }
|
| 37 |
|
| 38 | function saveAndClose() {
|
avm99963 | 8044b40 | 2021-02-07 14:24:12 +0100 | [diff] [blame] | 39 | save(_ => {
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 40 | chrome.tabs.getSelected(null, function(tab) {
|
| 41 | chrome.tabs.remove(tab.id);
|
| 42 | });
|
avm99963 | 8044b40 | 2021-02-07 14:24:12 +0100 | [diff] [blame] | 43 | });
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 44 | }
|
| 45 |
|
| 46 | function initScreenCaptureQuality() {
|
avm99963 | 476a2a6 | 2021-02-07 00:40:02 +0100 | [diff] [blame] | 47 | chrome.storage.local.get('screenshotQuality', value => {
|
avm99963 | 8044b40 | 2021-02-07 14:24:12 +0100 | [diff] [blame] | 48 | $('lossy').checked = value['screenshotQuality'] == 'jpeg';
|
| 49 | $('lossless').checked = value['screenshotQuality'] == 'png';
|
avm99963 | 476a2a6 | 2021-02-07 00:40:02 +0100 | [diff] [blame] | 50 | });
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 51 | }
|
| 52 |
|
| 53 | function i18nReplace(id, name) {
|
| 54 | return $(id).innerText = chrome.i18n.getMessage(name);
|
| 55 | }
|
| 56 |
|
| 57 | const CURRENT_LOCALE = chrome.i18n.getMessage('@@ui_locale');
|
| 58 | if (CURRENT_LOCALE != 'zh_CN') {
|
| 59 | UI.addStyleSheet('./i18n_styles/en_options.css');
|
| 60 | }
|
| 61 |
|
avm99963 | 04def3e | 2016-11-27 22:53:05 +0100 | [diff] [blame] | 62 | var 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 |
|
| 80 | document.addEventListener('DOMContentLoaded', init);
|