Created
February 26, 2018 10:14
-
-
Save cosminpopescu14/02139e8f85434f156fd5d5063f3e8f77 to your computer and use it in GitHub Desktop.
simple webpage that notify user with free ebook from Packtpub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can check it live at
http://www.chestiiautomate.ro/packtebook/