Spaces:
Running
Running
File size: 3,260 Bytes
28308e4 76d01cb 28308e4 76d01cb 28308e4 76d01cb 28308e4 76d01cb 28308e4 76d01cb 28308e4 5e211bf 76d01cb d5306a7 5e211bf 76d01cb d5306a7 5e211bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
// Income Tax Portal News Scraper
async function fetchTaxUpdates() {
try {
const proxyUrl = 'https://cors-anywhere.herokuapp.com/'; // Using CORS proxy
const targetUrl = 'https://www.incometax.gov.in/iec/foportal/latest-news';
const response = await fetch(proxyUrl + targetUrl);
const html = await response.text();
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const newsItems = Array.from(doc.querySelectorAll('.latest-news li'));
const taxNews = newsItems.map(item => {
const title = item.textContent.trim();
const url = item.querySelector('a')?.href || '#';
return { title, url };
});
if (taxNews.length > 0) {
const taxCard = document.querySelector('custom-notification-card[title="Income Tax Updates"]');
if (taxCard) {
const newCount = taxNews.length;
taxCard.setAttribute('new-content', `${newCount} new updates`);
taxCard.setAttribute('last-checked', 'Just now');
// Update news section with tax updates
const newsContainer = document.querySelector('.grid.grid-cols-1.md\\:grid-cols-2.lg\\:grid-cols-3.gap-6');
if (newsContainer) {
newsContainer.innerHTML = '';
taxNews.slice(0, 3).forEach((item, index) => {
const newsCard = document.createElement('news-card');
newsCard.setAttribute('title', item.title);
newsCard.setAttribute('source', 'Income Tax Dept.');
newsCard.setAttribute('date', 'Latest');
newsCard.setAttribute('summary', 'Official update from Income Tax portal');
newsCard.setAttribute('image', `http://static.photos/finance/640x360/${index+1}`);
newsCard.setAttribute('url', item.url.startsWith('http') ? item.url : `https://www.incometax.gov.in${item.url}`);
newsContainer.appendChild(newsCard);
});
}
}
}
} catch (error) {
console.error('Error fetching tax updates:', error);
}
}
document.addEventListener('DOMContentLoaded', function() {
fetchTaxUpdates();
// Check for updates periodically
setInterval(() => {
fetchTaxUpdates();
}, 300000); // Check every 5 minutes
// Request notification permission with better UX
if (Notification.permission === "default") {
setTimeout(() => {
const shouldRequest = confirm('Would you like to receive notifications for new content?');
if (shouldRequest) {
Notification.requestPermission().then(permission => {
if (permission === "granted") {
console.log('Notification permission granted');
}
});
}
}, 2000);
}
});
function showNotification(title, message) {
if (Notification.permission === "granted") {
new Notification(title, { body: message });
}
} |