Skip to content

Instantly share code, notes, and snippets.

@ReSTARTR
Created May 8, 2011 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ReSTARTR/961440 to your computer and use it in GitHub Desktop.
Save ReSTARTR/961440 to your computer and use it in GitHub Desktop.
chrome notification snippet
<script>
(function() {
var def_notification_timeout=5000;
var def_username = 'yoshida';
function show(msg) {
var noti = webkitNotifications.createNotification(
'icon.png',
'From: my notification',
msg
);
noti.show();
setTimeout(function() {
noti.cancel();
}, def_notification_timeout);
}
// 接続時に自分のIDを入力させることで、全体へのメッセージブロードキャストを防ぐ
var ws = null;
function connect() {
ws=new WebSocket("ws://localhost:8080/tw/?id=" + def_username);
}
connect();
ws.onopen = function(e){show('connected: as @' + def_username);};
ws.onclose = function(e){connect();};
ws.onerror = function(e){show('error!');};
ws.onmessage = function(e) {
show(e.data);
};
var noti = webkitNotifications.createHTMLNotification('test.html')
noti.show();
})();
</script>
{
"name": "My First Extension",
"version": "1.0",
"description": "the first extention that I made",
"browser_action": {
"default_icon": "icon.png"
},
"permissions": ["notifications"],
"background_page": "background.html"
}
<html>
<head></head>
<body id="test" onload="">
<h1>this is test</h1>
<h2>sample text is here.</h2>
<p><p>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment