Skip to content

Commit

Permalink
Request only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
samliew committed Feb 23, 2019
1 parent 0f00133 commit 0b5458a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions UserActivityNotifications.user.js
Expand Up @@ -3,7 +3,7 @@
// @description Display notifications on user profile when new activity is detected since page load
// @homepage https://github.com/samliew/SO-mod-userscripts
// @author @samliew
// @version 0.1.9
// @version 0.2
//
// @include https://*stackoverflow.com/*
// @include https://*serverfault.com/*
Expand All @@ -20,10 +20,10 @@


// If user accepts, we can show native notifications
if(!("Notification" in window)) {
var notifyperm = "Notification" in window;
if(!notifyperm) {
console.log("This browser does not support desktop notifications.");
}
Notification.requestPermission();


(function() {
Expand Down Expand Up @@ -154,6 +154,9 @@ Notification.requestPermission();
username = $('.profile-user--name > div:first, .mini-avatar .name').text().replace('♦', '').replace(/\s+/g, ' ').trim();
shortname = username.split(' ')[0].substr(0, 12).trim();

// Get notification permissions
if(notifyperm) Notification.requestPermission();

// Run once on page load, then start polling API occasionally
scheduledTask();
interval = setInterval(scheduledTask, pollInterval * 1000);
Expand Down

0 comments on commit 0b5458a

Please sign in to comment.