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

Unified Diff: lib/subscriptionLink.js

Issue 29531677: Issue 5599 - ext needs to be defined in the postload script (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: New approach as discussed in the bug Created Sept. 1, 2017, 8:37 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/subscriptionLink.js
===================================================================
rename from subscriptionLink.postload.js
rename to lib/subscriptionLink.js
--- a/subscriptionLink.postload.js
+++ b/lib/subscriptionLink.js
@@ -12,92 +12,97 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
-if (document instanceof HTMLDocument)
+function setupSubscriptionLink()
{
- document.addEventListener("click", event =>
+ if (document instanceof HTMLDocument)
{
- // Ignore right-clicks
- if (event.button == 2)
- return;
+ document.addEventListener("click", event =>
+ {
+ // Ignore right-clicks
+ if (event.button == 2)
+ return;
- // Ignore simulated clicks.
- if (event.isTrusted == false)
- return;
-
- // Search the link associated with the click
- let link = event.target;
- while (!(link instanceof HTMLAnchorElement))
- {
- link = link.parentNode;
-
- if (!link)
+ // Ignore simulated clicks.
+ if (event.isTrusted == false)
return;
- }
+
+ // Search the link associated with the click
+ let link = event.target;
+ while (!(link instanceof HTMLAnchorElement))
+ {
+ link = link.parentNode;
+
+ if (!link)
+ return;
+ }
- let queryString = null;
- if (link.protocol == "http:" || link.protocol == "https:")
- {
- if (link.host == "subscribe.adblockplus.org" && link.pathname == "/")
- queryString = link.search.substr(1);
- }
- else
- {
- // Firefox 51 doesn't seem to populate the "search" property for
- // links with non-standard URL schemes so we need to extract the query
- // string manually.
- let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
- if (match)
- queryString = match[1];
- }
+ let queryString = null;
+ if (link.protocol == "http:" || link.protocol == "https:")
+ {
+ if (link.host == "subscribe.adblockplus.org" && link.pathname == "/")
+ queryString = link.search.substr(1);
+ }
+ else
+ {
+ // Firefox 51 doesn't seem to populate the "search" property for
+ // links with non-standard URL schemes so we need to extract the query
+ // string manually.
+ let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
+ if (match)
+ queryString = match[1];
+ }
- if (!queryString)
- return;
+ if (!queryString)
+ return;
- // This is our link - make sure the browser doesn't handle it
- event.preventDefault();
- event.stopPropagation();
+ // This is our link - make sure the browser doesn't handle it
+ event.preventDefault();
+ event.stopPropagation();
- // Decode URL parameters
- let title = null;
- let url = null;
- for (let param of queryString.split("&"))
- {
- let parts = param.split("=", 2);
- if (parts.length != 2 || !/\S/.test(parts[1]))
- continue;
- switch (parts[0])
+ // Decode URL parameters
+ let title = null;
+ let url = null;
+ for (let param of queryString.split("&"))
{
- case "title":
- title = decodeURIComponent(parts[1]);
- break;
- case "location":
- url = decodeURIComponent(parts[1]);
- break;
+ let parts = param.split("=", 2);
+ if (parts.length != 2 || !/\S/.test(parts[1]))
+ continue;
+ switch (parts[0])
+ {
+ case "title":
+ title = decodeURIComponent(parts[1]);
+ break;
+ case "location":
+ url = decodeURIComponent(parts[1]);
+ break;
+ }
}
- }
- if (!url)
- return;
+ if (!url)
+ return;
- // Default title to the URL
- if (!title)
- title = url;
+ // Default title to the URL
+ if (!title)
+ title = url;
- // Trim spaces in title and URL
- title = title.trim();
- url = url.trim();
- if (!/^(https?|ftp):/.test(url))
- return;
+ // Trim spaces in title and URL
+ title = title.trim();
+ url = url.trim();
+ if (!/^(https?|ftp):/.test(url))
+ return;
- ext.backgroundPage.sendMessage({
- type: "subscriptions.add",
- title,
- url,
- confirm: true
- });
- }, true);
+ ext.backgroundPage.sendMessage({
+ type: "subscriptions.add",
+ title,
+ url,
+ confirm: true
+ });
+ }, true);
+ }
}
+
+exports.setupSubscriptionLink = setupSubscriptionLink;

Powered by Google App Engine
This is Rietveld