polyfill

Firefox、Opera、Google Chrome向けのpolyfillです。

目前为 2016-03-11 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/17895/112591/polyfill.js

// ==UserScript==
// @name        polyfill
// @version     1.0.0
// @description Firefox、Opera、Google Chrome向けのpolyfillです。
// @compatible  Firefox
// @compatible  Opera 36以降
// @compatible  Chrome
// @author      100の人
// @homepage    https://gf.qytechs.cn/users/137
// @license     Mozilla Public License Version 2.0 (MPL 2.0); https://www.mozilla.org/MPL/2.0/
// ==/UserScript==

(function () {
'use strict';

// Polyfill for Firefox, Opera, and Google Chrome
if (new URLSearchParams('?').has('?')) {
	URLSearchParams = new Proxy(URLSearchParams, {
		construct: function (URLSearchParams, argumentsList) {
			if (argumentsList.length > 0 && !(argumentsList[0] instanceof URLSearchParams)) {
				argumentsList[0] = String(argumentsList[0]).replace(/^\?/, '');
			}
			return new URLSearchParams(...argumentsList);
		},
	});
}
	
// Polyfill for Opera and Google Chrome
if (!(Symbol.iterator in NodeList.prototype)) {
	Object.defineProperties(NodeList.prototype, /** @lends NodeList# */ {
		/**
		 * @see [Issue 401699 - chromium - Add iterator support to NodeList and friends]{@link https://code.google.com/p/chromium/issues/detail?id=401699}
		 * @returns {Iterator.<Array.<number, Node>>}
		 * @name NodeList#@@iterator
		 */
		[Symbol.iterator]: {
			writable: true,
			enumerable: false,
			configurable: true,
			value: function* () {
				for (var i = 0, l = this.length; i < l; i++) {
					yield this[i];
				}
			}
		},
		/**
		 * @param {Function} callback
		 * @param {*} thisArg
		 * @function
		 */
		forEach: {
			writable: true,
			enumerable: true,
			configurable: true,
			value: Array.prototype.forEach
		},
		/**
		 * @returns {Iterator.<Array.<number, Node>>}
		 * @function
		 */
		entries: {
			writable: true,
			enumerable: true,
			configurable: true,
			value: function* () {
				for (var i = 0, l = this.length; i < l; i++) {
					yield [i, this[i]];
				}
			}
		},
		/**
		 * @returns {Iterator.<number>}
		 * @function
		 */
		keys: {
			writable: true,
			enumerable: true,
			configurable: true,
			value: function* () {
				for (var i = 0, l = this.length; i < l; i++) {
					yield i;
				}
			}
		},
		/**
		 * @returns {Iterator.<Node>}
		 * @function
		 */
		values: {
			writable: true,
			enumerable: true,
			configurable: true,
			value: function* () {
				for (var i = 0, l = this.length; i < l; i++) {
					yield this[i];
				}
			}
		},
	});
}

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址