Last active
July 23, 2021 15:34
-
-
Save bpatra/4087052461a87c37a8d81cf80513a31e to your computer and use it in GitHub Desktop.
Force internalisation of quizz courses in iadvize AppNorth Academy
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
<style> | |
@font-face { | |
font-family: "ProximaNova-Bold"; | |
src: url("https://s3-us-west-2.amazonaws.com/static.schoolkeep.com/fonts/ProximaNova-Bold.ttf"); | |
} | |
@font-face { | |
font-family: "ProximaNova-Reg"; | |
src: url("https://s3-us-west-2.amazonaws.com/static.schoolkeep.com/fonts/proximanova-regular-webfont.woff"); | |
} | |
</style> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
let courseId = window.location.href.split("/")[4]; | |
const englishCourses = { | |
"9tjjinyy" : "Asynchronous conversations" , | |
"qrhqavpu": "Take care of your Customer Satisfaction" , | |
"tcyl8aef": "The art of chatting", | |
"dackkuga": "💡 Get onboard : Key features to know", | |
"fx5szeh2": "How to deal with visitors on Covid-19", | |
"6rinxles": "Meet ibbü experts", | |
"sxc0wakt": "Optimize conversion with mobile visitors", | |
"xldserbb": "Your new conversation panel", | |
"qzrtkawd": "Beta Collaborative training", | |
"dackkuga": "💡 Get onboard : Key features to know", | |
"zfzo9xam": "Snooze for all", | |
"dxto8jix": "Samsung", | |
"aitzmsl6": "bPatra - My tailor is Rich" | |
} | |
$(document).ready(function() { | |
if(englishCourses[courseId]) { | |
window.I18n.translations.fr = window.I18n.translations.en; | |
} | |
}); | |
window.hack_translated = false; | |
let courseID = window.location.href.split("/")[4]; | |
function $iFrame(selector){ | |
var iFrame = $('#quiz-embed'); | |
return $(selector, iFrame.contents()) | |
} | |
function translateSummary(){ | |
let summary = $iFrame("p.quiz-summary__text--charcoal").html(); | |
summary = summary.split(" "); | |
// ["You", "scored", "0%", "with", "0", "of", "2", "questions", "answered", "correctly."] | |
// Vous avez obtenu un score de 30% en répondant correctement à 3 sur 10. Vous pouvez consulter la synthèse de vos réponses ci-dessous. | |
// ["Vous", "avez", "obtenu", "un", "score", "de", "30%", "en", "repondant", "correctement", a, 3, sur, 10] | |
let translatedSummary = `You scored ${summary[10]} by answering correctly to ${summary[15]} out of ${summary[17]} You can see the summary of your answers below.`; | |
$iFrame("p.quiz-summary__text--charcoal").html(translatedSummary); | |
} | |
function translateProgression(){ | |
let progression = $iFrame(".uk-article .uk-article-meta").html(); | |
progression = progression.replace("sur", "on"); | |
$iFrame(".uk-article .uk-article-meta").html(progression); | |
} | |
function listenToDom() { | |
const body = document.getElementsByTagName("body")[0]; | |
const config = { attributes: true, childList: true, subtree: true }; | |
const callback = function(mutationsList, observer) { | |
if ($iFrame("p.quiz-summary__text--charcoal").length) { | |
translateContent(); | |
//observer.disconnect(); | |
} else { | |
window.hack_translated = false; | |
} | |
}; | |
const observer = new MutationObserver(callback); | |
observer.observe(body, config); | |
} | |
function translateContent() { | |
if (!window.hack_translated) { | |
try{ | |
translateSummary(); //translated the summary | |
}catch(ex){console.log("Error localizing summary")} | |
try{ | |
translateProgression(); // translate the progression: e.g. 1 on 10 | |
}catch(ex){console.log("Error localizing progression")} | |
try{ | |
$iFrame("h2.uk-panel-title").html("You have completed this questionnaire"); // translate subheader | |
}catch(ex){console.log("Error localizing sub header")} | |
try{ | |
// Do not localize the "see all your answers" | |
$iFrame(".quiz-summary__learner-answer p.uk-margin-small-bottom.uk-margin-top.sk-text-medium").html("Your answer") | |
$iFrame("span.quiz-summary__text--charcoal").hide(); | |
$iFrame("a.uk-link").hide(); | |
}catch(ex){console.log("Error hiding trainling sentence")} | |
window.hack_translated = true; | |
} | |
} | |
$(window).bind("load", function() { | |
if (englishCourses[courseID]) { | |
console.log("start localization"); | |
if ($iFrame("p.quiz-summary__text--charcoal")) { | |
setTimeout(translateContent, 1000); | |
} | |
listenToDom(); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment