Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: subscriptionLink.postload.js

Issue 29452181: Noissue - Merge current tip to Edge bookmark (Closed)
Patch Set: Created May 30, 2017, 3:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « stats.js ('k') | utils.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2017 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 *
(...skipping 18 matching lines...) Expand all
32 // Search the link associated with the click 32 // Search the link associated with the click
33 let 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 let queryString = null;
42 if (link.protocol == "http:" || link.protocol == "https:") 43 if (link.protocol == "http:" || link.protocol == "https:")
43 { 44 {
44 if (link.host != "subscribe.adblockplus.org" || link.pathname != "/") 45 if (link.host == "subscribe.adblockplus.org" && link.pathname == "/")
45 return; 46 queryString = link.search.substr(1);
46 } 47 }
47 else if (!/^abp:\/*subscribe\/*\?/i.test(link.href)) 48 else
49 {
50 // Firefox 51 doesn't seem to populate the "search" property for
51 // links with non-standard URL schemes so we need to extract the query
52 // string manually.
53 let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
54 if (match)
55 queryString = match[1];
56 }
57
58 if (!queryString)
48 return; 59 return;
49 60
50 // This is our link - make sure the browser doesn't handle it 61 // This is our link - make sure the browser doesn't handle it
51 event.preventDefault(); 62 event.preventDefault();
52 event.stopPropagation(); 63 event.stopPropagation();
53 64
54 // Decode URL parameters 65 // Decode URL parameters
55 let title = null; 66 let title = null;
56 let url = null; 67 let url = null;
57 for (let param of link.search.substr(1).split("&")) 68 for (let param of queryString.split("&"))
58 { 69 {
59 let parts = param.split("=", 2); 70 let parts = param.split("=", 2);
60 if (parts.length != 2 || !/\S/.test(parts[1])) 71 if (parts.length != 2 || !/\S/.test(parts[1]))
61 continue; 72 continue;
62 switch (parts[0]) 73 switch (parts[0])
63 { 74 {
64 case "title": 75 case "title":
65 title = decodeURIComponent(parts[1]); 76 title = decodeURIComponent(parts[1]);
66 break; 77 break;
67 case "location": 78 case "location":
68 url = decodeURIComponent(parts[1]); 79 url = decodeURIComponent(parts[1]);
69 break; 80 break;
70 } 81 }
71 } 82 }
72 if (!url) 83 if (!url)
73 return; 84 return;
74 85
75 // Default title to the URL 86 // Default title to the URL
76 if (!title) 87 if (!title)
77 title = url; 88 title = url;
78 89
79 // Trim spaces in title and URL 90 // Trim spaces in title and URL
80 title = title.trim(); 91 title = title.trim();
81 url = url.trim(); 92 url = url.trim();
82 if (!/^(https?|ftp):/.test(url)) 93 if (!/^(https?|ftp):/.test(url))
83 return; 94 return;
84 95
85 ext.backgroundPage.sendMessage({ 96 ext.backgroundPage.sendMessage({
86 type: "subscriptions.add", 97 type: "subscriptions.add",
87 title: title, 98 title,
88 url: url, 99 url,
89 confirm: true 100 confirm: true
90 }); 101 });
91 }, true); 102 }, true);
92 } 103 }
OLDNEW
« no previous file with comments | « stats.js ('k') | utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld