| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 }); | 281 }); |
| 282 } | 282 } |
| 283 | 283 |
| 284 function prepareNotificationIconAndPopup() | 284 function prepareNotificationIconAndPopup() |
| 285 { | 285 { |
| 286 activeNotification.onClicked = function() | 286 activeNotification.onClicked = function() |
| 287 { | 287 { |
| 288 iconAnimation.stop(); | 288 iconAnimation.stop(); |
| 289 activeNotification = null; | 289 activeNotification = null; |
| 290 }; | 290 }; |
| 291 | 291 |
| 292 iconAnimation.update(activeNotification.severity); | 292 iconAnimation.update(activeNotification.severity); |
|
Felix Dahlke
2014/02/27 14:10:39
Nit: Probably whitespace differences, this shouldn
| |
| 293 } | 293 } |
| 294 | 294 |
| 295 function openNotificationLinks() | 295 function openNotificationLinks() |
| 296 { | 296 { |
| 297 if (activeNotification.links) | 297 if (activeNotification.links) |
| 298 { | 298 { |
| 299 activeNotification.links.forEach(function(link) | 299 activeNotification.links.forEach(function(link) |
| 300 { | 300 { |
| 301 ext.windows.getLastFocused(function(win) | 301 ext.windows.getLastFocused(function(win) |
| 302 { | 302 { |
| 303 win.openTab(Utils.getDocLink(link)); | 303 win.openTab(Utils.getDocLink(link)); |
| 304 }); | 304 }); |
| 305 }); | 305 }); |
| 306 } | 306 } |
| 307 prepareNotificationIconAndPopup(); | |
| 308 } | 307 } |
| 309 | 308 |
| 310 function notificationButtonClick(id, index) | 309 function notificationButtonClick(id, index) |
| 311 { | 310 { |
| 312 if (activeNotification.links && activeNotification.links[index]) | 311 if (activeNotification.links && activeNotification.links[index]) |
| 313 { | 312 { |
| 314 ext.windows.getLastFocused(function(win) | 313 ext.windows.getLastFocused(function(win) |
| 315 { | 314 { |
| 316 win.openTab(Utils.getDocLink(activeNotification.links[index])); | 315 win.openTab(Utils.getDocLink(activeNotification.links[index])); |
| 317 }); | 316 }); |
| 318 } | 317 } |
| 319 prepareNotificationIconAndPopup(); | |
| 320 } | |
| 321 | |
| 322 function getNotificationLinkTitles(text) | |
|
Thomas Greiner
2014/02/18 14:26:17
You can simply do:
var titles = [];
var regex = /
saroyanm
2014/02/18 16:20:28
I like this :)
| |
| 323 { | |
| 324 var titles = []; | |
| 325 var text = text; | |
| 326 while (text) | |
| 327 { | |
| 328 var match = /<a[^>]*>(.*?)<\/a>(.*)/.exec(text); | |
| 329 if(!match) | |
|
Thomas Greiner
2014/02/18 14:26:17
Nit: Missing space between "if" and opening bracke
saroyanm
2014/02/18 16:20:28
I have to be more attentive, I thought I fixed thi
| |
| 330 return titles; | |
| 331 titles.push({"title": match[1]}); | |
|
Thomas Greiner
2014/02/18 14:26:17
That's inconsistent. The function's name suggests
saroyanm
2014/02/18 16:20:28
Done.
| |
| 332 text = match[2]; | |
| 333 } | |
| 334 return titles; | |
| 335 } | 318 } |
| 336 | 319 |
| 337 function showNotification(notification) | 320 function showNotification(notification) |
| 338 { | 321 { |
| 339 activeNotification = notification; | 322 activeNotification = notification; |
| 340 if (activeNotification.severity === "critical") | 323 if (activeNotification.severity === "critical") |
| 341 { | 324 { |
| 342 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; | 325 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
| 343 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) | 326 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) |
| 344 { | 327 { |
| 345 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); | 328 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); |
| 346 notification.show(); | 329 notification.show(); |
| 347 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); | 330 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); |
| 348 return; | 331 return; |
| 349 } | 332 } |
| 350 | 333 |
| 351 var texts = Notification.getLocalizedTexts(notification); | 334 var texts = Notification.getLocalizedTexts(notification); |
| 352 var title = texts.title ? texts.title : ""; | 335 var title = texts.title || ""; |
| 353 var message = texts.message ? texts.message : ""; | 336 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
| 354 var iconUrl = ext.getURL("icons/abp-128.png"); | 337 var iconUrl = ext.getURL("icons/abp-128.png"); |
| 355 if ("notifications" in ext) | 338 var hasLinks = activeNotification.links && activeNotification.links.length > 0; |
| 356 { | 339 if ("browserNotifications" in ext) |
| 357 var buttons = getNotificationLinkTitles(message); | 340 { |
|
Thomas Greiner
2014/02/18 14:26:17
There's no need for a variable here if you only us
saroyanm
2014/02/18 16:20:28
Done.
| |
| 358 var opt = { | 341 var opts = { |
| 359 type: "basic", | 342 type: "basic", |
| 360 title: title, | 343 title: title, |
| 361 message: message, | 344 message: message, |
|
Thomas Greiner
2014/02/18 14:26:17
HTML tags need to be stripped from message.
saroyanm
2014/02/18 16:20:28
Done.
| |
| 362 iconUrl: iconUrl, | 345 iconUrl: iconUrl, |
| 363 buttons: buttons | 346 buttons: [] |
| 364 }; | 347 }; |
| 365 var notification = ext.notifications; | 348 var regex = /<a>(.*?)<\/a>/g; |
| 366 notification.create("", opt, function() {}); | 349 var plainMessage = texts.message || ""; |
| 350 var match; | |
| 351 while (match = regex.exec(plainMessage)) | |
| 352 opts.buttons.push({title: match[1]}); | |
| 353 | |
| 354 var notification = ext.browserNotifications; | |
| 355 notification.create("", opts, function() {}); | |
| 367 notification.onClosed.addListener(prepareNotificationIconAndPopup); | 356 notification.onClosed.addListener(prepareNotificationIconAndPopup); |
| 368 notification.onClicked.addListener(openNotificationLinks); | |
|
Thomas Greiner
2014/02/18 14:26:17
We don't need this anymore if there's a button for
saroyanm
2014/02/18 16:20:28
Done.
| |
| 369 notification.onButtonClicked.addListener(notificationButtonClick); | 357 notification.onButtonClicked.addListener(notificationButtonClick); |
| 370 } | 358 } |
| 371 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns) | 359 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns) |
| 372 { | 360 { |
| 361 if (hasLinks) | |
| 362 message += " " + ext.i18n.getMessage("notification_without_buttons"); | |
| 363 | |
| 373 var notification = webkitNotifications.createNotification(iconUrl, title, message); | 364 var notification = webkitNotifications.createNotification(iconUrl, title, message); |
| 374 notification.show(); | 365 notification.show(); |
| 375 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); | 366 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); |
| 376 notification.addEventListener("click", openNotificationLinks, false); | 367 notification.addEventListener("click", openNotificationLinks, false); |
| 377 } | 368 } |
| 378 else | 369 else |
| 379 { | 370 { |
| 380 var notification = confirm(title+"\n"+message); | 371 var message = title + "\n" + message; |
|
Thomas Greiner
2014/02/18 14:26:17
Nit: Missing spaces. |confirm(title + "\n" + messa
saroyanm
2014/02/18 16:20:28
Done.
| |
| 381 if (notification == true) | 372 if (hasLinks) |
| 373 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | |
| 374 | |
| 375 if (confirm(message)) | |
|
Thomas Greiner
2014/02/27 10:07:32
Nit: Change to…
if (confirm(message))
openNotif
| |
| 376 { | |
| 382 openNotificationLinks(); | 377 openNotificationLinks(); |
| 378 prepareNotificationIconAndPopup(); | |
| 379 } | |
| 380 else | |
| 381 prepareNotificationIconAndPopup(); | |
| 383 } | 382 } |
| 384 } | 383 } |
| 385 else | 384 else |
| 386 prepareNotificationIconAndPopup(); | 385 prepareNotificationIconAndPopup(); |
| 387 } | 386 } |
| 388 | 387 |
| 389 ext.onMessage.addListener(function (msg, sender, sendResponse) | 388 ext.onMessage.addListener(function (msg, sender, sendResponse) |
| 390 { | 389 { |
| 391 switch (msg.type) | 390 switch (msg.type) |
| 392 { | 391 { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 tab.sendMessage({type: "clickhide-deactivate"}); | 497 tab.sendMessage({type: "clickhide-deactivate"}); |
| 499 refreshIconAndContextMenu(tab); | 498 refreshIconAndContextMenu(tab); |
| 500 }); | 499 }); |
| 501 | 500 |
| 502 setTimeout(function() | 501 setTimeout(function() |
| 503 { | 502 { |
| 504 var notificationToShow = Notification.getNextToShow(); | 503 var notificationToShow = Notification.getNextToShow(); |
| 505 if (notificationToShow) | 504 if (notificationToShow) |
| 506 showNotification(notificationToShow); | 505 showNotification(notificationToShow); |
| 507 }, 3 * 60 * 1000); | 506 }, 3 * 60 * 1000); |
| LEFT | RIGHT |