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 | |
295 function showNotification(notification) | 322 function showNotification(notification) |
296 { | 323 { |
297 activeNotification = notification; | 324 activeNotification = notification; |
298 | 325 if (activeNotification.severity === "critical") |
299 if (activeNotification.severity === "critical" | |
300 && typeof webkitNotifications !== "undefined") | |
301 { | 326 { |
302 var notification = webkitNotifications.createHTMLNotification("notification. html"); | 327 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
303 notification.show(); | 328 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) |
304 notification.addEventListener("close", prepareNotificationIconAndPopup); | 329 { |
330 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); | |
331 notification.show(); | |
332 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); | |
333 return; | |
334 } | |
335 | |
336 var texts = Notification.getLocalizedTexts(notification); | |
337 var title = texts.title ? texts.title : ""; | |
338 var message = texts.message ? texts.message.replace(new RegExp("<(a|\/a)>", 'g'), "") : ""; | |
Thomas Greiner
2014/02/18 16:44:25
You can just use the literal version (also don't f
saroyanm
2014/02/18 17:53:48
Done.
| |
339 var iconUrl = ext.getURL("icons/abp-128.png"); | |
340 if ("notifications" in ext) | |
341 { | |
342 var opt = { | |
343 type: "basic", | |
344 title: title, | |
345 message: message, | |
346 iconUrl: iconUrl, | |
347 buttons: [] | |
348 }; | |
349 var regex = /<a>(.*?)<\/a>/g; | |
350 while (regex.test(texts.message ? texts.message : "")) | |
Thomas Greiner
2014/02/18 16:44:25
Can you move this outside of the while loop?
saroyanm
2014/02/18 17:53:48
Done.
| |
351 opt.buttons.push({title: RegExp.$1}); | |
352 | |
353 var notification = ext.notifications; | |
354 notification.create("", opt, function() {}); | |
355 notification.onClosed.addListener(prepareNotificationIconAndPopup); | |
356 notification.onButtonClicked.addListener(notificationButtonClick); | |
357 } | |
358 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns) | |
359 { | |
360 var notification = webkitNotifications.createNotification(iconUrl, title, message); | |
361 notification.show(); | |
362 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); | |
363 notification.addEventListener("click", openNotificationLinks, false); | |
364 } | |
365 else | |
366 { | |
367 var notification = confirm(title + "\n" + message); | |
368 if (notification == true) | |
369 openNotificationLinks(); | |
370 } | |
305 } | 371 } |
306 else | 372 else |
307 prepareNotificationIconAndPopup(); | 373 prepareNotificationIconAndPopup(); |
308 } | 374 } |
309 | 375 |
310 ext.onMessage.addListener(function (msg, sender, sendResponse) | 376 ext.onMessage.addListener(function (msg, sender, sendResponse) |
311 { | 377 { |
312 switch (msg.type) | 378 switch (msg.type) |
313 { | 379 { |
314 case "get-selectors": | 380 case "get-selectors": |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 tab.sendMessage({type: "clickhide-deactivate"}); | 485 tab.sendMessage({type: "clickhide-deactivate"}); |
420 refreshIconAndContextMenu(tab); | 486 refreshIconAndContextMenu(tab); |
421 }); | 487 }); |
422 | 488 |
423 setTimeout(function() | 489 setTimeout(function() |
424 { | 490 { |
425 var notificationToShow = Notification.getNextToShow(); | 491 var notificationToShow = Notification.getNextToShow(); |
426 if (notificationToShow) | 492 if (notificationToShow) |
427 showNotification(notificationToShow); | 493 showNotification(notificationToShow); |
428 }, 3 * 60 * 1000); | 494 }, 3 * 60 * 1000); |
OLD | NEW |