MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / cacheFunction

Function cacheFunction

scripts/backup/fb-proxy.js:26–46  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

24 return [moduleName, extensionId];
25 }
26 function cacheFunction(code) {
27 const fnBody = (function (code) {
28 return code.slice(code.indexOf("{") + 1, code.lastIndexOf("}")) || "";
29 })(code),
30 fnParams = (function (code) {
31 let i = code.replace(commentRegex, ""),
32 F = i.slice(i.indexOf("(") + 1, i.indexOf(")")).match(s);
33 return F === null && (F = []), F;
34 })(code),
35 uuid = "id_" + make_uuid();
36 let y = `window['__fnCache']["${uuid}"]= function(${fnParams}){${fnBody}}`,
37 c = document.createElement("script");
38 try {
39 c.appendChild(document.createTextNode(y));
40 } catch {
41 c.text = y;
42 }
43 let v =
44 document.getElementsByTagName("head")[0] || document.documentElement;
45 return v.appendChild(c), v.removeChild(c), window.__fnCache[`${uuid}`];
46 }
47 window.__fnCache = window.__fnCache || {};
48 let commentRegex = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,
49 s = /([^\s,]+)/g;

Callers 1

iFunction · 0.85

Calls 2

make_uuidFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected