Skip to content

Commit

Permalink
Merge pull request #1 from IC1101Virgo/IC1101Virgo-patch-1
Browse files Browse the repository at this point in the history
Update quiz.js
  • Loading branch information
IC1101Virgo authored Jul 13, 2024
2 parents 59d2397 + 7fcd9d3 commit e2dbec0
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion site/static/js/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function selectQuizOption(selectedId, autoselect = true) {
}
}

function initQuiz() {
async function initQuiz() {
try {
$(".option-button").click(function (e) {
$(this).parent().find(".option-button").removeClass("active");
Expand All @@ -58,6 +58,23 @@ function initQuiz() {
// use the name "macos" to match the button
userOS = "macos";
}
let arch = null;
try {
// currently compatible with these browsers: https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues#browser_compatibility
let architecture = await navigator.userAgentData.getHighEntropyValues(['architecture'])
switch( architecture.architecture ){
case "arm" :{
arch = "arm64"
break
}
case "x86" :{
arch = "x86-64"
break
}
}
}catch(e){
console.log(e)
}
$(".option-row[data-level=0]").removeClass("hide");

const urlParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -87,6 +104,15 @@ function initQuiz() {
const btn = $(".option-button[data-quiz-id='/" + userOS + "']").first();
btn.addClass("active");
selectQuizOption(btn.attr("data-quiz-id"));
// auto-select OS arch for user
if (arch){
const btn = $(".option-button[data-quiz-id='/" + userOS + "/" + arch + "']").first();
// disacitve all buttons of the row first
const row = $(".option-row[data-quiz-id='/" + userOS + "']").first()
row.find(".option-button").removeClass("active");
btn.addClass("active");
selectQuizOption(btn.attr("data-quiz-id"));
}
}
} catch (e) {
const elements = document.getElementsByClassName("quiz-instruction");
Expand Down

0 comments on commit e2dbec0

Please sign in to comment.