This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
ripper.js
75 lines (57 loc) · 2.02 KB
/
ripper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* ripper.js - a script to grab solutions from chegg
* By Elbert Basolis ([email protected])
* https://github.com/elby22/CheggRipper
*
* Disclaimer: I assume no responsibility for the use of this software.
* This is a proof cof concept only not intended to infringe copyright or violate any laws anywhere.
*/
//Clones the canvas
function cloneCanvas(oldCanvas) {
//create a new canvas
var newCanvas = document.createElement('canvas');
var context = newCanvas.getContext('2d');
//set dimensions
newCanvas.width = oldCanvas.width;
newCanvas.height = oldCanvas.height;
//apply the old canvas to the new one
context.drawImage(oldCanvas, 0, 0);
//return the new canvas
return newCanvas;
}
//Main logic: gets all the good stuff from the page, and advances to the next
function ripPage(){
//Get next Chapter/Problem text
var nextProblem = $('.next-problem-label').text();
//Get all html for the problem
var steps = $('.solution-player-steps').children();
for(var i = 0; i < steps.size(); i++){
//This only works for non-canvas elements
var stepInfo = $(steps[i]).find(".step-content").children().first();
if($(stepInfo[0]).html() === ""){
$(newDoc.body).append(cloneCanvas(stepInfo[0]));
$(newDoc.body).append("<br>");
}else{
$(newDoc.body).append(stepInfo.html());
}
}
//Add next problem header
$(newDoc.body).append('<br><u><h1 style="font-weight: bold">' + nextProblem + '</h1></u><br>');
console.log("next problem" + nextProblem);
//Its probably gonna have more than 1 problem in the book
$('.next-problem').click();
}
/*
*Run these lines first
*/
//New doc to put this info in
var impl = document.implementation;
var newDoc = impl.createHTMLDocument("Chegg output");
$(newDoc.body).append('<h1 style="font-weight: bold">FIRST PROBLEM</h1>');
/*
*Run the ripPage() function as many times as you want
*Then run the last two lines to generate the new document
*/
//Write new document to screen
newDoc.body.style.margin = "10px 10px 10px 10px";
document.body = newDoc.body;