logo

Crowdly

Browser

Add to Chrome

(function () { if (window.__cbGuard) return; window.__cbGuard = true; /...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

(function () {

if (window.__cbGuard) return;

window.__cbGuard = true;

// only the attempt page. the review and summary pages also render question

// text, and running there would show the red screen again and try to finish

// an attempt that is already finished

if (!/\/attempt\.php$/.test(location.pathname)) return;

/* ---------- tuning ---------- */

var STRIKES_TO_END = 3;

var END_COUNTDOWN_S = 8;

var FIRST_EXIT_SKIPS = false; // false means the first exit only warns

var CHECK_EXTENSIONS = true; // true looks for browser extensions that change the page

var HIDDEN_GRACE_MS = 800;

var BLUR_GRACE_MS = 1500;

var SELECT_GRACE_MS = 3500;

// everything is keyed to this attempt, so a new attempt in the same tab

// starts clean and the state of an old one cannot leak into it

var ATTEMPT = (/[?&]attempt=(\d+)/.exec(location.search) || [])[1] || "none";

var K_STRIKES = "cbguard_" + ATTEMPT + "_strikes", K_ENDED = "cbguard_" + ATTEMPT + "_ended",

K_WARN = "cbguard_" + ATTEMPT + "_warn", K_CONSENT = "cbguard_" + ATTEMPT + "_consent";

var NAVY = "#06205E", AMBER = "#B57B0D", RED = "#A32B22";

var FONT = "'Segoe UI',Calibri,Arial,sans-serif";

/* ---------- storage that survives page changes inside the attempt ---------- */

function get(k) { try { return sessionStorage.getItem(k); } catch (e) { return window["__cb_" + k] || null; } }

function set(k, v) { try { sessionStorage.setItem(k, v); } catch (e) {} window["__cb_" + k] = v; }

function strikes() { return parseInt(get(K_STRIKES) || "0", 10) || 0; }

function ended() { return get(K_ENDED) === "1"; }

function started() { return get(K_CONSENT) === "1"; }

/* ---------- banner ---------- */

var bar = document.createElement("div");

bar.id = "cb-guard-bar";

bar.setAttribute("style", "position:fixed;top:0;left:0;right:0;z-index:2147482000;background:" + NAVY +

";color:#fff;font:600 14px/1.4 " + FONT + ";padding:9px 16px;text-align:center;letter-spacing:.4px;" +

"box-shadow:0 2px 8px rgba(0,0,0,.25);user-select:none;-webkit-user-select:none");

bar.textContent = "CLOSED BOOK EXAM · Leaving this window skips the question. Leaving it 3 times ends the exam.";

document.body.appendChild(bar);

document.body.style.paddingTop = (bar.offsetHeight + 4) + "px";

/* ---------- notices that cover the page ---------- */

function overlay(colour, title, lines, buttonText, needTick, onOk) {

var old = document.getElementById("cb-guard-overlay"); if (old) old.parentNode.removeChild(old);

var o = document.createElement("div"); o.id = "cb-guard-overlay";

// the box is centred when it fits, and scrolls when the screen is short,

// so the button at the bottom can always be reached

o.setAttribute("style", "position:fixed;inset:0;z-index:2147483000;background:rgba(6,32,94,.92);display:flex;" +

"align-items:flex-start;justify-content:center;overflow-y:auto;padding:24px;font-family:" + FONT + ";user-select:none;-webkit-user-select:none");

var box = document.createElement("div");

box.setAttribute("style", "background:#fff;max-width:640px;width:100%;margin:auto 0;border-top:8px solid " + colour + ";padding:28px 30px;box-shadow:0 20px 60px rgba(0,0,0,.4)");

var h = document.createElement("div");

h.setAttribute("style", "font:700 24px/1.2 Cambria,Georgia,serif;color:" + colour + ";margin:0 0 14px");

h.textContent = title; box.appendChild(h);

lines.forEach(function (t) {

var p = document.createElement("p"); p.setAttribute("style", "font:15px/1.55 " + FONT + ";color:#1D2B4A;margin:0 0 10px"); p.textContent = t; box.appendChild(p);

});

var btn = null;

if (buttonText) {

var tick = null;

if (needTick) {

var lab = document.createElement("label");

lab.setAttribute("style", "display:flex;gap:10px;align-items:flex-start;font:600 15px/1.45 " + FONT + ";color:" + NAVY + ";margin:18px 0 14px;cursor:pointer");

tick = document.createElement("input"); tick.type = "checkbox"; tick.id = "cb-guard-tick"; tick.setAttribute("style", "width:18px;height:18px;margin-top:3px;flex:none");

var span = document.createElement("span"); span.textContent = needTick; lab.appendChild(tick); lab.appendChild(span); box.appendChild(lab);

}

btn = document.createElement("button"); btn.id = "cb-guard-ok";

btn.setAttribute("style", "background:" + colour + ";color:#fff;border:0;font:600 16px " + FONT + ";padding:13px 24px;cursor:pointer;margin-top:6px;opacity:" + (needTick ? ".4" : "1"));

btn.textContent = buttonText; btn.disabled = !!needTick;

if (tick) tick.addEventListener("change", function () { btn.disabled = !tick.checked; btn.style.opacity = tick.checked ? "1" : ".4"; });

btn.addEventListener("click", function () { if (btn.disabled) return; o.parentNode.removeChild(o); if (onOk) onOk(); });

box.appendChild(btn);

}

o.appendChild(box); document.body.appendChild(o);

return o;

}

/* ---------- ended. the red screen, and it stays ended ---------- */

function showEnded(seconds) {

bar.textContent = "This exam has been ended."; bar.style.background = RED;

var o = overlay(RED, "Your exam has been ended",

[(STRIKES_TO_END === 1 ? "You left the exam window." : "You left the exam window " + times(STRIKES_TO_END) + ".") +

" Your attempt is being submitted with the answers you had given up to that point.",

"This page can no longer be used. Going back, reloading or reopening it will not restore the attempt.",

"If you believe this happened by mistake, speak to the invigilator now, without leaving the room."],

null);

if (seconds) {

var cd = document.createElement("p"); cd.id = "cb-guard-countdown";

cd.setAttribute("style", "font:600 15px " + FONT + ";color:" + RED + ";margin:14px 0 0");

var box = o.firstChild; box.appendChild(cd);

var left = seconds;

cd.textContent = "Submitting in " + left + " seconds.";

var iv = setInterval(function () { left--; if (left <= 0) { clearInterval(iv); cd.textContent = "Submitting now."; return; }

cd.textContent = "Submitting in " + left + " seconds."; }, 1000);

}

var form = document.getElementById("responseform");

if (form) Array.prototype.forEach.call(form.querySelectorAll("input, select, textarea, button"), function (el) { el.disabled = true; });

}

/* ---------- finishing the attempt in one step ---------- */

function q(sel) { try { return document.querySelector(sel); } catch (e) { return null; } }

function finishAttempt() {

var m = /[?&]attempt=(\d+)/.exec(location.search);

var cm = /[?&]cmid=(\d+)/.exec(location.search);

var sk = (window.M && M.cfg && M.cfg.sesskey) || (q("input[name=sesskey]") || {}).value;

if (m && sk) {

var f = document.createElement("form"); f.method = "POST"; f.id = "cb-guard-finish";

f.action = location.pathname.replace(/[^\/]*$/, "processattempt.php");

var fields = { attempt: m[1], finishattempt: "1", timeup: "0", sesskey: sk, slots: "" };

if (cm) fields.cmid = cm[1];

Object.keys(fields).forEach(function (k) {

var i = document.createElement("input"); i.type = "hidden"; i.name = k; i.value = fields[k]; f.appendChild(i);

});

document.body.appendChild(f); f.submit(); return true;

}

var fin = q("a.endtestlink") || q("input[value*='Finish attempt']");

if (fin) fin.click();

var tries = 0, iv = setInterval(function () {

var b = q("#mod_quiz-submit-all-btn") || Array.prototype.slice.call(document.querySelectorAll("button, input[type=submit]"))

.filter(function (el) { return /submit all and finish/i.test(el.textContent || el.value || ""); })[0];

if (b) b.click();

var c = Array.prototype.slice.call(document.querySelectorAll(".modal button, [data-action='save'], button.btn-primary"))

.filter(function (el) { return /submit all and finish|yes|confirm/i.test(el.textContent || el.value || ""); })[0];

if (c) c.click();

if (++tries > 25) clearInterval(iv);

}, 400);

return false;

}

function endExam() {

set(K_ENDED, "1");

showEnded(END_COUNTDOWN_S);

setTimeout(finishAttempt, END_COUNTDOWN_S * 1000);

}

/* ---------- skipping the current question ---------- */

function clearAnswers() {

var form = document.getElementById("responseform"); if (!form) return;

Array.prototype.forEach.call(form.querySelectorAll("input[type=radio], input[type=checkbox]"), function (el) { el.checked = false; });

Array.prototype.forEach.call(form.querySelectorAll("select"), function (el) { el.selectedIndex = 0; });

Array.prototype.forEach.call(form.querySelectorAll("input[type=text], input[type=number], textarea"), function (el) { el.value = ""; });

}

function goNext() {

var n = q("#mod_quiz-next-nav") || q("input[name='next']") || q("input.mod_quiz-next-nav");

if (n) { n.click(); return; }

var fin = q("a.endtestlink"); if (fin) fin.click();

}

function remaining() { return STRIKES_TO_END - strikes(); }

function times(n) { return n + (n === 1 ? " time" : " times"); }

function warnBanner() {

var r = remaining(), n = strikes();

bar.style.background = AMBER;

bar.textContent = r <= 1

? "You have left the window " + times(n) + ". Leave again and your exam ends automatically."

: "You have left the window " + times(n) + ". Leave it " + times(r) + " more and your exam ends automatically.";

}

var TITLE = { window: "You left the exam window", extension: "A browser extension changed this page" };

var WHY = { window: "",

extension: "What it added has been removed. An extension counts as leaving the exam window. " };

// with several questions on one page, skipping would wipe all of them,

// so on such a page the first exit only warns

function oneQuestion() { return document.querySelectorAll("#responseform .que").length <= 1; }

function showWarning(thenNext, reason, skipped) {

if (!TITLE[reason]) reason = "window";

if (skipped === undefined) skipped = FIRST_EXIT_SKIPS && oneQuestion();

var r = remaining(), last = r <= 1;

overlay(AMBER, TITLE[reason],

[WHY[reason] + (skipped ? "The question you were on has been skipped. Its answers were cleared and it cannot be reopened." : "This time nothing has been lost."),

last ? "This is your last warning. If you leave this window again, for any reason, your exam ends automatically and is submitted exactly as it stands at that moment."

: "If you leave this window " + times(r) + " more, your exam ends automatically and is submitted as it stands. You will be warned again each time.",

reason === "extension" ? "Do not use any browser extension during the exam."

: "Close every other application now. Turn off notifications. Stay on this page until you have finished."],

"I understand. Continue the exam",

last ? "I acknowledge that leaving this window again ends my exam automatically."

: "I acknowledge that I have " + r + " exits left before my exam ends automatically.",

function () { set(K_WARN, "0"); if (thenNext) goNext(); });

}

function skipQuestion(reason) {

set(K_WARN, reason);

warnBanner();

var skip = FIRST_EXIT_SKIPS && oneQuestion();

if (skip) clearAnswers();

showWarning(skip, reason, skip);

}

function strike(reason) {

if (ended()) return;

if (!started()) return; // nothing counts until they have agreed to start

var n = strikes() + 1; set(K_STRIKES, String(n));

if (n >= STRIKES_TO_END) endExam(); else skipQuestion(reason || "window");

}

/* ---------- detecting that the window was really left ---------- */

var awaySince = null, awayKind = null;

function dropdownHasFocus() {

var a = document.activeElement;

return !!(a && a.tagName === "SELECT");

}

function here() { return !document.hidden && document.hasFocus(); }

function onHidden() { if (awaySince === null) { awaySince = Date.now(); awayKind = "hidden"; } }

function onLost() {

if (document.hidden) return;

if (awaySince === null) { awaySince = Date.now(); awayKind = dropdownHasFocus() ? "select" : "blur"; }

}

// clicking into a frame on the page, like the essay editor, also blurs the

// window. the page still has focus then, so that is not an exit

function onBlur() { setTimeout(function () { if (!document.hasFocus()) onLost(); }, 0); }

function onBack() {

if (awaySince === null) return;

var away = Date.now() - awaySince, kind = awayKind; awaySince = null; awayKind = null;

var limit = kind === "hidden" ? HIDDEN_GRACE_MS : kind === "select" ? SELECT_GRACE_MS : BLUR_GRACE_MS;

if (away >= limit) strike("window");

}

document.addEventListener("visibilitychange", function () { document.hidden ? onHidden() : onBack(); });

window.addEventListener("blur", onBlur);

window.addEventListener("focus", onBack);

// a light check every 400 ms catches what the events miss, for example

// leaving the browser while typing inside the essay editor

setInterval(function () {

if (here()) { if (awaySince !== null) onBack(); }

else if (awaySince === null) { if (document.hidden) onHidden(); else onLost(); }

}, 400);

/* ---------- browser extensions that change the page ---------- */

// a web page cannot switch extensions off. it can only see the ones that

// add things to it: sidebars, buttons, pop ups, marks on the page itself.

// an extension that only reads the page stays invisible

var EXT_URL = /^(chrome-extension|moz-extension|safari-web-extension|safari-extension|ms-browser-extension|extension):/i;

var EXT_MARK = /^data-(gr-ext-installed|new-gr-c-s|lt-installed)|extension/i;

var OK_TAG = /^(mjx-|video-js)/; // maths and video players that Moodle itself adds

var blocked = false, extCounted = false;

function suspect(el) {

var tag = el.tagName.toLowerCase();

if (el.parentNode === document.documentElement && tag !== "head" && tag !== "body") return tag;

if (tag.indexOf("-") > 0 && !OK_TAG.test(tag)) return tag;

if (el.shadowRoot && !OK_TAG.test(tag)) return tag;

var u = el.getAttribute("src") || el.getAttribute("href") || "";

if (EXT_URL.test(u)) return u.split("/").slice(0, 3).join("/");

return null;

}

function scanAll() {

var found = [];

[document.documentElement, document.body].forEach(function (el) {

if (el) Array.prototype.forEach.call(el.attributes, function (a) { if (EXT_MARK.test(a.name)) found.push({ what: a.name }); });

});

var all = document.getElementsByTagName("*");

for (var i = 0; i < all.length; i++) { var s = suspect(all[i]); if (s) found.push({ what: s, el: all[i] }); }

return found;

}

function names(found) {

var out = [];

found.forEach(function (f) { if (out.indexOf(f.what) === -1) out.push(f.what); });

return out.slice(0, 4).join(", ");

}

function blockStart(found) {

if (blocked) return;

blocked = true;

overlay(AMBER, "Turn off your browser extensions",

["A browser extension is changing this page, so the exam cannot start.",

"What was found: " + names(found) + ".",

"Turn off your extensions, then reload this page. The simplest way is to open the exam in a private window, where extensions are usually off.",

"Leaving this window now does not count against you, because the exam has not started yet."],

null);

}

function onExtension(found) {

if (!found.length || ended()) return;

if (!started()) { blockStart(found); return; }

found.forEach(function (f) { if (f.el && f.el.parentNode) f.el.parentNode.removeChild(f.el); });

if (!extCounted) { extCounted = true; strike("extension"); } // one count per page at most

}

if (CHECK_EXTENSIONS) {

var pending = null;

var later = function () { if (pending) return; pending = setTimeout(function () { pending = null; onExtension(scanAll()); }, 300); };

new MutationObserver(later).observe(document.documentElement, { childList: true, subtree: true });

new MutationObserver(later).observe(document.documentElement, { attributes: true });

new MutationObserver(later).observe(document.body, { attributes: true });

}

/* ---------- copy, paste, selection, right click ---------- */

var block = function (e) { e.preventDefault(); e.stopPropagation(); return false; };

function isAnswerBox(t) { return t && (t.tagName === "TEXTAREA" || (t.tagName === "INPUT" && /text|number/.test(t.type))); }

["copy", "cut", "paste", "contextmenu", "dragstart", "drop"].forEach(function (ev) {

document.addEventListener(ev, function (e) { if (ev === "paste" || ev === "drop" || !isAnswerBox(e.target)) return block(e); }, true);

});

document.addEventListener("selectstart", function (e) { if (!isAnswerBox(e.target)) return block(e); }, true);

document.addEventListener("keydown", function (e) {

var k = (e.key || "").toLowerCase();

if ((e.ctrlKey || e.metaKey) && ["c", "x", "v", "p", "s", "u", "a"].indexOf(k) !== -1) return block(e);

if (k === "f12" || k === "printscreen") return block(e);

if ((e.ctrlKey || e.metaKey) && e.shiftKey && ["i", "j", "c"].indexOf(k) !== -1) return block(e);

}, true);

var style = document.createElement("style"); style.id = "cb-guard-style";

style.textContent = ".que .qtext, .que .answer, .que .formulation { -webkit-user-select:none; user-select:none; }" +

".que textarea, .que input[type=text] { -webkit-user-select:text; user-select:text; }";

document.head.appendChild(style);

/* ---------- what to show when a page opens ---------- */

function onPageOpen() {

if (ended()) { showEnded(2); setTimeout(finishAttempt, 2000); return; }

if (strikes() >= 1) warnBanner();

if (CHECK_EXTENSIONS) {

var found = scanAll();

if (found.length) {

if (!started()) { blockStart(found); return; }

var first = !extCounted;

onExtension(found);

if (first) return; // its warning is on screen now

}

}

// the warning was shown on the page where it happened. if it was never

// acknowledged, because the page moved on or was reloaded, show it here

var w = get(K_WARN);

if (w && w !== "0") { showWarning(false, w); return; }

if (!started()) {

overlay(NAVY, "Before you start",

["This is a closed book examination taken alone. By continuing you confirm the following.","You will not use any AI assistant, chatbot or language model, on this device or any other, during the exam.","You will not use social media, messaging, email or any other communication tool during the exam.","You have closed every other application and turned off notifications, and you have no software running that can read this page or interact with it.","You will not leave this window. Leaving it once brings a warning. Leaving it 3 times ends the exam and submits it as it stands.","You have turned off all browser extensions. An extension that changes this page during the exam counts as leaving this window.","You understand that a breach of these conditions is treated as academic fraud under the school's regulations."],

"I agree, start the exam",

"I confirm all of the above and I take the exam under these conditions.",

function () { set(K_CONSENT, "1"); });

}

}

onPageOpen();

window.addEventListener("pageshow", function (e) { if (e.persisted) onPageOpen(); });

})();

Suppose Back Market, the refurbished phone marketplace, creates a quality-grading system for phones. It is valuable and no rival has it, but a rival copies it within six months. The system gives Back Market a temporary advantage, not a sustained one.

0%
0%
More questions like this

Want instant access to all verified answers on elearning.mbs-education.com?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome