Skip to content

Instantly share code, notes, and snippets.

@DevShaded
Created August 16, 2023 10:44
Show Gist options
  • Save DevShaded/eb0946cb3782f4305c5c5677864cb7bd to your computer and use it in GitHub Desktop.
Save DevShaded/eb0946cb3782f4305c5c5677864cb7bd to your computer and use it in GitHub Desktop.
VG Error and Warning Handeling
const originalConsoleError = console.error;
const originalConsoleWarn = console.warn;
let devMode = false;
const oldErrors = [];
const oldWarns = [];
function consoleResponse() {
const bigTitleStyle = "font-size: 35px; color: #ff0000; font-weight: bold;";
const titleStyle = "font-size: 30px; color: #ff0000; font-weight: bold;";
const descriptionStyle = "font-size: 18px";
console.log("%c👋 Velkommen til Konsollens Gang!", bigTitleStyle);
console.log("%cLiker du å være i konsollen? Det gjør vi også. Kom og snakk med oss da vel?\nJoin https://discord.gg/vgno.", descriptionStyle);
console.log("%c🤔 Lyst til å bli lærling hos oss?", titleStyle);
console.log("%cSøk her: https://emp.jobylon.com/jobs/180192-vg-soknad-til-laerlingplass-i-vge24/", descriptionStyle);
console.log("%c🤗 Eller kanskje bare en vanlig jobb?", titleStyle);
console.log("%cSøk her: https://vg.jobylon.com/#positions", descriptionStyle);
console.log("%csetDevMode(true) for more debug information", 'font-size: 15px; font-weight: bold; margin-top: 5px; margin-button: 5px;');
}
function setDevMode(devModeBoolean) {
if (devModeBoolean) {
devMode = true;
console.error = originalConsoleError;
console.info('%cDev mode enabled', 'font-weight:bold; margin:0; font-size: 24px');
console.info('%cPrevious errors:', 'font-size: 15px');
for (let i in oldErrors) {
console.error(oldErrors[i]);
}
console.warn = originalConsoleWarn;
console.info('%cPrevious warnings:', 'font-size: 15px');
for (let i in oldWarns) {
console.warn(oldWarns[i]);
}
} else {
devMode = false;
console.clear();
consoleResponse();
}
}
if (!devMode) {
consoleResponse();
console.error = function (message) {
oldErrors.push(message);
console.clear();
consoleResponse();
}
console.warn = function (message) {
oldWarns.push(message);
console.clear();
consoleResponse();
}
window.addEventListener('error', () => {
console.clear();
consoleResponse();
});
window.addEventListener('warn', () => {
console.clear();
consoleResponse();
});
}
window.setDevMode = setDevMode;
// used for testing
//setInterval(() => {
// console.error("👋 Velkommen til Konsollens Gang!");
// console.warn("👋 Velkommen til Konsollens Gang!");
//}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment