你现在正在访问的是萌娘百科用于保存和管理图片、音频等媒体文件的子项目萌娘共享,想要回到萌娘百科,请使用浏览器上的返回按钮、或点击这里
MediaWiki:Gadget-libPolyfill-String.prototype.at.js
AnnAngela-dbot(讨论 | 贡献)2024年1月23日 (二) 10:22的版本 (代码变动: 40592b0 - feat: 新版 polyfill 生成机制 (#410) by U:AnnAngela, co-authored-by: GH:github-actions[bot])
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
/** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/libPolyfill/MediaWiki:Gadget-libPolyfill-String.prototype.at.js|user=[[U:AnnAngela]]|co-authors=GH:github-actions[bot]|longId=40592b0b722ca3f6e5a448a8847015ae96151e5e|shortId=40592b0|summary=feat: 新版 polyfill 生成机制 (#410)|body=<nowiki>Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}'; /* <pre> */ "use strict"; (function () { if (!("at" in String.prototype)) { if (!("defineProperty" in Object && function () { try { var e = {}; return Object.defineProperty(e, "test", { value: 42 }), !0; } catch (t) { return !1; } }())) { (function (nativeDefineProperty) { var supportsAccessors = Object.prototype.hasOwnProperty.call(Object.prototype, '__defineGetter__'); var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine'; var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value'; Object.defineProperty = function defineProperty(object, property, descriptor) { if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) { return nativeDefineProperty(object, property, descriptor); } if (object === null || !(object instanceof Object || typeof object === 'object')) { throw new TypeError('Object.defineProperty called on non-object'); } if (!(descriptor instanceof Object)) { throw new TypeError('Property description must be an object'); } var propertyString = String(property); var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor; var getterType = 'get' in descriptor && typeof descriptor.get; var setterType = 'set' in descriptor && typeof descriptor.set; if (getterType) { if (getterType === undefined) { return object; } if (getterType !== 'function') { throw new TypeError('Getter must be a function'); } if (!supportsAccessors) { throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); } if (hasValueOrWritable) { throw new TypeError(ERR_VALUE_ACCESSORS); } Object.__defineGetter__.call(object, propertyString, descriptor.get); } else { object[propertyString] = descriptor.value; } if (setterType) { if (setterType === undefined) { return object; } if (setterType !== 'function') { throw new TypeError('Setter must be a function'); } if (!supportsAccessors) { throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); } if (hasValueOrWritable) { throw new TypeError(ERR_VALUE_ACCESSORS); } Object.__defineSetter__.call(object, propertyString, descriptor.set); } if ('value' in descriptor) { object[propertyString] = descriptor.value; } return object; }; }(Object.defineProperty)); } function CreateMethodProperty(O, P, V) { var newDesc = { value: V, writable: true, enumerable: false, configurable: true }; Object.defineProperty(O, P, newDesc); } function RequireObjectCoercible(argument) { if (argument === null || argument === undefined) { throw TypeError(Object.prototype.toString.call(argument) + ' is not coercible to Object.'); } return argument; } function ToNumber(argument) { return Number(argument); } function ToIntegerOrInfinity(argument) { var number = ToNumber(argument); if (isNaN(number) || number === 0 || 1 / number === -Infinity) return 0; if (number === Infinity) return Infinity; if (number === -Infinity) return -Infinity; var integer = Math.floor(Math.abs(number)); if (number < 0) integer = -integer; return integer; } function Call(F, V) { var argumentsList = arguments.length > 2 ? arguments[2] : []; if (IsCallable(F) === false) { throw new TypeError(Object.prototype.toString.call(F) + 'is not a function.'); } return F.apply(V, argumentsList); } function ToObject(argument) { if (argument === null || argument === undefined) { throw TypeError(); } return Object(argument); } function GetV(v, p) { var o = ToObject(v); return o[p]; } function IsCallable(argument) { return typeof argument === 'function'; } function GetMethod(V, P) { var func = GetV(V, P); if (func === null || func === undefined) { return undefined; } if (IsCallable(func) === false) { throw new TypeError('Method not callable: ' + P); } return func; } function Get(O, P) { return O[P]; } function Type(x) { switch (typeof x) { case 'undefined': return 'undefined'; case 'boolean': return 'boolean'; case 'number': return 'number'; case 'string': return 'string'; case 'symbol': return 'symbol'; default: if (x === null) return 'null'; if ('Symbol' in self && (x instanceof self.Symbol || x.constructor === self.Symbol)) return 'symbol'; return 'object'; } } function OrdinaryToPrimitive(O, hint) { if (hint === 'string') { var methodNames = ['toString', 'valueOf']; } else { methodNames = ['valueOf', 'toString']; } for (var i = 0; i < methodNames.length; ++i) { var name = methodNames[i]; var method = Get(O, name); if (IsCallable(method)) { var result = Call(method, O); if (Type(result) !== 'object') { return result; } } } throw new TypeError('Cannot convert to primitive.'); } function ToPrimitive(input) { var PreferredType = arguments.length > 1 ? arguments[1] : undefined; if (Type(input) === 'object') { if (arguments.length < 2) { var hint = 'default'; } else if (PreferredType === String) { hint = 'string'; } else if (PreferredType === Number) { hint = 'number'; } var exoticToPrim = typeof self.Symbol === 'function' && typeof self.Symbol.toPrimitive === 'symbol' ? GetMethod(input, self.Symbol.toPrimitive) : undefined; if (exoticToPrim !== undefined) { var result = Call(exoticToPrim, input, [hint]); if (Type(result) !== 'object') { return result; } throw new TypeError('Cannot convert exotic object to primitive.'); } if (hint === 'default') { hint = 'number'; } return OrdinaryToPrimitive(input, hint); } return input; } function ToString(argument) { switch (Type(argument)) { case 'symbol': throw new TypeError('Cannot convert a Symbol value to a string'); case 'object': var primValue = ToPrimitive(argument, String); return ToString(primValue); default: return String(argument); } } CreateMethodProperty(String.prototype, 'at', function at(index) { var O = RequireObjectCoercible(this); var S = ToString(O); var len = S.length; var relativeIndex = ToIntegerOrInfinity(index); var k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex; if (k < 0 || k >= len) return undefined; return S.substring(k, k + 1); }); } })(); /* </pre> */