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

Side by Side Diff: subscriptionLink.postload.js

Issue 29336084: Issue 2426 - Open block.html as a popup window (Closed)
Patch Set: Rebased, replaced search param with proper messaging Created Feb. 17, 2016, 8:04 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
« safari/ext/background.js ('K') | « safari/ext/background.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 "use strict";
19
20 // In Chrome 37-40, the document_end content script (this one) runs properly,
21 // while the document_start content scripts (that defines ext) might not. Check
22 // whether variable ext exists before continuing to avoid
23 // "Uncaught ReferenceError: ext is not defined". See https://crbug.com/416907
24 if ("ext" in window && document instanceof HTMLDocument)
25 {
26 document.addEventListener("click", function(event)
27 {
28 // Ignore right-clicks
29 if (event.button == 2)
30 return;
31
32 // Search the link associated with the click
33 var link = event.target;
34 while (!(link instanceof HTMLAnchorElement))
35 {
36 link = link.parentNode;
37
38 if (!link)
39 return;
40 }
41
42 if (link.protocol == "http:" || link.protocol == "https:")
43 {
44 if (link.host != "subscribe.adblockplus.org" || link.pathname != "/")
45 return;
46 }
47 else if (!/^abp:\/*subscribe\/*\?/i.test(link.href))
48 return;
49
50 // This is our link - make sure the browser doesn't handle it
51 event.preventDefault();
52 event.stopPropagation();
53
54 // Decode URL parameters
55 var params = link.search.substr(1).split("&");
56 var title = null;
57 var url = null;
58 for (var i = 0; i < params.length; i++)
59 {
60 var parts = params[i].split("=", 2);
61 if (parts.length != 2 || !/\S/.test(parts[1]))
62 continue;
63 switch (parts[0])
64 {
65 case "title":
66 title = decodeURIComponent(parts[1]);
67 break;
68 case "location":
69 url = decodeURIComponent(parts[1]);
70 break;
71 }
72 }
73 if (!url)
74 return;
75
76 // Default title to the URL
77 if (!title)
78 title = url;
79
80 // Trim spaces in title and URL
81 title = title.trim();
82 url = url.trim();
83 if (!/^(https?|ftp):/.test(url))
84 return;
85
86 ext.backgroundPage.sendMessage({
87 type: "add-subscription",
88 title: title,
89 url: url
90 });
91 }, true);
92 }
OLDNEW
« safari/ext/background.js ('K') | « safari/ext/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld