// ==UserScript== // @name canTvas // @namespace https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256 // @downloadURL https://gist.github.com/lulzsun/f8eff07e74b40126866d83a17d0fb256/raw/canTvas.user.js // @version 0.2 // @description Prevents the logging of specific canvas lms quiz events. // @author lulzsun // @match http*://*.instructure.com/* // @match http*://*.canvas.*.edu/* // @icon https://www.google.com/s2/favicons?sz=64&domain=canvaslms.com // @grant none // ==/UserScript== (function() { 'use strict'; window.cantvas = true; var oldXHROpen = window.XMLHttpRequest.prototype.open; var oldXHRSend = window.XMLHttpRequest.prototype.send; window.XMLHttpRequest.prototype.open = function (method, url) { this._url = url; var args = arguments; return oldXHROpen.apply(this, args); }; window.XMLHttpRequest.prototype.send = function (body) { var url = this._url; var args = arguments; // testing for quiz events var regexMatches = new RegExp("*/api/v1/courses/*/quizzes/*/submissions/*/events".replace(/\*/g, "[^ ]*")); if (regexMatches.test(url) && window.cantvas === true) { if (body !== undefined) { var parsedBody = JSON.parse(body); var i = parsedBody["quiz_submission_events"].length; var prevents = 0; while (i--) { var element = parsedBody["quiz_submission_events"][i]; if (element["event_type"] === "page_focused" || element["event_type"] === "page_blurred") { parsedBody["quiz_submission_events"].splice(i, 1); prevents++; } } if (prevents > 0) console.warn(`[canTvas] '${prevents}' event(s) were prevented.`); args[0] = JSON.stringify(parsedBody["quiz_submission_events"]); console.log('on send body:', parsedBody["quiz_submission_events"]); if (parsedBody["quiz_submission_events"].length <= 0) return; } } return oldXHRSend.apply(this, args); }; console.warn(`[canTvas] Userscript loaded successfully.`); })();