Last active
May 20, 2019 23:14
-
-
Save mistzzt/b713e70b56f0cd025ad0c8d5000d583d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name cs140bypass | |
// @namespace ucsd.cse | |
// @version 0.0.3 | |
// @description yeman cse 140 | |
// @author mist | |
// @license MIT | |
// @date 2019-05-13 | |
// @match *://learn.zybooks.com/zybook/UCSDCSE140ChengSpring2019/* | |
// @grant none | |
// ==/UserScript== | |
// | |
(function () { | |
function setIfExists(obj, prop, value) { | |
if (obj == null || !obj.hasOwnProperty(prop)) { | |
return obj; | |
} | |
Object.defineProperty(obj, prop, { | |
value, | |
writable: false | |
}); | |
return obj; | |
} | |
function initializeCompletionRewrite() { | |
const ARG_INDEX = 2; | |
const CONTENT_TYPE_JSON = "application/json"; | |
$(document).ajaxSend(function () { | |
const instance = arguments[ARG_INDEX]; | |
if (instance.contentType !== CONTENT_TYPE_JSON) { | |
return; | |
} | |
let prevData = JSON.parse(arguments[ARG_INDEX].data); | |
setIfExists(prevData, 'complete', true); | |
setIfExists(prevData, 'isComplete', true); | |
if (prevData.hasOwnProperty('metadata') | |
&& prevData.hasOwnProperty('answer')) { | |
const expected = JSON.parse(prevData.metadata).expectedAnswer; | |
prevData.answer = expected; | |
} | |
instance.data = JSON.stringify(prevData); | |
console.log("modified `complete=true`"); | |
}); | |
$(document).bind('DOMSubtreeModified', function () { | |
$('.zyante-progression-check-button').click(function () { | |
$('.zyante-progression-checkmark').prop('style', ''); | |
$('.zyante-progression-explanation').text('Now refresh the page and continue to the next part.'); | |
}); | |
}); | |
} | |
function initializeAutoClick() { | |
const divToAdd = document.querySelector('.right-buttons'); | |
if (divToAdd == null) { | |
console.log("Failed to find proper div for input."); | |
return; | |
} | |
const btnRun = $(`<input />`).attr({ | |
type: "button", | |
class: "reset-button zb-button primary raised ember-view", | |
value: "Run" | |
}); | |
btnRun.on('click', function () { _startAutomation(); }); | |
btnRun.appendTo(divToAdd); | |
function _startAutomation() { | |
let interval = 0; | |
const performClick = input => { | |
interval += 5; | |
setTimeout(() => input.click(), interval); | |
} | |
document.querySelectorAll('.zb-radio-button').forEach(k => { | |
const input = k.children[0]; | |
performClick(input); | |
}); | |
document.querySelectorAll('.start-button').forEach(k => { | |
const input = k.children[0]; | |
performClick(input); | |
}); | |
document.querySelectorAll('.unclicked').forEach(k => { | |
performClick(k); | |
}); | |
document.querySelectorAll('.show-answer-button').forEach(k => { | |
performClick(k); | |
performClick(k); | |
}); | |
} | |
} | |
$(window).ready(function () { | |
initializeCompletionRewrite(); | |
initializeAutoClick(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment