PageSourceSearch

https://www.tsemtulku.com/wp-content/plugins/raven/assets/lib/url-polyfill/url-polyfill.js?ver=1.1.7

js tsemtulku.com collected 2026-09-25 00:41:00 UTC 13,307 bytes, 483 lines download raw bytes

vendor: 13,307 bytes, lines 1-483
1(function(global) {
2  /**
3   * Polyfill URLSearchParams
4   *
5   * Inspired from : https://github.com/WebReflection/url-search-params/blob/master/src/url-search-params.js
6   */
7
8  var checkIfIteratorIsSupported = function() {
9    try {
10      return !!Symbol.iterator;
11    } catch (error) {
12      return false;
13    }
14  };
15
16
17  var iteratorSupported = checkIfIteratorIsSupported();
18
19  var createIterator = function(items) {
20    var iterator = {
21      next: function() {
22        var value = items.shift();
23        return { done: value === void 0, value: value };
24      }
25    };
26
27    if (iteratorSupported) {
28      iterator[Symbol.iterator] = function() {
29        return iterator;
30      };
31    }
32
33    return iterator;
34  };
35
36  /**
37   * Search param name and values should be encoded according to https://url.spec.whatwg.org/#urlencoded-serializing
38   * encodeURIComponent() produces the same result except encoding spaces as `%20` instead of `+`.
39   */
40  var serializeParam = function(value) {
41    return encodeURIComponent(value).replace(/%20/g, '+');
42  };
43
44  var deserializeParam = function(value) {
45    return decodeURIComponent(String(value).replace(/\+/g, ' '));
46  };
47
48  var polyfillURLSearchParams = function() {
49
50    var URLSearchParams = function(searchString) {
51      Object.defineProperty(this, '_entries', { writable: true, value: {} });
52      var typeofSearchString = typeof searchString;
53
54      if (typeofSearchString === 'undefined') {
55        // do nothing
56      } else if (typeofSearchString === 'string') {
57        if (searchString !== '') {
58          this._fromString(searchString);
59        }
60      } else if (searchString instanceof URLSearchParams) {
61        var _this = this;
62        searchString.forEach(function(value, name) {
63          _this.append(name, value);
64        });
65      } else if ((searchString !== null) && (typeofSearchString === 'object')) {
66        if (Object.prototype.toString.call(searchString) === '[object Array]') {
67          for (var i = 0; i < searchString.length; i++) {
68            var entry = searchString[i];
69            if ((Object.prototype.toString.call(entry) === '[object Array]') || (entry.length !== 2)) {
70              this.append(entry[0], entry[1]);
71            } else {
72              throw new TypeError('Expected [string, any] as entry at index ' + i + ' of URLSearchParams\'s input');
73            }
74          }
75        } else {
76          for (var key in searchString) {
77            if (searchString.hasOwnProperty(key)) {
78              this.append(key, searchString[key]);
79            }
80          }
81        }
82      } else {
83        throw new TypeError('Unsupported input\'s type for URLSearchParams');
84      }
85    };
86
87    var proto = URLSearchParams.prototype;
88
89    proto.append = function(name, value) {
90      if (name in this._entries) {
91        this._entries[name].push(String(value));
92      } else {
93        this._entries[name] = [String(value)];
94      }
95    };
96
97    proto.delete = function(name) {
98      delete this._entries[name];
99    };
100
101    proto.get = function(name) {
102      return (name in this._entries) ? this._entries[name][0] : null;
103    };
104
105    proto.getAll = function(name) {
106      return (name in this._entries) ? this._entries[name].slice(0) : [];
107    };
108
109    proto.has = function(name) {
110      return (name in this._entries);
111    };
112
113    proto.set = function(name, value) {
114      this._entries[name] = [String(value)];
115    };
116
117    proto.forEach = function(callback, thisArg) {
118      var entries;
119      for (var name in this._entries) {
120        if (this._entries.hasOwnProperty(name)) {
121          entries = this._entries[name];
122          for (var i = 0; i < entries.length; i++) {
123            callback.call(thisArg, entries[i], name, this);
124          }
125        }
126      }
127    };
128
129    proto.keys = function() {
130      var items = [];
131      this.forEach(function(value, name) {
132        items.push(name);
133      });
134      return createIterator(items);
135    };
136
137    proto.values = function() {
138      var items = [];
139      this.forEach(function(value) {
140        items.push(value);
141      });
142      return createIterator(items);
143    };
144
145    proto.entries = function() {
146      var items = [];
147      this.forEach(function(value, name) {
148        items.push([name, value]);
149      });
150      return createIterator(items);
151    };
152
153    if (iteratorSupported) {
154      proto[Symbol.iterator] = proto.entries;
155    }
156
157    proto.toString = function() {
158      var searchArray = [];
159      this.forEach(function(value, name) {
160        searchArray.push(serializeParam(name) + '=' + serializeParam(value));
161      });
162      return searchArray.join('&');
163    };
164
165
166    global.URLSearchParams = URLSearchParams;
167  };
168
169  var checkIfURLSearchParamsSupported = function() {
170    try {
171      var URLSearchParams = global.URLSearchParams;
172
173      return (new URLSearchParams('?a=1').toString() === 'a=1') && (typeof URLSearchParams.prototype.set === 'function');
174    } catch (e) {
175      return false;
176    }
177  };
178
179  if (!checkIfURLSearchParamsSupported()) {
180    polyfillURLSearchParams();
181  }
182
183  var proto = global.URLSearchParams.prototype;
184
185  if (typeof proto.sort !== 'function') {
186    proto.sort = function() {
187      var _this = this;
188      var items = [];
189      this.forEach(function(value, name) {
190        items.push([name, value]);
191        if (!_this._entries) {
192          _this.delete(name);
193        }
194      });
195      items.sort(function(a, b) {
196        if (a[0] < b[0]) {
197          return -1;
198        } else if (a[0] > b[0]) {
199          return +1;
200        } else {
201          return 0;
202        }
203      });
204      if (_this._entries) { // force reset because IE keeps keys index
205        _this._entries = {};
206      }
207      for (var i = 0; i < items.length; i++) {
208        this.append(items[i][0], items[i][1]);
209      }
210    };
211  }
212
213  if (typeof proto._fromString !== 'function') {
214    Object.defineProperty(proto, '_fromString', {
215      enumerable: false,
216      configurable: false,
217      writable: false,
218      value: function(searchString) {
219        if (this._entries) {
220          this._entries = {};
221        } else {
222          var keys = [];
223          this.forEach(function(value, name) {
224            keys.push(name);
225          });
226          for (var i = 0; i < keys.length; i++) {
227            this.delete(keys[i]);
228          }
229        }
230
231        searchString = searchString.replace(/^\?/, '');
232        var attributes = searchString.split('&');
233        var attribute;
234        for (var i = 0; i < attributes.length; i++) {
235          attribute = attributes[i].split('=');
236          this.append(
237            deserializeParam(attribute[0]),
238            (attribute.length > 1) ? deserializeParam(attribute[1]) : ''
239          );
240        }
241      }
242    });
243  }
244
245  // HTMLAnchorElement
246
247})(
248  (typeof global !== 'undefined') ? global
249    : ((typeof window !== 'undefined') ? window
250    : ((typeof self !== 'undefined') ? self : this))
251);
252
253(function(global) {
254  /**
255   * Polyfill URL
256   *
257   * Inspired from : https://github.com/arv/DOM-URL-Polyfill/blob/master/src/url.js
258   */
259
260  var checkIfURLIsSupported = function() {
261    try {
262      var u = new global.URL('b', 'http://a');
263      u.pathname = 'c%20d';
264      return (u.href === 'http://a/c%20d') && u.searchParams;
265    } catch (e) {
266      return false;
267    }
268  };
269
270
271  var polyfillURL = function() {
272    var _URL = global.URL;
273
274    var URL = function(url, base) {
275      if (typeof url !== 'string') url = String(url);
276
277      // Only create another document if the base is different from current location.
278      var doc = document, baseElement;
279      if (base && (global.location === void 0 || base !== global.location.href)) {
280        doc = document.implementation.createHTMLDocument('');
281        baseElement = doc.createElement('base');
282        baseElement.href = base;
283        doc.head.appendChild(baseElement);
284        try {
285          if (baseElement.href.indexOf(base) !== 0) throw new Error(baseElement.href);
286        } catch (err) {
287          throw new Error('URL unable to set base ' + base + ' due to ' + err);
288        }
289      }
290
291      var anchorElement = doc.createElement('a');
292      anchorElement.href = url;
293      if (baseElement) {
294        doc.body.appendChild(anchorElement);
295        anchorElement.href = anchorElement.href; // force href to refresh
296      }
297
298      if (anchorElement.protocol === ':' || !/:/.test(anchorElement.href)) {
299        throw new TypeError('Invalid URL');
300      }
301
302      Object.defineProperty(this, '_anchorElement', {
303        value: anchorElement
304      });
305
306
307      // create a linked searchParams which reflect its changes on URL
308      var searchParams = new global.URLSearchParams(this.search);
309      var enableSearchUpdate = true;
310      var enableSearchParamsUpdate = true;
311      var _this = this;
312      ['append', 'delete', 'set'].forEach(function(methodName) {
313        var method = searchParams[methodName];
314        searchParams[methodName] = function() {
315          method.apply(searchParams, arguments);
316          if (enableSearchUpdate) {
317            enableSearchParamsUpdate = false;
318            _this.search = searchParams.toString();
319            enableSearchParamsUpdate = true;
320          }
321        };
322      });
323
324      Object.defineProperty(this, 'searchParams', {
325        value: searchParams,
326        enumerable: true
327      });
328
329      var search = void 0;
330      Object.defineProperty(this, '_updateSearchParams', {
331        enumerable: false,
332        configurable: false,
333        writable: false,
334        value: function() {
335          if (this.search !== search) {
336            search = this.search;
337            if (enableSearchParamsUpdate) {
338              enableSearchUpdate = false;
339              this.searchParams._fromString(this.search);
340              enableSearchUpdate = true;
341            }
342          }
343        }
344      });
345    };
346
347    var proto = URL.prototype;
348
349    var linkURLWithAnchorAttribute = function(attributeName) {
350      Object.defineProperty(proto, attributeName, {
351        get: function() {
352          return this._anchorElement[attributeName];
353        },
354        set: function(value) {
355          this._anchorElement[attributeName] = value;
356        },
357        enumerable: true
358      });
359    };
360
361    ['hash', 'host', 'hostname', 'port', 'protocol']
362      .forEach(function(attributeName) {
363        linkURLWithAnchorAttribute(attributeName);
364      });
365
366    Object.defineProperty(proto, 'search', {
367      get: function() {
368        return this._anchorElement['search'];
369      },
370      set: function(value) {
371        this._anchorElement['search'] = value;
372        this._updateSearchParams();
373      },
374      enumerable: true
375    });
376
377    Object.defineProperties(proto, {
378
379      'toString': {
380        get: function() {
381          var _this = this;
382          return function() {
383            return _this.href;
384          };
385        }
386      },
387
388      'href': {
389        get: function() {
390          return this._anchorElement.href.replace(/\?$/, '');
391        },
392        set: function(value) {
393          this._anchorElement.href = value;
394          this._updateSearchParams();
395        },
396        enumerable: true
397      },
398
399      'pathname': {
400        get: function() {
401          return this._anchorElement.pathname.replace(/(^\/?)/, '/');
402        },
403        set: function(value) {
404          this._anchorElement.pathname = value;
405        },
406        enumerable: true
407      },
408
409      'origin': {
410        get: function() {
411          // get expected port from protocol
412          var expectedPort = { 'http:': 80, 'https:': 443, 'ftp:': 21 }[this._anchorElement.protocol];
413          // add port to origin if, expected port is different than actual port
414          // and it is not empty f.e http://foo:8080
415          // 8080 != 80 && 8080 != ''
416          var addPortToOrigin = this._anchorElement.port != expectedPort &&
417            this._anchorElement.port !== '';
418
419          return this._anchorElement.protocol +
420            '//' +
421            this._anchorElement.hostname +
422            (addPortToOrigin ? (':' + this._anchorElement.port) : '');
423        },
424        enumerable: true
425      },
426
427      'password': { // TODO
428        get: function() {
429          return '';
430        },
431        set: function(value) {
432        },
433        enumerable: true
434      },
435
436      'username': { // TODO
437        get: function() {
438          return '';
439        },
440        set: function(value) {
441        },
442        enumerable: true
443      },
444    });
445
446    URL.createObjectURL = function(blob) {
447      return _URL.createObjectURL.apply(_URL, arguments);
448    };
449
450    URL.revokeObjectURL = function(url) {
451      return _URL.revokeObjectURL.apply(_URL, arguments);
452    };
453
454    global.URL = URL;
455
456  };
457
458  if (!checkIfURLIsSupported()) {
459    polyfillURL();
460  }
461
462  if ((global.location !== void 0) && !('origin' in global.location)) {
463    var getOrigin = function() {
464      return global.location.protocol + '//' + global.location.hostname + (global.location.port ? (':' + global.location.port) : '');
465    };
466
467    try {
468      Object.defineProperty(global.location, 'origin', {
469        get: getOrigin,
470        enumerable: true
471      });
472    } catch (e) {
473      setInterval(function() {
474        global.location.origin = getOrigin();
475      }, 100);
476    }
477  }
478
479})(
480  (typeof global !== 'undefined') ? global
481    : ((typeof window !== 'undefined') ? window
482    : ((typeof self !== 'undefined') ? self : this))
483);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.