| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); |
| 293 } | 293 } |
| 294 | 294 |
| 295 function openNotificationLinks() | |
| 296 { | |
| 297 if (activeNotification.links) | |
| 298 { | |
| 299 activeNotification.links.forEach(function(link) | |
| 300 { | |
| 301 ext.windows.getLastFocused(function(win) | |
| 302 { | |
| 303 win.openTab(Utils.getDocLink(link)); | |
| 304 }); | |
| 305 }); | |
| 306 } | |
| 307 prepareNotificationIconAndPopup(); | |
| 308 } | |
| 309 | |
| 310 function notificationButtonClick(id, index) | |
| 311 { | |
| 312 if (activeNotification.links && activeNotification.links[index]) | |
| 313 { | |
| 314 ext.windows.getLastFocused(function(win) | |
| 315 { | |
| 316 win.openTab(Utils.getDocLink(activeNotification.links[index])); | |
| 317 }); | |
| 318 } | |
| 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 } | |
| 336 | |
| 295 function showNotification(notification) | 337 function showNotification(notification) |
| 296 { | 338 { |
| 297 activeNotification = notification; | 339 activeNotification = notification; |
| 298 | 340 if (activeNotification.severity === "critical") |
| 299 if (activeNotification.severity === "critical" | |
| 300 && typeof webkitNotifications !== "undefined") | |
| 301 { | 341 { |
| 302 var notification = webkitNotifications.createHTMLNotification("notification. html"); | 342 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
| 303 notification.show(); | 343 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) |
| 304 notification.addEventListener("close", prepareNotificationIconAndPopup); | 344 { |
| 345 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); | |
| 346 notification.show(); | |
| 347 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); | |
| 348 return; | |
| 349 } | |
| 350 | |
| 351 var texts = Notification.getLocalizedTexts(notification); | |
| 352 var title = texts.title ? texts.title : ""; | |
| 353 var message = texts.message ? texts.message : ""; | |
| 354 var iconUrl = ext.getURL("icons/abp-128.png"); | |
| 355 if ("notifications" in ext) | |
| 356 { | |
| 357 var buttons = getNotificationLinkTitles(message); | |
|
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 = { | |
| 359 type: "basic", | |
| 360 title: title, | |
| 361 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, | |
| 363 buttons: buttons | |
| 364 }; | |
| 365 var notification = ext.notifications; | |
| 366 notification.create("", opt, function() {}); | |
| 367 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); | |
| 370 } | |
| 371 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns) | |
| 372 { | |
| 373 var notification = webkitNotifications.createNotification(iconUrl, title, message); | |
| 374 notification.show(); | |
| 375 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); | |
| 376 notification.addEventListener("click", openNotificationLinks, false); | |
| 377 } | |
| 378 else | |
| 379 { | |
| 380 var notification = confirm(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) | |
| 382 openNotificationLinks(); | |
| 383 } | |
| 305 } | 384 } |
| 306 else | 385 else |
| 307 prepareNotificationIconAndPopup(); | 386 prepareNotificationIconAndPopup(); |
| 308 } | 387 } |
| 309 | 388 |
| 310 ext.onMessage.addListener(function (msg, sender, sendResponse) | 389 ext.onMessage.addListener(function (msg, sender, sendResponse) |
| 311 { | 390 { |
| 312 switch (msg.type) | 391 switch (msg.type) |
| 313 { | 392 { |
| 314 case "get-selectors": | 393 case "get-selectors": |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 tab.sendMessage({type: "clickhide-deactivate"}); | 498 tab.sendMessage({type: "clickhide-deactivate"}); |
| 420 refreshIconAndContextMenu(tab); | 499 refreshIconAndContextMenu(tab); |
| 421 }); | 500 }); |
| 422 | 501 |
| 423 setTimeout(function() | 502 setTimeout(function() |
| 424 { | 503 { |
| 425 var notificationToShow = Notification.getNextToShow(); | 504 var notificationToShow = Notification.getNextToShow(); |
| 426 if (notificationToShow) | 505 if (notificationToShow) |
| 427 showNotification(notificationToShow); | 506 showNotification(notificationToShow); |
| 428 }, 3 * 60 * 1000); | 507 }, 3 * 60 * 1000); |
| OLD | NEW |