Skip to content

Commit 9846dd9

Browse files
committed
Hangouts: use iconified HTML5 notifications
1 parent 896a204 commit 9846dd9

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

sites/Hangouts/app.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
var hangouts = {
66
transparent: true,
77
postinject: ["notifier"],
8-
preinject: ["styler"],
9-
subscribeTo: ['receivedHangoutsMessage', 'unhideApp', 'HangoutsRosterReady'],
8+
preinject: ["styler", 'shim_html5_notifications'],
9+
subscribeTo: ['receivedHTML5DesktopNotification','receivedHangoutsMessage', 'unhideApp', 'HangoutsRosterReady'],
1010
url: "https://plus.google.com/hangouts"
1111
};
1212
$.browser.addShortcut("Google Hangouts", hangouts);
@@ -95,6 +95,11 @@ delegate.receivedHangoutsMessage = function(tab, msg) {
9595
console.log(Date() + ' [posted user notification] ' + msg);
9696
};
9797

98+
delegate.receivedHTML5DesktopNotification = function(tab, note) {
99+
console.log(Date() + ' [posted HTML5 notification] ' + note);
100+
$.app.postHTML5Notification(note);
101+
};
102+
98103
delegate.handleClickedNotification = function(title, subtitle, msg, id) {
99104
console.log("JS: opening notification for: "+ [title, subtitle, msg, id]);
100105
$.browser.tabSelected = hangoutsTab;

sites/Hangouts/styler.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
/* eslint-env browser */
2-
/* eslint builtins */
3-
4-
if (~window.name.indexOf('h_gtn_')) { //this is an incoming phone call notifcation
5-
webkit.messageHandlers.unhideApp.postMessage([]); //get the app in the user's face right now!!
6-
window.addEventListener('DOMSubtreeModified', function(e){
7-
if (btn = document.querySelector('button + button')) { //answer button
8-
document.removeEventListener('DOMSubtreeModified', this, false);
9-
btn.autofocus = true //hafta apply this before .onload
10-
}
11-
});
12-
window.addEventListener("keypress", function (e) {
13-
switch (e.which) {
14-
case 13: //Enter
15-
case 32: //Space
16-
document.querySelector('button + button').click(); //Answer call
17-
break;
18-
case 27: //Esc
19-
case 9: //Tab
20-
case 8: //Bksp
21-
document.querySelector('button').click(); //Decline call
22-
break;
23-
default:
24-
}
25-
});
26-
};
2+
/*eslint eqeqeq:0, quotes:0, space-infix-ops:0, curly:0*/
273

284
if (window == top)
295
(function(){ //IIFE
@@ -49,7 +25,7 @@ if (window == top)
4925

5026
var css = document.createElement("style");
5127
css.type = 'text/css';
52-
css.id = 'unSocialSpam'
28+
css.id = 'unSocialSpam';
5329
css.innerHTML = "\
5430
body, #content { overflow: hidden; background-color: transparent !important; }\
5531
#contentPane, #gb, #gba, #notify-widget-pane { display: none; }\
@@ -90,14 +66,41 @@ if (window.name == 'preld') { //frame-id ^gtn_ this is a chatbox iframe
9066
css.type = 'text/css';
9167
css.id = 'appleEmoji'
9268
css.innerHTML = "\
93-
span[data-emo] span { opacity: 1.0 !important; width: auto !important; } \
69+
span[data-emo] span { opacity: 1.0 !important; width: auto !important; font-size: 12pt; } \
9470
span[data-emo] div { display: none !important; } \
9571
\
9672
";
9773
document.head.appendChild(css);
9874
}
9975
}
10076
document.addEventListener('DOMSubtreeModified', injectCSS, false); //mutation events are deprecated
77+
78+
document.addEventListener('DOMSubtreeModified', function(e){
79+
// enable keyboard to quickly take/reject phone calls
80+
if (btn = document.querySelector('button[title="Answer call"]')) { //answer button
81+
var from = document.QuerySelector('div[googlevoice]').innerText;
82+
console.log(Date() + " [Incoming phone call from:] " + from);
83+
document.removeEventListener('DOMSubtreeModified', this, false);
84+
btn.autofocus = true //hafta apply this before .onload
85+
window.addEventListener("keypress", function (e) {
86+
switch (e.which) {
87+
case 13: //Enter
88+
case 32: //Space
89+
document.querySelector('button[title="Answer call"]').click();
90+
document.removeEventListener('keypress', this, false);
91+
break;
92+
case 27: //Esc
93+
case 9: //Tab
94+
case 8: //Bksp
95+
document.querySelector('button[title="Decline call"]').click();
96+
document.removeEventListener('keypress', this, false);
97+
break;
98+
default:
99+
}
100+
});
101+
webkit.messageHandlers.unhideApp.postMessage([]); //get the app in the user's face right now!!
102+
}
103+
});
101104
})();
102105

103106
// watch for pop-out button to appear

0 commit comments

Comments
 (0)