我如何创建chrome.通知实时
How can I create chrome.notification real Time?
使用google chrome Api扩展,我有以下代码显示JSON通知。一旦通知显示,当我点击它打开多个标签url(这是一个错误)。我需要解决这个问题,因为这应该只打开一个标签url,这是唯一的问题。看看下面的代码:
var timeChange = 1000, jsons = ['JSON_URL'];
updateValue = function() {
var colorStatus = 0;
chrome.storage.local.get(function (dataStorage) {
$.getJSON(jsons+'?'+$.now(), function (data) {
var jLastPost = {'LastNotification':''}, sizePost = (data.results.length - 1), dataLastPost = data.results[0];
totalEntradas = data.totalEntradas ? data.totalEntradas : '';
$.each(data.results, function (k,v) {
if (($.inArray('post-'+v.id, dataStorage.IDs) !== -1) && (v.date_status > 0)) {
colorStatus = 1;
}
});
chrome.browserAction.setBadgeText({'text': totalEntradas.toString()});
if (dataStorage.LastNotification !== dataLastPost.id)
{
jLastPost.LastNotification = dataLastPost.id;
chrome.storage.local.set(jLastPost);
chrome.notifications.create(dataLastPost.id,{
type: 'basic',
title: dataLastPost.titulo,
message: 'Now for you!',
iconUrl: dataLastPost.image
}, function (id) {});
chrome.notifications.onClicked.addListener(function () {
chrome.tabs.create({url: dataLastPost.uri});
});
chrome.notifications.clear(dataLastPost.id, function() {});
return false;
}
});
});
setTimeout(updateValue, timeChange);
}
updateValue();
运行updateValue
时,每秒附加一个chrome.notifications.onClicked
侦听器。您至少应该将侦听器移出方法。
这些应该可以工作。
var timeChange = 1000, jsons = ['JSON_URL'];
var lastPostUri;
chrome.notifications.onClicked.addListener(function () {
if (lastPostUri) {
chrome.tabs.create({url: lastPostUri});
}
});
updateValue = function() {
var colorStatus = 0;
chrome.storage.local.get(function (dataStorage) {
$.getJSON(jsons+'?'+$.now(), function (data) {
var jLastPost = {'LastNotification':''}, sizePost = (data.results.length - 1), dataLastPost = data.results[0];
totalEntradas = data.totalEntradas ? data.totalEntradas : '';
$.each(data.results, function (k,v) {
if (($.inArray('post-'+v.id, dataStorage.IDs) !== -1) && (v.date_status > 0)) {
colorStatus = 1;
}
});
chrome.browserAction.setBadgeText({'text': totalEntradas.toString()});
if (dataStorage.LastNotification !== dataLastPost.id)
{
jLastPost.LastNotification = dataLastPost.id;
chrome.storage.local.set(jLastPost);
lastPostUri = dataLastPost.uri
chrome.notifications.create(dataLastPost.id,{
type: 'basic',
title: dataLastPost.titulo,
message: 'Now for you!',
iconUrl: dataLastPost.image
}, function (id) {});
chrome.notifications.clear(dataLastPost.id, function() {});
return false;
}
});
});
setTimeout(updateValue, timeChange);
}
updateValue();
相关文章:
- 单击Chrome通知后,转到已打开的选项卡
- 带有XHR的Chrome推送通知(使用不带PHP的JavaScript)
- Chrome Android版-通知;t出现
- Chrome扩展通知未显示contextMessage
- 如何在chrome扩展中插入通知操作按钮
- 我可以禁用Chrome浏览器中的“你已经全屏”通知吗
- Chrome扩展-在全屏视频顶部显示自定义通知/弹出窗口(HTML元素)
- 用户点击后关闭通知的Google Chrome扩展
- 如何使用 chrome 桌面通知向许多用户发送通知
- Chrome通知在所有选项卡中都可见
- 如何使用http向特定用户发送Chrome通知
- 在Chrome通知中打开URL
- 编辑chrome通知后,它被调用
- 如何用JavaScript在加载视图中删除所有Chrome通知
- Chrome通知使用AJAX
- 如何创建在全屏应用程序上显示的Javascript/Chrome通知
- 我如何创建chrome.通知实时
- 使用for循环与Chrome通知导致错误的onclick链接
- 打包应用中的 Chrome 通知“Chrome.notifications.create”
- 不能得到一个简单的Chrome通知工作