Polyfill Lite for old browser

add Array.at and Object.hasOwn.

  1. // ==UserScript==
  2. // @name Polyfill Lite for old browser
  3. // @namespace github.com/hmjz100
  4. // @version 1.0.0
  5. // @description add Array.at and Object.hasOwn.
  6. // @author hmjz100
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. if (!window.Array.prototype.at) {
  14. window.Array.prototype.at = function(index) {
  15. const len = this.length;
  16. index = index >= 0 ? index : len + index;
  17. if (index < 0 || index >= len) {
  18. return undefined;
  19. }
  20. return this[index];
  21. };
  22. }
  23. if (!window.Object.hasOwn) {
  24. window.Object.defineProperty(Object, 'hasOwn', {
  25. value: function(object, key) {
  26. return Object.prototype.hasOwnProperty.call(object, key);
  27. },
  28. configurable: true,
  29. enumerable: false,
  30. writable: true
  31. });
  32. }
  33. })();