gpt4 book ai didi

javascript读取新的rss条目并创建通知

转载 作者:行者123 更新时间:2023-11-30 04:35:35 24 4
gpt4 key购买 nike

I want to create a javascript which checks if a new rss feed has been updated and display a notification using phonegaps notification methods. http://docs.phonegap.com/phonegap_notification_notification.md.html#Notification

     var oldEntry="";
document.addEventListener("deviceready", onDeviceReady, false);

// PhoneGap is ready
//
function onDeviceReady() {
// Empty
}

// Show a custom alert
//

function sendRequest(){

getRss("http://rss.cnn.com/rss/cnn_latest.rss.xml");
setTimeout('showAlert(newEntry.title)',4000);

}


function showAlert(data) {
var st = randomString();
if(oldEntry==""){
oldEntry = data;
navigator.notification.alert(
data, // message
'New Rss Entry', // title
'New Rss Entry'


);
}

else {
if(oldEntry!=data){
navigator.notification.alert(
data, // message
'New Rss Entry', // title
'New Rss Entry'


);
oldEntry = data;

}
}

setTimeout('sendRequest()',8000);
}

function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}

sendRequest();

现在新的和旧的 Rss 标题都会作为通知弹出,是否可以限制该功能只显示最新的 Rss 标题?

即使我在 8000 毫秒后关闭了这两个通知,它们都再次出现,但我想检查是否有任何新通知并只显示它们,而不是用户已关闭的通知。

这是为了获取新条目。

    var newEntry="";
function getRss(url){
if(url == null) return false;

// Create Google Feed API address
var api = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="
+ encodeURIComponent(url);

api += "&output=json_xml"

// Send request
$.getJSON(api, function(data){

// Check for error
if (data.responseStatus == 200) {

// Process the feeds
_process(data.responseData);

}
else {

};
});

}

var _process = function(data) {

// Get JSON feed data
var feeds = data.feed;
if (!feeds) {
return false;
}

// Get XML data for media (parseXML not used as requires 1.5+)
var xml = getXMLDocument(data.xmlString);
var xmlEntries = xml.getElementsByTagName('item');
var entry = feeds.entries[0];
newEntry = entry;

};

最佳答案

可能会有很多问题。我想也许你遇到了缓存错误。所以尝试添加这个 -

api += "&tempVar="+ Math.random()

在你的代码之后 -

api += "&output=json_xml"

关于javascript读取新的rss条目并创建通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6906664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com