LEFT | RIGHT |
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 |
(...skipping 25 matching lines...) Expand all Loading... |
36 // Search the link associated with the click | 36 // Search the link associated with the click |
37 var link = event.target; | 37 var link = event.target; |
38 while (!(link instanceof HTMLAnchorElement)) | 38 while (!(link instanceof HTMLAnchorElement)) |
39 { | 39 { |
40 link = link.parentNode; | 40 link = link.parentNode; |
41 | 41 |
42 if (!link) | 42 if (!link) |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
| 46 let queryString = null; |
46 if (link.protocol == "http:" || link.protocol == "https:") | 47 if (link.protocol == "http:" || link.protocol == "https:") |
47 { | 48 { |
48 if (link.host != "subscribe.adblockplus.org" || link.pathname != "/") | 49 if (link.host == "subscribe.adblockplus.org" && link.pathname == "/") |
49 return; | 50 queryString = link.search.substr(1); |
50 } | 51 } |
51 else if (!/^abp:\/*subscribe\/*\?/i.test(link.href)) | 52 else |
| 53 { |
| 54 // Old versions of Chrome (30) don't populate the "search" property for |
| 55 // links with non-standard URL schemes so we need to extract the query |
| 56 // string manually. |
| 57 let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href); |
| 58 if (match) |
| 59 queryString = match[1]; |
| 60 } |
| 61 |
| 62 if (!queryString) |
52 return; | 63 return; |
53 | 64 |
54 // This is our link - make sure the browser doesn't handle it | 65 // This is our link - make sure the browser doesn't handle it |
55 event.preventDefault(); | 66 event.preventDefault(); |
56 event.stopPropagation(); | 67 event.stopPropagation(); |
57 | 68 |
58 // Decode URL parameters (Note: Old versions of Chrome (30) don't populate | 69 // Decode URL parameters |
59 // link.search here so we have to grab the search part of the URL manually.) | 70 var params = queryString.split("&"); |
60 var params = link.href.substr(link.href.indexOf("?") + 1).split("&"); | |
61 var title = null; | 71 var title = null; |
62 var url = null; | 72 var url = null; |
63 for (var i = 0; i < params.length; i++) | 73 for (var i = 0; i < params.length; i++) |
64 { | 74 { |
65 var parts = params[i].split("=", 2); | 75 var parts = params[i].split("=", 2); |
66 if (parts.length != 2 || !/\S/.test(parts[1])) | 76 if (parts.length != 2 || !/\S/.test(parts[1])) |
67 continue; | 77 continue; |
68 switch (parts[0]) | 78 switch (parts[0]) |
69 { | 79 { |
70 case "title": | 80 case "title": |
(...skipping 18 matching lines...) Expand all Loading... |
89 return; | 99 return; |
90 | 100 |
91 ext.backgroundPage.sendMessage({ | 101 ext.backgroundPage.sendMessage({ |
92 type: "subscriptions.add", | 102 type: "subscriptions.add", |
93 title: title, | 103 title: title, |
94 url: url, | 104 url: url, |
95 confirm: true | 105 confirm: true |
96 }); | 106 }); |
97 }, true); | 107 }, true); |
98 } | 108 } |
LEFT | RIGHT |