-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch-inject2.js
executable file
·186 lines (157 loc) · 4.63 KB
/
match-inject2.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Get the script element by its ID
var scriptElement = document.getElementById("__NEXT_DATA__");
// Extract the content of the script element
var scriptContent = scriptElement.textContent;
// Parse the content as JSON
var jsonData = JSON.parse(scriptContent);
// console.log("Json data:", jsonData)
// console.log(jsonData.props.pageProps.dehydratedReduxStateKey)
// this is a list of all cards...
var datadata = JSON.parse(jsonData.props.pageProps.dehydratedReduxStateKey);
// console.log(datadata)
datadata = datadata.studyModesCommon.studiableData.studiableItems;
// console.log(datadata)
// console.log(window.Quizlet["matchModeData"].terms);
var termsSmall = [];
//this should be a list
// let studyItems = window.Quizlet["matchModeData"].terms;
let studyItems = datadata;
for (let card of studyItems) {
//useful variables to take...
//self explanatory
let cardID = card.id;
//word and definition
let cardSidesMap = card.cardSides.map(e => e.label);
//WORD
//(check if this fails!)
if (cardSidesMap.indexOf("word") == -1) {
//we have a problem
console.log("skipping card... no word")
console.log(card);
continue;
}
//now map the media of this card side...
let wordMediaMap = card.cardSides[cardSidesMap.indexOf("word")].media.map(e => e.type);
// console.log(wordMediaMap);
//now find index 1...
if (wordMediaMap.indexOf(1) == -1) {
//we have a problem
console.log("skipping card... no word type 1 media")
console.log(card, wordMediaMap);
continue;
}
let word = card.cardSides[cardSidesMap.indexOf("word")].media[wordMediaMap.indexOf(1)].plainText;
//definition (check if this also fails)
if (cardSidesMap.indexOf("definition") == -1) {
//we have a problem
console.log("skipping card... no definition")
console.log(card);
continue;
}
//now map the media of this card side...
let defMediaMap = card.cardSides[cardSidesMap.indexOf("definition")].media.map(e => e.type);
// console.log(defMediaMap);
//now find index 1...
if (defMediaMap.indexOf(1) == -1) {
//we have a problem
console.log("skipping card... no def type 1 media")
console.log(card, defMediaMap);
continue;
}
let definition = card.cardSides[cardSidesMap.indexOf("definition")].media[defMediaMap.indexOf(1)].plainText;
console.log({
"id":cardID,
"term":word,
"def":definition,
});
termsSmall.push(
{
"id":cardID,
"term":word,
"def":definition,
}
);
}
console.log("termsSmall,",termsSmall);
//create element
var newNode = document.createElement('div');
//add text to element
newNode.innerHTML = `<p id='convenientCode' style='display:none'>`+JSON.stringify(termsSmall)+`</p>
<style>
.quizletpluspluspopupcontainer {
pointer-events:none;
position:absolute;
bottom:0px;
right:0px;
width:300px;
height:800px;
overflow:hidden;
display:flex;
flex-direction:column-reverse;
justify-content:flex-start;
}
.quizletpluspluspopup {
background:rgba(0,0,0,0.5);
padding:1px;
font-size:12px;
color:black;
}
.rightAnswer:hover {
border:.125rem dashed #ffcd1f;
}
.rightAnswerAlways {
border:.125rem dashed #ffcd1f;
background:#fafafa;
}
.matchplusplus {
position: absolute;
top: 0px;
right: 0px;
font-size: 36px;
/* background: gray; */
width: 50px;
height: 50px;
line-height: 1;
display: flex;
align-content: center;
flex-wrap: wrap;
justify-content: center;
padding-bottom: 4px;
cursor:pointer;
border-radius: 0px 5px 0px 0px;
user-select: none;
color: gold;
}
.matchplusplus.selected {
}
.matchplusplus:hover {
background:#eee;
color: #B59410;
}
</style>
`;
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
waitForElm('.cvmjmph').then(elm => {
var referenceNode = document.querySelector('.cvmjmph');
// Insert the new node before the reference node
referenceNode.after(newNode); // sometimes fails.
//it aint over until the phat console sings
console.log("element added");
});