Skip to content

Instantly share code, notes, and snippets.

@cosminpopescu14
Created February 26, 2018 10:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosminpopescu14/02139e8f85434f156fd5d5063f3e8f77 to your computer and use it in GitHub Desktop.
Save cosminpopescu14/02139e8f85434f156fd5d5063f3e8f77 to your computer and use it in GitHub Desktop.
simple webpage that notify user with free ebook from Packtpub
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PackPub free ebook notifier</title>
</head>
<body>
<?php
require('simple_html_dom.php');
$page = file_get_html('https://www.packtpub.com/packt/offers/free-learning');
$ebook_title = '';
foreach ($page->find('div[class=dotd-title]') as $value)
{
$ebook_title = preg_replace('/\s+/', ' ', $value->plaintext);
}
?>
<script>
window.onload = notifyMe;
function notifyMe(){
if (!("Notification" in window)){
alert("This browser does not support desktop notification");
}
else if (Notification.permission === "granted"){
var notification = new Notification("Today free ebook is" + '<?php echo $ebook_title; ?>');
}
else if (Notification.permission !== "denied"){
Notification.requestPermission(function(permission){
if(permission === "granted"){
var notification = new Notification("Today free ebook is" + '<?php echo $ebook_title; ?>');
}
});
}
}
</script>
<p id="ebook-name">
Tody free e-book from PacktPub is <?php echo $ebook_title; ?>
</p>
</body>
</html>
@cosminpopescu14
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment