function getStorage(key)
{
var ar = [];
ar.push(key);
chrome.storage.sync.get(ar, function(obj) {
return obj[ar[0]];
//console.log('Value currently is ' + obj.key);
});
}
console.log(getStorage('updates'));
function getUpdates()
{
$.ajax({
url: server + '/api/updates',
success: function(data){
setStorage('updates', data);
getStorage('updates');
}
});
}
function setStorage(key, value)
{
chrome.storage.sync.set({[key]: value}, function() {
console.log('Value is set to ' + value);
});
}
function getStorage(key)
{
var ar = [];
ar.push(key);
chrome.storage.sync.get(ar, function(obj) {
return obj[ar[0]];
//console.log('Value currently is ' + obj.key);
});
}
getUpdates();
undefined
function getUpdates()
{
console.log('Updates... strat! ');
$.ajax({
url: server + '/api/updates',
success: function(data){
chrome.storage.local.set({'updates': data + Date.now()}, function() {
console.log('Value is set to ' + data + Date.now());
});
}
});
}
getUpdates();
Uncaught ReferenceError: $ is not defined
<!doctype html>
<html>
<head>
<title>Proxybeatch.io</title>
<!-- meta tags -->
<meta charset="utf-8">
<!-- styles sheets -->
<link rel="stylesheet" href="/css/common.css">
<!-- javascripts -->
<script src="jquery-3.3.1.min.js"></script>
<script src="popup.js"></script>
</head>
<body>
<main>
</main>
</body>
</html>
{
"manifest_version": 2,
"name": "Proxybeatch",
"description": "Прокси для Chrome",
"version": "0.1",
"homepage_url": "http://Proxybeatch.io",
"icons": {
"128": "icon_128.png"
},
"content_scripts": [
{
"js": [
"jquery-3.3.1.min.js",
"background.js"
],
"run_at": "document_start",
"matches": [
"*://*.Proxybeatch.io/*"
],
"all_frames": true
}
],
"background": {
"scripts": [
"jquery-3.3.1.min.js",
"background.js"
]
},
"browser_action": {
"default_icon": "icon_128.png",
"default_popup": "popup.html",
},
"permissions": [
"<all_urls>",
"cookies",
"storage",
"notifications",
"activeTab",
"tabs",
"webRequest",
"webRequestBlocking",
"*://*/*",
"background",
"browsingData",
"contextMenus"
]
}
Расширению нужны права на доступ к www.proxybeatch.io (либо доступ вообще ко всем сайтам):
"permissions": [ "https://www.proxybeatch.io/*" ]
["<all_urls>"]
$.ajax({
url: ''proxybeatch.io,
dataType: "json",
success: function(data){
$('main').append('data')
}
});