forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
30 lines (26 loc) · 1000 Bytes
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 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.
//
// See note in options.js for rationale on why not to use "sync".
var storage = chrome.storage.local;
var message = document.querySelector('#message');
// Check if there is CSS specified.
storage.get('css', function(items) {
console.log(items);
// If there is CSS specified, inject it into the page.
if (items.css) {
chrome.tabs.insertCSS({code: items.css}, function() {
if (chrome.runtime.lastError) {
message.innerText = 'Not allowed to inject CSS into special page.';
} else {
message.innerText = 'Injected style!';
}
});
} else {
var optionsUrl = chrome.extension.getURL('options.html');
message.innerHTML = 'Set a style in the <a target="_blank" href="' +
optionsUrl + '">options page</a> first.';
}
});