OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 if (document instanceof HTMLDocument) | 20 if (document instanceof HTMLDocument) |
21 { | 21 { |
22 document.addEventListener("click", function(event) | 22 document.addEventListener("click", event => |
23 { | 23 { |
24 // Ignore right-clicks | 24 // Ignore right-clicks |
25 if (event.button == 2) | 25 if (event.button == 2) |
26 return; | 26 return; |
27 | 27 |
28 // Ignore simulated clicks. | 28 // Ignore simulated clicks. |
29 if (event.isTrusted == false) | 29 if (event.isTrusted == false) |
30 return; | 30 return; |
31 | 31 |
32 // Search the link associated with the click | 32 // Search the link associated with the click |
33 var link = event.target; | 33 let link = event.target; |
34 while (!(link instanceof HTMLAnchorElement)) | 34 while (!(link instanceof HTMLAnchorElement)) |
35 { | 35 { |
36 link = link.parentNode; | 36 link = link.parentNode; |
37 | 37 |
38 if (!link) | 38 if (!link) |
39 return; | 39 return; |
40 } | 40 } |
41 | 41 |
42 if (link.protocol == "http:" || link.protocol == "https:") | 42 if (link.protocol == "http:" || link.protocol == "https:") |
43 { | 43 { |
44 if (link.host != "subscribe.adblockplus.org" || link.pathname != "/") | 44 if (link.host != "subscribe.adblockplus.org" || link.pathname != "/") |
45 return; | 45 return; |
46 } | 46 } |
47 else if (!/^abp:\/*subscribe\/*\?/i.test(link.href)) | 47 else if (!/^abp:\/*subscribe\/*\?/i.test(link.href)) |
48 return; | 48 return; |
49 | 49 |
50 // This is our link - make sure the browser doesn't handle it | 50 // This is our link - make sure the browser doesn't handle it |
51 event.preventDefault(); | 51 event.preventDefault(); |
52 event.stopPropagation(); | 52 event.stopPropagation(); |
53 | 53 |
54 // Decode URL parameters | 54 // Decode URL parameters |
55 var params = link.search.substr(1).split("&"); | 55 let title = null; |
56 var title = null; | 56 let url = null; |
57 var url = null; | 57 for (let param of link.search.substr(1).split("&")) |
58 for (var i = 0; i < params.length; i++) | |
59 { | 58 { |
60 var parts = params[i].split("=", 2); | 59 let parts = param.split("=", 2); |
61 if (parts.length != 2 || !/\S/.test(parts[1])) | 60 if (parts.length != 2 || !/\S/.test(parts[1])) |
62 continue; | 61 continue; |
63 switch (parts[0]) | 62 switch (parts[0]) |
64 { | 63 { |
65 case "title": | 64 case "title": |
66 title = decodeURIComponent(parts[1]); | 65 title = decodeURIComponent(parts[1]); |
67 break; | 66 break; |
68 case "location": | 67 case "location": |
69 url = decodeURIComponent(parts[1]); | 68 url = decodeURIComponent(parts[1]); |
70 break; | 69 break; |
(...skipping 13 matching lines...) Expand all Loading... |
84 return; | 83 return; |
85 | 84 |
86 ext.backgroundPage.sendMessage({ | 85 ext.backgroundPage.sendMessage({ |
87 type: "subscriptions.add", | 86 type: "subscriptions.add", |
88 title: title, | 87 title: title, |
89 url: url, | 88 url: url, |
90 confirm: true | 89 confirm: true |
91 }); | 90 }); |
92 }, true); | 91 }, true); |
93 } | 92 } |
OLD | NEW |