Skip to content

Commit 2311c3c

Browse files
committed
Added "presenter mode" and (re)storing settings from local storage
1 parent cfa6df3 commit 2311c3c

File tree

1 file changed

+55
-8
lines changed

1 file changed

+55
-8
lines changed

src/Pages/Home/JwtDecoder/JwtDecoder.cshtml

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@page "~/jwt-decoder"
1+
@page "~/jwt-decoder"
22
@model IdentityServerHost.Pages.Home.JwtDecoder
33

44
<!-- Google Tag Manager (noscript) -->
@@ -56,7 +56,7 @@
5656
</div>
5757
</div>
5858
</div>
59-
<div class="col-12 col-md-6 pb-4 pb-md-0">
59+
<div class="col-jwt col-12 col-md-6 pb-4 pb-md-0">
6060
<h3>Decoded JWT</h3>
6161
<div class="jwt-decoded-output">
6262
<h4>Header</h4>
@@ -108,7 +108,11 @@
108108
signature: null
109109
};
110110
111-
let explainClaims = false;
111+
const optionsKey = 'jwtDecoderSettings';
112+
let options = {
113+
presenterMode: false,
114+
explainClaims: false
115+
};
112116
113117
function defaultJsonStringifyReplacer(key, value) {
114118
if (value === null || value === undefined) {
@@ -277,14 +281,57 @@
277281
278282
$(document).ready(initializeJwtDecoder);
279283
284+
function readSettingsFromStorage() {
285+
try {
286+
const settings = window.localStorage.getItem(optionsKey);
287+
if (settings) {
288+
options = JSON.parse(settings);
289+
}
290+
291+
$('#explainClaims').prop('checked', options.explainClaims);
292+
$('#togglePresenterMode').prop('checked', options.presenterMode);
293+
jsonStringifyReplacer = options.explainClaims ? expandedJsonStringifyReplacer : defaultJsonStringifyReplacer;
294+
setPresenterMode(options.presenterMode);
295+
}
296+
catch (e) {}
297+
}
298+
299+
function saveSettingsToStorage() {
300+
window.localStorage.setItem(optionsKey, JSON.stringify({
301+
explainClaims: options.explainClaims,
302+
presenterMode: options.presenterMode
303+
}));
304+
}
305+
306+
function setPresenterMode(enabled) {
307+
if (enabled) {
308+
$('.row-jwt').removeClass('align-items-stretch');
309+
$('.col-jwt').removeClass('col-md-6');
310+
$('#jwt-input').parent().removeClass('flex-grow-1');
311+
}
312+
else {
313+
$('.row-jwt').addClass('align-items-stretch');
314+
$('.col-jwt').addClass('col-md-6');
315+
$('#jwt-input').parent().addClass('flex-grow-1');
316+
}
317+
}
318+
280319
async function initializeJwtDecoder() {
281-
const explainClaimsCheckbox = $('#explainClaims');
282-
explainClaims = explainClaimsCheckbox.is(':checked');
283-
explainClaimsCheckbox.on('change', function() {
284-
explainClaims = this.checked;
285-
jsonStringifyReplacer = explainClaims ? expandedJsonStringifyReplacer : defaultJsonStringifyReplacer;
320+
await readSettingsFromStorage();
321+
322+
$('#explainClaims').on('change', async function() {
323+
options.explainClaims = this.checked;
324+
await saveSettingsToStorage();
325+
jsonStringifyReplacer = options.explainClaims ? expandedJsonStringifyReplacer : defaultJsonStringifyReplacer;
286326
updateClaimsExplanation();
287327
});
328+
329+
$('#togglePresenterMode').on('change', async function() {
330+
options.presenterMode = this.checked;
331+
await saveSettingsToStorage();
332+
333+
setPresenterMode(options.presenterMode);
334+
});
288335
289336
$('#jwt-input').on('input', async function() {
290337
decodedJwt = {

0 commit comments

Comments
 (0)