| OLD | NEW |
| (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 (function(global) | |
| 19 { | |
| 20 "use strict"; | |
| 21 | |
| 22 var URLProperties = ["href", "protocol", "hostname", | |
| 23 "host", "pathname", "search"]; | |
| 24 | |
| 25 // Chrome <35 and Safari 6 used the non-standard name webkitURL | |
| 26 var URL = global.URL || global.webkitURL; | |
| 27 | |
| 28 // Chrome <32 didn't implement any of those properties | |
| 29 function hasProperties() | |
| 30 { | |
| 31 var dummy = new URL("about:blank"); | |
| 32 for (var i = 0; i < URLProperties.length; i++) | |
| 33 if (!(URLProperties[i] in dummy)) | |
| 34 return false; | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 if (!URL || !hasProperties()) | |
| 39 { | |
| 40 var doc = document.implementation.createHTMLDocument(); | |
| 41 | |
| 42 var base = doc.createElement("base"); | |
| 43 doc.head.appendChild(base); | |
| 44 | |
| 45 var anchor = doc.createElement("a"); | |
| 46 doc.body.appendChild(anchor); | |
| 47 | |
| 48 URL = function(url, baseUrl) | |
| 49 { | |
| 50 if (baseUrl instanceof URL) | |
| 51 base.href = baseUrl.href; | |
| 52 else | |
| 53 base.href = baseUrl || ""; | |
| 54 anchor.href = url; | |
| 55 | |
| 56 for (var i = 0; i < URLProperties.length; i++) | |
| 57 { | |
| 58 var prop = URLProperties[i]; | |
| 59 this[prop] = anchor[prop]; | |
| 60 } | |
| 61 }; | |
| 62 } | |
| 63 | |
| 64 global.URL = URL; | |
| 65 })(this); | |
| OLD | NEW |