Skip to content

Commit

Permalink
Update interaction.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jcponce committed Mar 29, 2024
1 parent 62c3640 commit 9cf4f6f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions dctools/libraries/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,37 @@ $('#copyable-link').blur(function () {
// Check if the user already specified an expression in the URL
$(function () {
const expressionBase64 = trimSpaces(getQueryVariable('expression'));
if (expressionBase64) {
const expression_unicode = trimSpaces(getQueryVariable('expression'));
const checkValue = isBase64Encoded(expressionBase64);
//console.log(isBase64Encoded(expressionBase64));
///if (expressionBase64) {
// $('#equation-input').val(atob(expressionBase64.replace('/', '')));
//}
if(checkValue)
$('#equation-input').val(atob(expressionBase64.replace('/', '')));
}
else
$('#equation-input').val(decodeURIComponent(expression_unicode));

});

// Function to trim leading and trailing spaces
function trimSpaces(s) {
return s.trim ? s.trim() : s.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function isBase64Encoded(str) {
// Remove white spaces from the string before checking
str = str.trim();

// Base64 encoded strings typically have a length that is a multiple of 4
// and only contain characters from the base64 character set, plus optional '=' padding
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;

// Unicode-encoded strings should not match the base64 regex
return base64Regex.test(str);
}


// Function to get the value of a query variable from the URL
function getQueryVariable(variable) {
const query = window.location.search.substring(1);
Expand Down

0 comments on commit 9cf4f6f

Please sign in to comment.