1 Star 0 Fork 0

David/chrome-extensions-samples

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
options.js 2.07 KB
Copy Edit Raw Blame History
Sam Thorogood authored 5 years ago . import old samples
// Copyright (c) 2012 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.
// Store CSS data in the "local" storage area.
//
// Usually we try to store settings in the "sync" area since a lot of the time
// it will be a better user experience for settings to automatically sync
// between browsers.
//
// However, "sync" is expensive with a strict quota (both in storage space and
// bandwidth) so data that may be as large and updated as frequently as the CSS
// may not be suitable.
var storage = chrome.storage.local;
// Get at the DOM controls used in the sample.
var resetButton = document.querySelector('button.reset');
var submitButton = document.querySelector('button.submit');
var textarea = document.querySelector('textarea');
// Load any CSS that may have previously been saved.
loadChanges();
submitButton.addEventListener('click', saveChanges);
resetButton.addEventListener('click', reset);
function saveChanges() {
// Get the current CSS snippet from the form.
var cssCode = textarea.value;
// Check that there's some code there.
if (!cssCode) {
message('Error: No CSS specified');
return;
}
// Save it using the Chrome extension storage API.
storage.set({'css': cssCode}, function() {
// Notify that we saved.
message('Settings saved');
});
}
function loadChanges() {
storage.get('css', function(items) {
// To avoid checking items.css we could specify storage.get({css: ''}) to
// return a default value of '' if there is no css value yet.
if (items.css) {
textarea.value = items.css;
message('Loaded saved CSS.');
}
});
}
function reset() {
// Remove the saved value from storage. storage.clear would achieve the same
// thing.
storage.remove('css', function(items) {
message('Reset stored CSS');
});
// Refresh the text area.
textarea.value = '';
}
function message(msg) {
var message = document.querySelector('.message');
message.innerText = msg;
setTimeout(function() {
message.innerText = '';
}, 3000);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/df_coding/chrome-extensions-samples.git
git@gitee.com:df_coding/chrome-extensions-samples.git
df_coding
chrome-extensions-samples
chrome-extensions-samples
master

Search