Created
August 14, 2013 19:32
-
-
Save noahm/6234698 to your computer and use it in GitHub Desktop.
Compatibility shim for chrome's desktop notification API, and lines to turn on notifications in Steam's web chat after they have been disabled following a page load
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
/* | |
* Patch in support for Google's draft webkit version of HTML notifications | |
* It seems that firefox doesn't currently support the iconUrl option. | |
* see the official spec at: http://www.w3.org/TR/2012/WD-notifications-20120614/#api | |
* and google's spec at: http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification | |
*/ | |
window.webkitNotifications = { | |
requestPermission: function(callback){ | |
Notification.requestPermission(callback); | |
}, | |
checkPermission: function(){ | |
if (Notification.permission === "granted") return 0; | |
if (Notification.permission === "default") return 1; | |
return 2; | |
}, | |
createNotification: function(img, title, message) { | |
var n = new Notification(title, {body: message, iconUrl: img}); | |
n.show = n.close = function(){}; | |
return n; | |
}, | |
createHTMLNotification: function() { | |
if (window.console && window.console.warn) { | |
console.warn("Attempted use of deprecated HTML notification"); | |
} | |
return false; | |
} | |
}; | |
// enable notifications in Steam web chat (steamcommunity.com/chat) after the page has already disabled them | |
Chat.m_bBrowserSupportsNotifications = true; | |
Chat.SetPref('notifications', true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment