From 054a30d6c868a1ae7048a32e2262acc329f75df0 Mon Sep 17 00:00:00 2001 From: YourFriendlyNeighborhoodDealer Date: Thu, 7 Mar 2019 09:06:25 +0100 Subject: [PATCH] Added timer for performance measurement --- main.js | 60 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/main.js b/main.js index 530a482..8f5dfff 100644 --- a/main.js +++ b/main.js @@ -32,7 +32,7 @@ const forceTestPage = false; const forceResultPage = false; const forceDefaultPage = false; const logElementGetting = false; -const log = false; +const log = true; const motdShowCount = 3; var motd = ""; @@ -227,6 +227,8 @@ class QuestionDB { //: Main function {{{ function Main() { 'use strict'; + console.time('main'); + Init(function(count, subjCount) { var url = location.href; @@ -237,38 +239,40 @@ function Main() { m: "Passzív mód bekapcsolva, válaszok megjelenítéséhez menü gomb alatt kapcsold ki, és frissíts!", isSimple: true }); - return; - } - - try { - if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test - HandleQuiz(); - } else if ((url.includes("/quiz/") && url.includes("review.php")) || forceResultPage) { // if the current window is a test-s result - HandleResults(url); - } else if ((!url.includes("/quiz/") && !url.includes("review.php") && !url.includes(".pdf")) || - (forceDefaultPage)) { // if the current window is any other window than a quiz or pdf. - HandleUI(url, count, subjCount); - } - } catch (e) { - ShowMessage({ - m: "Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!", - isSimple: true - }, undefined, function() { - GM_openInTab(serverAdress + 'legacy', { - active: true + } else { + try { + if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test + HandleQuiz(); + } else if ((url.includes("/quiz/") && url.includes("review.php")) || forceResultPage) { // if the current window is a test-s result + HandleResults(url); + } else if ((!url.includes("/quiz/") && !url.includes("review.php") && !url.includes(".pdf")) || + (forceDefaultPage)) { // if the current window is any other window than a quiz or pdf. + HandleUI(url, count, subjCount); + } + } catch (e) { + ShowMessage({ + m: "Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!", + isSimple: true + }, undefined, function() { + GM_openInTab(serverAdress + 'legacy', { + active: true + }); }); - }); - Exception(e, "script error at main:"); + Exception(e, "script error at main:"); + } + if (url.includes("eduplayer")) // if the current site is a video site + AddVideoHotkeys(url); // adding video hotkeys + Log( + "Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót! Nagy esélyel a kérdéseket nem lehetett beolvasni." + ); } - if (url.includes("eduplayer")) // if the current site is a video site - AddVideoHotkeys(url); // adding video hotkeys - Log( - "Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót! Nagy esélyel a kérdéseket nem lehetett beolvasni." - ); }); if (forceTestPage || forceResultPage || forceDefaultPage) alert("TEST MODE"); + + console.log("Main run time:"); + console.timeEnd('main'); } //: }}} @@ -1237,7 +1241,7 @@ function SearchSameQuestion(questionData, quiz, i) { let count = 0; r.forEach((item) => { if (item.match > minResultMatchPercent) - count ++; + count++; }); return count == 0 ? -1 : count;