Skip to content

Commit 5293245

Browse files
committed
Method to Store Content shown
Additionally added a feature that adds an event listener and saves the current language to the users local storage, if not defiend previously. If it is defined it loads the selected language from this example Cpp or Csharp. Which will be asked each time a refresh is called or page is reloaded. Additionally Pressing the Button either cpp or Csharp will rewrite the Language Preference and store it to locally. Note: This Requires that the JavaScript would be made globally not for each instance where possible. Make sure that only specified buttons are called so make cases if there are less or more languages. " in the future figure out where to store these as all in the same file would be an overkill potentially ".
1 parent 1e26e23 commit 5293245

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

docs/Concepts/OOP.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@ has_children: false
2525
<button onclick="showContent('csharp')">C#</button>
2626

2727
<script>
28+
function setLanguagePreference(language) {
29+
localStorage.setItem('languagePreference', language);
30+
}
31+
32+
function getLanguagePreference() {
33+
return localStorage.getItem('languagePreference');
34+
}
35+
2836
function showContent(language) {
37+
setLanguagePreference(language);
38+
2939
if (language === 'cpp') {
3040
document.getElementById('cppContent').style.display = 'block';
3141
document.getElementById('csharpContent').style.display = 'none';
@@ -34,4 +44,11 @@ has_children: false
3444
document.getElementById('csharpContent').style.display = 'block';
3545
}
3646
}
47+
48+
document.addEventListener('DOMContentLoaded', function () {
49+
var savedLanguage = getLanguagePreference();
50+
if (savedLanguage) {
51+
showContent(savedLanguage);
52+
}
53+
});
3754
</script>

0 commit comments

Comments
 (0)