私はまだ解決できない問題があります。メニューとタブがあるポップアップページがあり、設定タブがあります。設定タブで、i をローカルストレージに保存します.1つはデスクトップ通知のnotification_timeです。ポップアップでbackground.htmlのオプションを保存するには?
注::オプションページはありません!
私の拡張機能にはこのポップアップウィンドウと背景ページがあり、その機能はデスクトップ通知をユーザに警告することです。 5,10,30分、1,2時間などで通知を表示します。この時間はポップアップページのオプションメニューで選択できます。問題は、5分が保存され、たとえば10分に更新する場合、background.htmlが自分自身を更新していないことです。私はコードを約20回書き換えましたが、解決策を見つけることができませんでした。私の問題について明確にするために、コードサンプルとプリントスクリーンを入手してください。
ポップアップ:
$("#save_settings").click(function(){
var bgp = chrome.extension.getBackgroundPage();
localStorage.setItem("notifynumber",$("#notifynumber").val());
if($("#notify").attr('checked')){
localStorage.setItem('chbox','true');
} else {
localStorage.setItem('chbox','false');
}
if($("#notif_time_select :selected").val()!="default"){
bgp.setTime(parseInt($("#notif_time_select :selected").val()));
}
if($("#org_select :selected").val()!="default"){
localStorage.setItem('org',$("#org_select :selected").val().replace(/%20/g," "));
}
});
注:save_settingsボタンで、タブ上のチェックボックス(チェック後、通知が許可されている場合、他のdiabled)があります。いくつかのデータを選択するためのもの(org = organization)と、時間を選択するものの2つのhtml選択タグがあります。 "#notif_time_select"
はhtml selectタグです。ここでは5,10,30分などを選択します。
保存ボタンをクリックすると、チェックボックスの状態がlocalstorageに保存され、バックグラウンドページの1つの関数が保存されます時間。 :bgp.setTime(parseInt($("#notif_time_select :selected").val()));
背景ページ:私は、関数のsetTimeを使用し、時間を節約するため
:
var time = 300000; // default
function setTime(time){
this.time=time;
console.log("time set to: "+this.time);
}
私は定期的に
setInterval(function(){
howmanyOnline("notify",function(data){
if(data>localStorage.getItem("notifynumber")){
if (!window.webkitNotifications) { // check browser support
alert('Sorry , your browser does not support desktop notifications.');
}
notifyUser(data); // create the notification
}
if(localStorage.getItem('tweet')=='true'){
if(data>localStorage.getItem("notifynumber")){
sendTweet(data,localStorage.getItem('org'),localStorage.getItem('ck'),localStorage.getItem('cs'),localStorage.getItem('at'),localStorage.getItem('ats'));
}
}
});
},time);
内のコードの通知を表示するようにするsetIntervalを使用し、後setIntervalは問題なく動作しますが、その
},time);
はうまく更新されません。 10分ごとに通知を表示するように設定を変更すると、5分後に表示されます。唯一の方法は、拡張子全体を再起動することです。どのように私は全体の拡張を再起動せずにsetIntervalの頻度を更新できますか?私はあまりにものlocalStorageにnotif_time保存した場合、バックグラウンドで、私はのlocalStorageの変更をリッスンするために、リスナーを設定何おかげでジム・
。特定のlocalStorageアイテムの変更を聞く方法はありますか?
を、私はそれを3回テストし、うまく機能し、1000の感謝の@apsillers –