Index: lib/url.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/lib/url.js |
@@ -0,0 +1,44 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2015 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * 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/>. |
+ */ |
+ |
+window.URL = (function() |
+{ |
+ let URL = window.URL || window.webkitURL; |
+ let URLproperties = ["href", "protocol", "host", "hostname", "port", "pathname", "search"]; |
Wladimir Palant
2015/01/21 15:33:44
Nit: This isn't proper camel case, should be URLPr
Sebastian Noack
2015/01/21 17:48:18
Done.
|
+ |
+ if (!URL || !URLproperties.every(prop => prop in new URL(""))) |
Wladimir Palant
2015/01/21 15:33:44
This will create seven URL instances, seems unnece
Sebastian Noack
2015/01/21 15:58:04
So what? This code runs only once, and an empty st
|
+ { |
+ let doc = document.implementation.createHTMLDocument(); |
+ |
+ let base = doc.createElement("base"); |
+ doc.head.appendChild(base); |
Wladimir Palant
2015/01/21 15:33:44
I was about to suggest using xml:base (wouldn't re
|
+ |
+ let anchor = doc.createElement("a"); |
+ doc.body.appendChild(anchor); |
+ |
+ URL = function(url, baseUrl) |
+ { |
+ base.href = baseUrl; |
Wladimir Palant
2015/01/21 15:33:44
This will stringify baseUrl, meaning typically ass
Sebastian Noack
2015/01/21 17:48:18
Done.
|
+ anchor.href = url; |
+ |
+ for (var prop of URLproperties) |
Wladimir Palant
2015/01/21 15:33:44
Nit: let prop?
Sebastian Noack
2015/01/21 17:48:18
Done.
|
+ this[prop] = anchor[prop]; |
+ }; |
+ } |
+ |
+ return URL; |
+})(); |