Skip to content

Commit

Permalink
push fixes (no version bump until fully tested)
Browse files Browse the repository at this point in the history
  • Loading branch information
wo-r committed Feb 25, 2024
1 parent 35e4bd9 commit 904a0d9
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 55 deletions.
128 changes: 73 additions & 55 deletions extension/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@

// Set the rest to the default settings.
config("set", "proview_allow_extension_updates", true);
config("set", "proview_stay_logged_in", false);
config("set", "proview_stylesheets", false);
config("set", "proview_remove_thumbnails", false);
config("set", "proview_replace_standards", true);
config("set", "proview_quality_features", true);
config("set", "proview_custom_background", "");
config("set", "proview_hide_courses", "");
config("set", "proview_hide_courses", JSON.stringify([""]));

window.alert("Hey, thanks for using Proview.\n\nThis extension brings a lot of changes to Echo. We recommend that you view the documentation for this extension, the link is available on the settings page of Echo.");
}
Expand Down Expand Up @@ -167,60 +168,6 @@
$("head").append(`<base id="proview-base-change" href="/" target="_blank">`);
})

// Checks for login details, then it uses those details to always create a login that last forever.
new MutationObserver((mutations) => {mutations.forEach(() => {
// This will be here anyways I guess
if (!isEmpty($("body:has(app-before-login)")) && !isEmpty(config("get", "proview_automatic_logins_details"))) {
$.ajax({
url: api("/cmd"),
method: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({"request": {
cmd: "login3",
expireseconds: "-1",
token: get_details.token,
password: JSON.parse(config("get", "proview_automatic_logins_details"))[1],
username: `${window.location.href.split("//")[1].split(".")[0]}/${JSON.parse(config("get", "proview_automatic_logins_details"))[0]}`,
}}),
success: function (json) {
if (json.response.code == "OK") {
let token = json.response.user.token;

json.response.token = token;
json.response.user.id = json.response.user.userid;

delete json.response.user.token;
delete json.response.code;
delete json.response.user.userid;

config("set", "session", JSON.stringify(json.response));

window.location.href = "student/home/courses";
}
}
})

debug_logger("Automatically logging in", 4);
}

// Get details
if (is_page("login") && isEmpty(config("get", "proview_automatic_logins_details"))) {
$("mat-toolbar button[type=\"submit\"]").on("mousedown", function () {
let details = [];
$.each($(".login-fields mat-form-field input"), function () {
if ($(this).val() != "" && details.length != 2)
details.push($(this).val());
})

if (details.length == 2 && isEmpty(config("get", "proview_automatic_logins_details"))) {
config("set", "proview_automatic_logins_details", JSON.stringify(details));
debug_logger("Saved login details", 1);
}
});
}
})}).observe($("body app-root")[0], { childList: true });

// Re-enable all disabled buttons, inputs, and checkboxes.
new MutationObserver(function (mutations) {mutations.forEach(function () {
$("button[disabled], input[disabled], div:has(input[disabled]).mdc-text-field--disabled").removeAttr("disabled").removeClass("mdc-text-field--disabled");
Expand Down Expand Up @@ -286,4 +233,75 @@
})}).observe($("body app-root")[0], { childList: true });
debug_logger(`Actively looking for scores`, 4); // no spam plz
}

// Checks for login details, then it uses those details to create a login session that last forever.
if (is_true_by_string(config("get", "proview_stay_logged_in"))) {
new MutationObserver((mutations) => {mutations.forEach(() => {
if (!isEmpty($("body:has(app-before-login)")) && !isEmpty(config("get", "proview_automatic_logins_details"))) {
$.ajax({
url: api("/cmd"),
method: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({"request": {
cmd: "login3",
expireseconds: "-1",
password: JSON.parse(config("get", "proview_automatic_logins_details"))[1],
username: `${window.location.href.split("//")[1].split(".")[0]}/${JSON.parse(config("get", "proview_automatic_logins_details"))[0]}`,
}}),
success: function (json) {
if (json.response.code == "OK") {
let token = json.response.user.token;

json.response.token = token;
json.response.user.id = json.response.user.userid;

delete json.response.user.token;
delete json.response.code;
delete json.response.user.userid;

config("set", "session", JSON.stringify(json.response));

window.location.href = "/student/home/courses";
}
}
})

debug_logger("Automatically logging in", 4);
}

// Get details (if they don't exist)
if (is_page("login") && isEmpty(config("get", "proview_automatic_logins_details"))) {
$("mat-toolbar button[type=\"submit\"]").on("mousedown", function () {
let details = [];
$.each($(".login-fields mat-form-field input"), function () {
if ($(this).val() != "" && details.length != 2)
details.push($(this).val());
})

// Check if valid
$.ajax({
url: api("/cmd"),
method: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({"request": {
cmd: "login3",
expireseconds: "-1",
password: details[1],
username: `${window.location.href.split("//")[1].split(".")[0]}/${details[0]}`,
}}),
success: (json) => {
if (json.response.code == "OK" && details.length == 2 && isEmpty(config("get", "proview_automatic_logins_details"))) {
config("set", "proview_automatic_logins_details", JSON.stringify(details));
debug_logger("Saved login details", 1);
}
}
})
});
}
})}).observe($("body app-root")[0], { childList: true });
}
else
config("remove", "proview_stay_logged_in");
})();
21 changes: 21 additions & 0 deletions extension/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@
</mat-checkbox>
<!---->
<!---->
<mat-checkbox class="mat-mdc-checkbox mat-accent mat-mdc-checkbox-checked ng-untouched ng-pristine ng-valid">
<div class="mdc-form-field">
<div class="mdc-checkbox">
<div class="mat-mdc-checkbox-touch-target"></div>
<input id="stay_logged_in" type="checkbox" class="mdc-checkbox__native-control mdc-checkbox--selected">
<div class="mdc-checkbox__ripple"></div>
<div class="mdc-checkbox__background">
<svg focusable="false" viewBox="0 0 24 24" class="mdc-checkbox__checkmark">
<path fill="none" d="M1.73,12.91 8.1,19.28 22.79,4.59" class="mdc-checkbox__checkmark-path"></path>
</svg>
<div class="mdc-checkbox__mixedmark"></div>
</div>
<div class="mat-ripple mat-mdc-checkbox-ripple mat-mdc-focus-indicator"></div>
</div>
<label class="mdc-label">Stay logged in</label>
</div>
</mat-checkbox>
<!---->
<!---->
<mat-checkbox class="mat-mdc-checkbox mat-accent mat-mdc-checkbox-checked ng-untouched ng-pristine ng-valid">
<div class="mdc-form-field">
<div class="mdc-checkbox">
Expand Down Expand Up @@ -285,6 +304,7 @@
try {
$("#custom_pfp").prop("value", config("get", "proview_custom_profile_picture"));
$("#update_extension").prop("checked", config("get", "proview_allow_extension_updates") === "true");
$("#stay_logged_in").prop("checked", config("get", "proview_stay_logged_in") === "true");
$("#custom_styles").prop("checked", config("get", "proview_stylesheets") === "true");
$("#remove_thumbnails").prop("checked", config("get", "proview_remove_thumbnails") === "true");
$("#replace_standards").prop("checked", config("get", "proview_replace_standards") === "true");
Expand All @@ -302,6 +322,7 @@
$("app-settings mat-toolbar button:last-child").on("mousedown mouseup", async function (event) {
try {
config("set", "proview_allow_extension_updates", $("#update_extension").prop("checked"));
config("set", "proview_stay_logged_in", $("#stay_logged_in").prop("checked"));
config("set", "proview_stylesheets", $("#custom_styles").prop("checked"));
config("set", "proview_remove_thumbnails", $("#remove_thumbnails").prop("checked"));
config("set", "proview_replace_standards", $("#replace_standards").prop("checked"));
Expand Down

0 comments on commit 904a0d9

Please sign in to comment.