In my HTML code I have href links to files, which are being downloaded. I would like to create a javascript file, that checks the last modified date and changes the styling of the anchor tag to make the name of the link turn orange, until it is clicked for the first time. Is this possible in Javascript?
I am using Electron and am wondering if there is a way to implement this.
This is an example of the link in one of the HTML files:
<a href="Link to file"><div><h3>Name of file</h3></div></a>
I found this Is it possible to retrieve the last modified date of a file using Javascript?
function fetchHeader(url, wch) {
try {
var req=new XMLHttpRequest();
req.open("HEAD", url, false);
req.send(null);
if(req.status== 200){
return req.getResponseHeader(wch);
}
else return false;
} catch(er) {
return er.message;
}
}
and am wondering if I could use
fetchHeader(location.href,'Last-Modified')
to check the last modified date of the file every time it gets downloaded and then show a desktop notification if the date has changed. I would have to store the dates in a file of course, because it should still be working when you start the app the next time. But I have to do it for local files, so I guess Javascript does not suppor this?
Then I would like to have a desktop notifcation. I created this script following this tutorial https://www.youtube.com/watch?v=ihcsKfIN6YU
function doNotify() {
Notification.requestPermission().then(function (result){
var myNotification = new Notification('NEW DOCUMENT!!!', {
body: "document" +".docx" + "has changed!!!",
icon: __dirname + '/app.ico'
});
});
}
doNotify();
When I try to call it, I get "Notifcation is not defined"
I thought of creating a function that checks for the last modified date, which is called when you click the anchor tag. This function should then call the doNotify() function, when the date has changed.
I know this is a lot. Should I maybe break this down into fewer questions?