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

Function onDocumentEnd

scripts/ufs_statistic.js:40–431  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38};
39
40async function onDocumentEnd() {
41 const logs = document.body.innerText
42 .split("\n")
43 .filter((_) => _)
44 .map((_) => _.trim());
45
46 if (!logs.length) return;
47
48 let hasLog = logs[0] != "Log not found" && logs[0] != "Waking up";
49
50 const allLogs = logs.map((log, i) => {
51 const timeString = extractTime(log).replace(/\d+\/\d+\/\d+, /, "");
52 const pm_am = timeString?.split(" ")[1];
53 let hour = parseInt(timeString?.split(":")[0]) + (pm_am == "PM" ? 12 : 0);
54 if (hour == 12 && pm_am == "AM") hour = 0;
55
56 const data = {
57 i,
58 log,
59 uid: extractUid(log),
60 time: new Date(extractTime(log)),
61 timeString,
62 hour,
63 eventName: extractEventName(log),
64 version: extractVersion(log),
65 totalCount: extractTotalCount(log),
66 isScript: isScript(log),
67 fbName: "",
68 fbAvatar: "",
69 };
70 const eventNameWithoutVersion = data.eventName
71 .replace("(" + data.version + ")", "")
72 .trim();
73 const version = padStr(data.version, 4, " ");
74 if (version && eventNameWithoutVersion)
75 data.logPretty = `${data.timeString} | ${version} | ${eventNameWithoutVersion} <i class="show-on-hover">${data.totalCount} ${data.uid}</i>`;
76 else data.logPretty = data.log;
77 return data;
78 });
79
80 console.log(allLogs);
81
82 document.body.innerText = "";
83 const container = document.createElement("div");
84
85 if (hasLog) {
86 UfsGlobal.Extension.getURL("/scripts/ufs_statistic.css").then(
87 UfsGlobal.DOM.injectCssFile
88 );
89 UfsGlobal.DOM.injectCssFile(
90 "https://cdn.jsdelivr.net/npm/ag-grid-community@32.2.2/styles/ag-grid.css",
91 "ag-grid-css"
92 );
93 UfsGlobal.DOM.injectCssFile(
94 "https://cdn.jsdelivr.net/npm/ag-grid-community@32.2.2/styles/ag-theme-quartz-dark.css",
95 "ag-grid-theme-css"
96 );
97 await UfsGlobal.DOM.injectScriptSrcAsync(

Callers

nothing calls this directly

Calls 15

getUserAvatarFromUidFunction · 0.90
createLogCountPerHourFunction · 0.85
filterMethod · 0.80
replaceMethod · 0.80
getMethod · 0.80
sortMethod · 0.80
extractTimeFunction · 0.70
extractUidFunction · 0.70
extractEventNameFunction · 0.70
extractVersionFunction · 0.70
extractTotalCountFunction · 0.70
isScriptFunction · 0.70

Tested by

no test coverage detected