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