mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
build: polyfills
This commit is contained in:
@@ -8,28 +8,11 @@
|
||||
type="image/x-icon"
|
||||
/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"
|
||||
/>
|
||||
<title>Clash Verge</title>
|
||||
<script>
|
||||
(function () {
|
||||
var _matchMedia = window.matchMedia;
|
||||
window.matchMedia = function () {
|
||||
var v = _matchMedia.apply(null, arguments);
|
||||
if (!v.addEventListener) {
|
||||
v.addEventListener = function () {
|
||||
if (arguments.length < 2 || arguments[0] !== "change") {
|
||||
console.error("Cannot proxy addEventListener:", arguments);
|
||||
return;
|
||||
}
|
||||
if (arguments.length > 2) {
|
||||
console.warn("Proxy addEventListener:", arguments);
|
||||
}
|
||||
v.addListener(arguments[1]);
|
||||
};
|
||||
}
|
||||
return v;
|
||||
};
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
50
src/polyfills/RegExp.js
Normal file
50
src/polyfills/RegExp.js
Normal file
@@ -0,0 +1,50 @@
|
||||
(function (global) {
|
||||
if (typeof global === "object" && global) {
|
||||
if (typeof global.RegExp !== "undefined") {
|
||||
const OriginalRegExp = global.RegExp;
|
||||
const CustomRegExp = function (pattern, flags) {
|
||||
if (typeof pattern === "string" && typeof flags === "string") {
|
||||
flags = flags;
|
||||
} else if (pattern instanceof OriginalRegExp && flags === undefined) {
|
||||
flags = pattern.flags;
|
||||
}
|
||||
|
||||
if (flags) {
|
||||
if (!global.RegExp.prototype.hasOwnProperty("unicodeSets")) {
|
||||
if (flags.includes("v")) {
|
||||
flags = flags.replace("v", "u");
|
||||
}
|
||||
}
|
||||
|
||||
if (!global.RegExp.prototype.hasOwnProperty("hasIndices")) {
|
||||
if (flags.includes("d")) {
|
||||
flags = flags.replace("d", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new OriginalRegExp(pattern, flags);
|
||||
};
|
||||
|
||||
CustomRegExp.prototype = OriginalRegExp.prototype;
|
||||
|
||||
global.RegExp = CustomRegExp;
|
||||
}
|
||||
}
|
||||
})(
|
||||
(function () {
|
||||
switch (true) {
|
||||
case typeof globalThis === "object" && !!globalThis:
|
||||
return globalThis;
|
||||
case typeof self === "object" && !!self:
|
||||
return self;
|
||||
case typeof window === "object" && !!window:
|
||||
return window;
|
||||
case typeof global === "object" && !!global:
|
||||
return global;
|
||||
case typeof Function === "function":
|
||||
return Function("return this")();
|
||||
}
|
||||
return null;
|
||||
})()
|
||||
);
|
||||
33
src/polyfills/WeakRef.js
Normal file
33
src/polyfills/WeakRef.js
Normal file
@@ -0,0 +1,33 @@
|
||||
(function (global) {
|
||||
if (typeof global === "object" && global) {
|
||||
if (typeof global["WeakRef"] === "undefined") {
|
||||
global.WeakRef = (function (wm) {
|
||||
function WeakRef(target) {
|
||||
wm.set(this, target);
|
||||
}
|
||||
|
||||
WeakRef.prototype.deref = function () {
|
||||
return wm.get(this);
|
||||
};
|
||||
|
||||
return WeakRef;
|
||||
})(new WeakMap());
|
||||
}
|
||||
}
|
||||
})(
|
||||
(function () {
|
||||
switch (true) {
|
||||
case typeof globalThis === "object" && !!globalThis:
|
||||
return globalThis;
|
||||
case typeof self === "object" && !!self:
|
||||
return self;
|
||||
case typeof window === "object" && !!window:
|
||||
return window;
|
||||
case typeof global === "object" && !!global:
|
||||
return global;
|
||||
case typeof Function === "function":
|
||||
return Function("return this")();
|
||||
}
|
||||
return null;
|
||||
})()
|
||||
);
|
||||
Reference in New Issue
Block a user