Auto OnPageLoad
This is a Test
Auto OnPageLoad
<script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.3/dist/js.cookie.min.js"></script>
<script>
(function($) {
$(document).ready(function() {
var rssFeedUrl = "https://rss.app/feeds/TqiGIeGZEUuRTwQx.xml";
var cookieName = "rssItemRead";
// Initially hide the "Dismiss All" button
var dismissBtnHtml = '<button id="dismissAllNotifications" class="uk-button uk-button-default" style="position: fixed; top: 20px; right: 20px; z-index: 10000; background-color: #0d56d857; display: none;">Dismiss All</button>';
$('body').append(dismissBtnHtml);
$('#dismissAllNotifications').on('click', function() {
$.ajax({
url: rssFeedUrl,
type: 'GET',
dataType: 'xml',
success: function(response) {
$(response).find("item").each(function() {
var item = $(this);
var title = item.find("title").text();
var content = item.find("content\\:encoded").text() || item.find("description").text();
var contentHash = hashCode(title + content);
updateReadItemsHashes(contentHash); // Mark each item as read
});
}
});
UIkit.notification.closeAll();
});
// Logic to temporarily show the "Dismiss All" button on hover over notification close buttons
$(document).on('mouseenter', '.uk-notification-close', function() {
$('#dismissAllNotifications').show();
setTimeout(function() {
$('#dismissAllNotifications').fadeOut();
}, 7000); // Hide after 7 seconds
});
function fetchAndDisplayRssItems() {
$.ajax({
url: rssFeedUrl,
type: 'GET',
dataType: 'xml',
success: function(response) {
$(response).find("item").each(function() {
var item = $(this);
var content = item.find("content\\:encoded").text() || item.find("description").text();
var title = item.find("title").text();
var contentHash = hashCode(title + content);
var readItemsHashes = getReadItemsHashes();
if (!readItemsHashes.includes(contentHash)) {
var notification = UIkit.notification({
message: `<div class="uk-light" style="max-height: 200px; overflow-y: auto; cursor: pointer;">${content}</div>`,
status: 'primary',
pos: 'top-right',
timeout: false
});
$(notification.$el).on('click', function() {
updateReadItemsHashes(contentHash);
$(this).hide();
});
}
});
},
error: function() {
console.log("Error fetching the RSS feed.");
}
});
}
function getReadItemsHashes() {
var cookieVal = Cookies.get(cookieName);
if (cookieVal) {
try {
var decodedCookieVal = decodeURIComponent(cookieVal);
return JSON.parse(decodedCookieVal);
} catch (e) {
console.error("Error parsing cookie value:", e);
return [];
}
}
return [];
}
function updateReadItemsHashes(contentHash) {
var hashes = getReadItemsHashes();
if (!hashes.includes(contentHash)) {
hashes.push(contentHash);
Cookies.set(cookieName, JSON.stringify(hashes), { expires: 7, path: '/' });
console.log('Cookie updated:', contentHash);
}
}
function hashCode(s) {
return s.split('').reduce(function(a, b) {
a = ((a << 5) - a) + b.charCodeAt(0);
return a & a;
}, 0);
}
fetchAndDisplayRssItems();
});
})(jQuery);
</script>
<style>
.uk-notification.uk-notification-top-right {
margin-top: 60px;
}
.uk-notification-message-primary {
color: #fff;
background-color: #222222b3 !important;
}
</style>