这是一个chrome扩展程序,涉及2个脚本,第1个用于设置页面(default_popup),第二个用于具有特定网页的操作。在设置页面中一切都很好但是当我尝试在第二个脚本中访问数据时我什么都没得到。任何指针将不胜感激!将根据请求添加代码,只需告诉我您想看到的内容。
[清单]
{
"name" : "TEST",
"description" : "it just works",
"version" : "1.0",
"manifest_version" : 2,
"permissions": [
"activeTab",
"declarativeContent",
"storage"
],
"content_scripts": [
{
"matches": [This is filled in the original],
"js": ["jquery.js", "script.js"]
}
],
"browser_action":{
"default_popup": "popup.html"
}
}
[input.js]
$(function(){
window.onload = function() {
updateval();
document.getElementById('save').onclick = function(){
var value1 = document.getElementById('input_refresh').value;
var value2 = document.getElementById('input_max').value;
var value3 = document.getElementById('input_min').value;
var value4 = document.getElementById('input_disc').value;
//alert(value);
chrome.storage.local.set({
'ref' : value1,
'max' : value2,
'min' : value3,
'disc' : value4
}, function(){
console.log('Values saved');
$("#save").val("Saved!");
setTimeout(function() {
$("#save").val("Save Settings");
}, 2000);
});
}
document.getElementById('reset').onclick = function(){
chrome.storage.local.set({
'ref' : 10,
'max' : 999999,
'min' : 0,
'disc' : 30
}, function(){
updateval();
console.log('Values got reset');
$("#reset").val("Reset!");
setTimeout(function() {
$("#reset").val("Reset To Default");
}, 2000);
});
}
}
function updateval (){
chrome.storage.local.get([
'ref',
'max',
'min',
'disc'
], function(data){
$('#input_refresh').val(data.ref);
$('#input_max').val(data.max);
$('#input_min').val(data.min);
$('#input_disc').val(data.disc);
console.log('Values Gotten');
});
}
})();
[的script.js]
$(document).ready(function(){
chrome.storage.local.get([
'ref',
'max',
'min',
'disc'
], function(data){
var ref = data.ref;
var max = data.max;
var min = data.min;
var disc = data.disc;
console.log('Values Gotten');
});
if(window.location.href.indexOf("") > -1) {
//console.log("homepage");
main();
}
});
function main() { additional code here}