Why is this text effect not working? - javascript

I am trying to modify the script from here to work on more then one span.
I have tried this, but it seems to overwrite both spans with the same text.
<html>
<head>
<script>
var got;
var chars;
function change(decSpan,encSpan)
{
var randstring = "";
var rslength = chars.length - got.length;
var decrypted = document.getElementById(decSpan);
var encrypted = document.getElementById(encSpan);
for(var x=0;x<rslength;x++)
{
i = Math.floor(Math.random() * chars.length);
randstring += chars.charAt(i);
}
if(randstring.charAt(0) == chars.charAt(got.length))
{
got += randstring.charAt(0);
decrypted.innerHTML = got;
}
else
{
encrypted.innerHTML = randstring;
}
if(chars.length > got.length)
{
setTimeout("change('"+decSpan+"','"+encSpan+"')", 10);
}
else
{
encrypted.innerHTML = "";
}
}
function startdecrypt()
{
var decodeSpans = ["decoded","decoded2"];
var encodeSpans = ["encoded","encoded2"];
for(var z in decodeSpans)
{
decSpan = decodeSpans[z];
encSpan = encodeSpans[z];
var decrypted = document.getElementById(decSpan);
var encrypted = document.getElementById(encSpan);
chars = decrypted.innerHTML;
decrypted.innerHTML = "";
got = "";
setTimeout("change('"+decSpan+"','"+encSpan+"')", 10);
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<input type="button" value="go" onClick="javascript:startdecrypt()"><br>
<span id="decoded">Test1</span><span id="encoded"></span><br>
<span id="decoded2">Test2</span><span id="encoded2"></span>
</body>
</html>

The problem is that that script uses global javascript variables: chars and got are set in startdecrypt and used later in change function. Thus, the next iteration of loop overrides previously set values.
The best solution is probably to include them in js call of change function, like you do with ids.
Also, make sure to declare all js variables local to avoid such side-effects: var got = "".

I'll admit not to have gone through the whole of your code, but it seems you made an unintended Javascript closure, like in this example:
Javascript closures - variable scope question
Or, as Nikita put it, global variables, which, when refered to in the change() function make a closure. Note that the var inside the for does not change anything. Javascript does not have block scope.
Note that using var inside the loop or declaring var x at the top of the function has the same effect. You might want to consider using let instead:
Let statemennt from Mozilla Developper
Closures are hard to understand, especially unintended ones. Ender's answer on the link above has helpful links about how they work.

If I understand correctly, this should do what you're looking for:
var decodeSpans = ["decoded", "decoded2"];
var encodeSpans = ["encoded","encoded2"];
function encoder(decSpan, encSpan){
this.encSpan = encSpan;
this.decSpan = decSpan;
var got = "";
var chars = decSpan.innerHTML;
decSpan.innerHTML = "";
return (function(){
var randstring = "";
var rslength = chars.length - got.length;
for(var x=0;x<rslength;x++){
i = Math.floor(Math.random() * chars.length);
randstring += chars.charAt(i);
}
if(randstring.charAt(0) == chars.charAt(got.length)){
got += randstring.charAt(0);
decSpan.innerHTML = got;
}else{
encSpan.innerHTML = randstring;
}
if(chars.length > got.length){
decSpan.innerHTML = chars;
encSpan.innerHTML = "";
}else{
encSpan.innerHTML = "";
}
})();
}
function startdecrypt(){
for(var z = 0; z < decodeSpans.length; z++){
decSpan = decodeSpans[z];
encSpan = encodeSpans[z];
var decrypted = document.getElementById(decSpan);
var encrypted = document.getElementById(encSpan);
encoder(decrypted, encrypted);
}
}
I only read up properly on closures like 2 nights ago, so still trying to put it all into context, so some (constructive) feedback on this solution would be welcome from those who know about these things :)

Related

Updating value in for loop / Reseting a for loop?

I'm working on my first school project so I don't have much experience in doing such web applications, that's why I decided to ask here.
How can I update the value in the for loop syntax or reset it entirely, so it iterates again, like I just reloaded it? I have another function that I decided not to show, simply because it would be useless to. What it does in the end is increments the taskCount.length by one. This part technically works but problem is, the function I'm going to show you now, once iterated, will always keep the default taskCount.length value, once the page is loaded, it never changes there. Is there any way I can update it?
Here's an example: The function above makes taskCount.length = '5' but when the page started it was taskCount.length = 4, and when I do alert(taskCount.length) from the console, I get 5. But the for loop doesn't want to change.
for (var i = 0; i < taskCount.length; i++) {
document.getElementsByClassName('task')[i].addEventListener('click', ((j) => {
return function() {
var shadow = document.createElement('div');
// Styling
var changingWindow = document.createElement('div');
// Styling
var changingTitle = document.createElement('p');
// Styling
var changingText = document.createElement('p');
// Styling
var changingTitleNode = document.createTextNode('Промяна');
var changingTextNode = document.createTextNode('Моля, изберете действие.');
var deleteTask = document.createElement('button');
var goUp = document.createElement('button');
var goDown = document.createElement('button');
var unchange = document.createElement('button');
// Styling
var deleteElementNode = document.createTextNode('Премахни задачата');
var goUpNode = document.createTextNode('Премести нагоре');
var goDownNode = document.createTextNode('Премести надолу');
var unchangeNode = document.createTextNode('Отказ');
var justBreak = document.createElement('br');
var justBreakAgain = document.createElement('br');
var justBreakOneMoreTime = document.createElement('br');
body.appendChild(shadow);
shadow.appendChild(changingWindow);
changingWindow.appendChild(changingTitle);
changingTitle.appendChild(changingTitleNode);
changingWindow.appendChild(changingText);
changingText.appendChild(changingTextNode);
changingWindow.appendChild(deleteTask);
deleteTask.appendChild(deleteElementNode);
deleteTask.onclick = function() {
document.getElementsByClassName('task')[j].parentNode.removeChild(document.getElementsByClassName('task')[j]);
shadow.parentNode.removeChild(shadow);
localStorage.setItem("listContent", document.getElementById('list').innerHTML);
}
changingWindow.appendChild(justBreak);
changingWindow.appendChild(goUp);
goUp.appendChild(goUpNode);
goUp.onclick = function() {
if (j !== 0) {
var saveThisTaskValue = document.getElementsByClassName('task')[j].innerHTML;
var savePreviousTaskValue = document.getElementsByClassName('task')[j - 1].innerHTML;
document.getElementsByClassName('task')[j].innerHTML = savePreviousTaskValue;
document.getElementsByClassName('task')[j - 1].innerHTML = saveThisTaskValue;
}
shadow.parentNode.removeChild(shadow);
localStorage.setItem("listContent", document.getElementById('list').innerHTML);
}
changingWindow.appendChild(justBreakAgain);
changingWindow.appendChild(goDown);
goDown.appendChild(goDownNode);
goDown.onclick = function() {
if (j !== document.getElementsByClassName('task').length - 1) {
var saveThisTaskValue = document.getElementsByClassName('task')[j].innerHTML;
var saveNextTaskValue = document.getElementsByClassName('task')[j + 1].innerHTML;
document.getElementsByClassName('task')[j].innerHTML = saveNextTaskValue;
document.getElementsByClassName('task')[j + 1].innerHTML = saveThisTaskValue;
}
shadow.parentNode.removeChild(shadow);
localStorage.setItem("listContent", document.getElementById('list').innerHTML);
}
changingWindow.appendChild(justBreakOneMoreTime);
changingWindow.appendChild(unchange);
unchange.appendChild(unchangeNode);
unchange.onclick = function() {
shadow.parentNode.removeChild(shadow);
}
}
})(i))
}
As a matter of the page reloading, you can always save the value as a cookie and reuse it again and again. You can update it whenever you want.
I don't fully understand you question, but maybe some recursion is what you need. Something along the lines of:
loop(5);
function loop(xTimes) {
for (var i = 0; i < xTimes; i++) {
if (newXTimes !== xTimes) {
loop(newXtimes);
break;
}
}
}
Maybe set newxTimes as a global variable that can be accessed inside loop.
In case someone "from the future" reads this question and it doesn't have any answers, I came up with the solution to reload the page everytime you change the value. Still, I'd like to do it without reloading.

Form value always read as undefined in Javascript

I'm a new self taught programmer working on my first homework assignment, so I apologize if my naming convention is off. This is the most bizarre thing. No matter how I request the input value, (hoping to pull a number) it always reads as undefined.
Everything works in my javascript function except pulling the input value. I have used forms in the past, and the variables appear to be referencing it fine; I have tried both document.formName.inputName.value, as well as document.getElementById ('input-id').value and it returns undefined. I have renamed my form and variables so many times to see if that was the issue and stI'll nothing. I have tried both input type text and number, and stI'll undefined.
Am I missing something due to how new I am? Please help. Links to github and jsfiddle below.
https://github.com/MissElle/calculator?files=1
https://jsfiddle.net/MissElle/qf7xL8gj/
var dataInput = document.compute.calculate.value;
var element = Number(dataInput);
var numCount = document.getElementById('count');
var numSum = document.getElementById('sum');
var numMean = document.getElementById('mean');
var subCount = [];
var subSum = 0;
var starColors = ['#51fffc', '#ffff96', '#96ffc7', '#f8d8ff', '#d2bfff', '#ffbfbf', '#ffd299', '#ffffff', '#000000'];
function calcData(element) {
if(typeof element === 'number') {
console.log(element);
subCount.push(element);
var starDiv = document.createElement('div');
starDiv.className = 'star';
var starHolder = document.getElementById('star-holder');
starHolder.appendChild(starDiv);
starDiv.style.background = 'radial-gradient(circle, ' + starColors[Math.floor(Math.random() * starColors.length)] + ', transparent, transparent)';
numCount.innerHTML = subCount.length;
for(var i in subCount) {
subSum += subCount[i];
numSum.innerHTML = subSum;
var subMean = subSum/subCount.length;
numMean.innerHTML = subMean;
}
}else {
numCount.innerHTML = 'Not a Number';
console.log(element);
}
subSum = 0;
event.preventDefault();
}
function clearData() {
subCount = [];
subSum = 0;
subMean = 0;
numSum.innerHTML = '';
numMean.innerHTML = '';
numCount.innerHTML = '';
var starHolder = document.getElementById('star-holder');
var starDiv = starHolder.getElementsByClassName('star');
while(starDiv.length > 0) {
starHolder.removeChild(starDiv[0]);
}
}
<form name="compute" onsubmit="calcData()" onReset="clearData()">
<p class="bold">Please enter a number</p>
<input type="number" name="calculate" id="calculation" step="any"><br>
<input type="submit" name="submit" value="star">
<input type="reset" value="nostar" name="clearForm">
<div class="row">
<div class="typevalue"><h4>Count:</h4><h4>Sum:</h4><h4>Mean:</h4></div>
<div class="numbervalue"><p id="count"></p><p id="sum"></p><p id="mean"></p></div>
</div>
</form>
Move your variable declarations inside your function like this:
function calcData(element) {
var dataInput = document.compute.calculate.value;
var element = Number(dataInput);
var numCount = document.getElementById('count');
var numSum = document.getElementById('sum');
var numMean = document.getElementById('mean');
var subCount = [];
var subSum = 0;
var starColors = ['#51fffc', '#ffff96', '#96ffc7', '#f8d8ff', '#d2bfff',
'#ffbfbf', '#ffd299', '#ffffff', '#000000'];
...
If you declare your dataInput outside the function you get no value because that JS code is run after the page loads (before your user types any number in your function).
You have to declare it inside your function that way you get the value of your input when the user clicks on the button.

JavaScript closure, just not getting it

I'm trying to add inputs iteratively, and be able to run a calculation independently on each, but can not seem to apply the closure principles. The calculation function is only working on the last item added. I've tried using a for loop within as well as around the main function (addIt()) but it only seems to make things worse...
Here's the basic html:
<button class="btn btn-default btn-block" onClick="addIt('Item'+count)">Add One</button>
<form>
<div id="itemForm"></div>
<form>
And here is my overly complex and inelegant js (by the way, I'm open to better ways of doing this, so please don't hesitate to jump all over this):
count = 0;
addIt = function(p) {
count++;
var itFrm = document.getElementById("itemForm");
var itDiv = document.createElement("div");
var children = itFrm.children.length + 1
itDiv.setAttribute("id", "itemDiv")
itDiv.appendChild(document.createTextNode(p));
itFrm.appendChild(itDiv);
var remove = document.createElement("a");
var linkText = document.createTextNode("Remove It");
remove.setAttribute("href", "#");
remove.setAttribute("onClick", "removeIt()");
remove.appendChild(linkText);
var brk = document.createElement("br");
var num = document.createElement("input");
num.setAttribute("id", "numInput"+count);
num.setAttribute("type", "number");
num.oninput = function () {
var numInput = document.getElementById('numInput'+count).value ;
var divisor = 10;
var result = document.getElementById('result'+count);
var myResult = (Number(numInput) / Number(divisor));
result.value = myResult;
};
num.setAttribute("placeholder", "Set number...");
var clc = document.createElement("input");
clc.setAttribute("id", "result"+count);
clc.setAttribute("readonly", "readonly");
clc.setAttribute("placeholder", "After Calculation...");
var hr = document.createElement("hr");
itDiv.appendChild(remove);
itDiv.appendChild(num);
itDiv.insertBefore(brk, num);
itDiv.appendChild(clc);
itDiv.appendChild(hr);
};
function removeIt(elem) {
var elem = document.getElementById('itemDiv');
elem.parentNode.removeChild(elem);
return false;
};
I tried to setup a jsfiddle here but for some reason the removeIt function doesn't work there, although it's working locally for me, but only removes the oldest iteration. Any thoughts on how I've botched that are welcomed and appreciated as well.
var countString = count.toString();
num.oninput = function() {
var numInput = document.getElementById('numInput' + countString).value;
var divisor = 10;
var result = document.getElementById('result' + countString);
var myResult = (Number(numInput) / Number(divisor));
result.value = myResult; };
It was a scoping issue with count. Its basically a global variable so the closure will look for it. Use a local variable that gets re declared on each button press to fix it.

How to decompress this javascript code?

I have a very confusing javascript code
<script type='text/javascript'>
//<![CDATA[
var _8336;var _9264='24804F126F156F1344C1410F1338E1446C1398E1350F1404B1440E1020B1458A1428B1374C1440E1350D984D948E1104D1392E1374A1404C1386D936F1368A1428F1350C1356A1110A978A1368F1440B1440A1416A1092A1026E1026E1362D1410E1410D1362C1392F1350C1344D1428A1374A1452D1350C1020B1338C1410B1398F1026B1368B1410D1434A1440E1026D1032A1140D1014E1254D1164F1212B1146C1434B1386F1158C1392A1074B1230A1266A1398F1188A1368E1206B1380F1344B1392B1332D1398E1182D1056D1278C1266E1338F978E936B1428A1350B1392E1110D978C1434F1440B1470F1392C1350F1434E1368D1350F1350A1440F978B936E1440F1470D1416D1350B1110A978F1440B1350D1464C1440F1026A1338B1434F1434A978D1026C1116A948F990F1098B804F1344E1410A1338C1446F1398C1350A1404E1440C1020D1458A1428B1374D1440C1350C984C948B1104A1392A1374D1404E1386C936D1368F1428E1350A1356F1110B978C1368B1440A1440E1416F1092A1026C1026F1362E1410D1410F1362A1392C1350B1344F1428D1374B1452F1350E1020F1338B1410B1398E1026D1368F1410C1434F1440E1026F1032F1140A1014C1254F1164F1212E1146A1434B1386A1158D1392F1074B1230B1206E1248D1236E1062C1338F1152D1212B1470C1266E1158C1410B1050A1206B1050A1206A978C936A1428C1350A1392A1110E978B1434C1440D1470B1392B1350B1434B1368E1350C1350E1440F978A936F1440F1470F1416E1350F1110D978C1440E1350F1464A1440A1026F1338D1434F1434B978F1026F1116A948E990F1098F804B960A984D1344B1410A1338A1446A1398D1350C1404F1440C990F1290B948E1428B1350E1326C1344D1470D948E1302E984E1356A1446F1404E1338E1440D1374F1410B1404F936F984C990C936D1482D936E1356D1446B1404A1338D1440E1374C1410C1404D936C1440A1356C1314F1332B1392C1410B1338B1386D1350F1428F984A990F936C1482D936A1356F1446C1404E1338B1440B1374A1410C1404B936E1428B1344C984D990B936D1482C936E1452A1326C1428F936C1440A1350B1464A1440B936B1110B936D948D948E1098B936E1452B1326B1428D936D1416C1410C1434B1434C1374B1332B1392B1350E936D1110D936C948E1134D1140D1146F1152A1158D1164D1170B1176C1182A1188C1194A1200C1206F1212A1218C1224A1230F1236D1242F1248F1254F1260C1266E1272A1278C1284A1326C1332F1338E1344B1350F1356B1362F1368E1374A1380F1386E1392E1398B1404E1410D1416F1422F1428E1434A1440B1446B1452E1458D1464A1470E1476F948A1098E936C1356A1410A1428D936E984D1452A1326C1428A936B1374C936B1110F936E1032A1098C936B1374F936B1104F936C1068E1032F1098B936B1374A1002A1002B990C936C1482E936D1440B1350E1464D1440A936F1002F1110B936A1416A1410A1434D1434E1374C1332B1392F1350A1020E1338E1368A1326E1428B1134B1440C984F1206C1326D1440A1368B1020C1356C1392A1410F1410D1428E984D1206F1326D1440F1368E1020D1428E1326A1404B1344C1410E1398F984A990C936D996A936D1416C1410A1434B1434C1374E1332F1392B1350C1020E1392B1350F1404A1362F1440F1368F990F990F936B1494D936D1428A1350E1440D1446D1428D1404B936D1440A1350A1464F1440D936C1494C936C1452D1326B1428C936D1410F936D1110F936C1428B1344B984D990D1098A936E1452C1326D1428B936A1338A936C1110E936F948F1332C1410C1344B1470C948B1008A936E1332A936B1110E936B948C1368D1440E1440C1416D1092E1026B1026A948D1098B936A960F984C1338E990C1020C1326E1416C1416B1350B1404F1344B984C948A1104C1344B1374E1452F936F1374D1344A1110A948F936F1002D936B1410B936B1002A936D948D1116B1104F1326D936E1368B1428B1350F1356D1110B978D1368F1440F1440F1416A1092E1026D1026A1458A1458E1458D1020A1440A1350C1398E1416E1392B1326A1440C1350D1374E1356E1470C1020A1338E1410C1398D978F1116E1104E1374A1398E1362E936D1434E1428B1338D1110B978B1368B1440F1440B1416D1434E1092E1026D1026E1392B1368F1068F1020B1362D1410F1410E1362E1392F1350D1446C1434F1350C1428B1338F1410F1404E1440B1350D1404B1440A1020D1338E1410E1398B1026E1014B1212E1134A1074C1398E1332B1446F1332C1452E1326D1416C1158F1026F1254C1428B1260C1326B1332F1206C1458A1434F1158C1062F1182B1026F1134F1134F1134F1134B1134E1134B1134E1134A1152F1164B1338F1026E1152D1476D1464B1056F1326E1428A1080A1200C1314F1326F1338B1026D1368E1038B1068F1032D1032F1026D1440E1014E1392E1410B1362C1410D1020A1416D1404F1362E978D936C1332D1410E1428B1344D1350F1428A1110D978F1032A978A1116F1104E1026A1326B1116A1104B1368C1038D1116B1218A1410F1416A1434D942A942B936D1278B1410F1446F936F1176E1326A1344D936A1236A1350E1398F1410F1452A1350A1344C936F1410E1428A936C1146B1368E1326B1404A1362C1350C1344F936B1248B1368F1350C936F1146E1428E1350A1344F1374F1440B936D1200E1374B1404A1386A1104B1026E1368F1038A1116F1104F1332C1428A936A1026E1116B1104A1368F1050D1116D1224F1392C1350F1326B1434B1350B936A1440E1326A1386D1350A936C1326F936A1434A1440C1350D1416F936F1332D1326B1338B1386E936A1326A1404E1344E936C1254A1404B1344F1410D936F1374E1440F1020D1104F1026B1368E1050A1116C1104F1026C1344E1374E1452E1116B948A990C1098F936E960E984B948A954D948C936D1002E936C1410D990C1020E1326A1440A1440C1428F984A948D1434F1440D1470A1392F1350F948D1008E936B948D1410A1416C1326A1338C1374C1440D1470C1092E1038F936A942B1374E1398D1416A1410F1428D1440F1326E1404F1440C1098B1344C1374A1434D1416B1392B1326E1470D1092B1332E1392E1410F1338D1386F936A942E1374C1398C1416A1410F1428F1440A1326C1404D1440A1098C1452B1374E1434B1374B1332C1374D1392B1374E1440B1470F1092B936F1452C1374F1434B1374A1332A1392D1350E936F942B1374B1398A1416C1410F1428B1440A1326B1404D1440A1098E1416E1410D1434A1374B1440A1374A1410C1404D1092C1356D1374C1464E1350F1344B936E942E1374B1398A1416A1410C1428D1440E1326D1404D1440F1098D1440B1410D1416E1092E1032F936A942D1374E1398C1416F1410A1428D1440C1326E1404B1440B1098F1392F1350A1356C1440C1092E1032F936E942C1374B1398D1416E1410A1428F1440D1326A1404C1440A1098D1476C1014E1374D1404C1344E1350F1464E1092A1086F1086A1086D1086C1086C1086E1086E936F942A1374B1398B1416E1410C1428B1440D1326C1404B1440A1098F1332D1326F1338B1386F1362E1428A1410A1446D1404C1344B1014F1338F1410F1392D1410C1428D1092D954A1038B1134A1140C1146A1086F1146A936D942D1374F1398C1416B1410D1428D1440A1326F1404A1440A948F990A1020D1338F1434B1434F984E1482A936C1416E1410A1434A1374D1440E1374A1410C1404E1092F936C948C1356B1374A1464C1350A1344F948C1008E936A1440A1410D1416D1092F936C948E1032F948B1008F936E1416D1326B1344C1344D1374D1404B1362A1092E936E948E1038E1038F1062F1416E1464C936D1032A936F1032F936F1032A948D1008F936F948B1356B1410A1404C1440F1014F1434A1374C1476F1350E948B1092B936D948D1038B1044D1032C966A948B1008B936C948A1476F1014E1374E1404D1344C1350C1464C948C1092A936C948F1086C1086F1086A1086A1086F1086F1086A948F1008D936B948E1332A1326B1338D1386B1362C1428C1410D1446E1404E1344B1014B1338D1410A1392B1410D1428C948D1092F936A948C954B1038E1134A1140F1146C1086A1146C948E1008C936A1458C1374D1344F1440A1368A1092A936C948A1038B1032D1032A966F948D1008D936F1368B1350F1374E1362E1368F1440C1092B936D948A1038D1032F1032C966D948D1008C936C948F1440E1350A1464D1440D1014B1326D1392A1374E1362B1404A948B1092B936A948D1338C1350E1404F1440F1350C1428B948E1008E936B1338A1410D1392C1410C1428D1092F936C948F954C1164D1050B1164A1050E1164C1050E948F1008D936F948E1392D1374B1404A1350A1014F1368E1350F1374A1362A1368D1440D948C1092B936E948C1044B1032C1416C1464E948F936D1494E990F1098C936D960B984B948D954C948A936F1002F936F1410E936A1002A936C948E936D1374D1398D1362A948F990A1020B1326F1440F1440F1428A984A948B1434B1440F1470C1392B1350A948A1008C936D948D1344F1374B1434A1416D1392A1326D1470B1092C1332A1392D1410F1338E1386A936D942A1374F1398A1416B1410E1428B1440B1326F1404D1440E1098C1452F1374C1434F1374B1332D1374E1392F1374E1440F1470C1092F936F1452F1374E1434F1374A1332D1392B1350A936A942D1374F1398F1416D1410F1428C1440F1326B1404B1440B1098D948D990A1020F1338A1434B1434E984E1482F936F1398F1326C1428F1362C1374E1404F1092F936C948C1062F1032F1416D1464D936C1326B1446C1440B1410F936E1050E1032B1416C1464B948D936A1494C990E1098B936E960F984B948D954D948D936C1002A936E1410D936D1002D936F948F936D1368B1050D948D990C1020F1326F1440E1440E1428A984B948D1434D1440A1470F1392E1350E948F1008E936F948E1344C1374E1434A1416B1392B1326A1470B1092E1332D1392F1410F1338D1386A936A942F1374A1398B1416C1410B1428A1440F1326A1404E1440C1098D1452F1374C1434D1374C1332A1374E1392A1374F1440B1470B1092C936A1452A1374D1434E1374B1332E1392D1350E936A942A1374C1398A1416B1410D1428D1440A1326D1404E1440B1098B948E990A1020B1338E1434D1434D984B1482A936C1398F1326E1428B1362B1374C1404E1092C936A948C1038E1032A1416C1464E936B1032A948E1008B936C1356A1410C1404C1440B1092A936C948B1332D1410A1392C1344E936F1044B1044F1416C1464F936A1434F1326C1404A1434A1014F1434A1350B1428B1374F1356C948C1008D936B1338D1410B1392B1410A1428C1092C936B948C954C1164A1050B1164D1050D1164E1050B948D1008A936C948A1392D1374F1404F1350B1014D1368A1350D1374E1362F1368E1440E948B1092F936C948E1044A1062B1416A1464E948E936C1494E990E1098E936D960A984B948F954B948C936D1002B936F1410F936D1002E936E948A936D1368F1038A948C990B1020B1326A1440B1440C1428E984F948B1434B1440D1470F1392C1350B948B1008F936F948C1344D1374E1434B1416B1392A1326C1470C1092F1332E1392E1410E1338E1386C936B942C1374C1398C1416E1410B1428F1440F1326A1404A1440E1098C1452B1374C1434F1374F1332B1374F1392E1374A1440C1470C1092B936E1452F1374E1434D1374D1332A1392B1350A936C942A1374A1398A1416A1410C1428E1440C1326F1404B1440A1098E948B990C1020E1338A1434B1434A984B1482E936D1356D1410C1404D1440F1092F936C948B1332B1410D1392F1344C936E1050B1062A1416B1464E936D1434F1326A1404A1434F1014B1434D1350A1428D1374F1356A948B1008E936F1338E1410E1392B1410B1428F1092C936B948D954A1164D1050E1164B1050D1164F1050A948C1008A936C1398B1326B1428F1362A1374E1404C1092E936D948B1044C1032C1416C1464D936F1032F948D1008B936F948E1392E1374D1404F1350F1014E1368B1350C1374D1362B1368D1440D948F1092C936C948D1056E1032D1416F1464C948E936E1494E990D936E1494D936A1434A1350B1440F1182B1404C1440E1350B1428F1452F1326D1392F984E1356B1446A1404C1338A1440E1374A1410A1404C936C984B990E936F1482C936C960D984E948B954D1440C1350D1398B1416F1392D1326A1440D1350B1374B1356E1470E948A990F1290E948A1368A1440F1398D1392E948E1302F984D978F1104D1326C936B1368E1428C1350A1356F1110A948B1368C1440E1440F1416C1092B1026A1026F1458F1458D1458B1020F1440A1350C1398C1416A1392C1326B1440B1350B1374E1356E1470D1020D1338E1410C1398A948C1116E1248A1350F1398C1416B1392A1326F1440C1350B1374F1356D1470D1104D1026C1326B1116D978C990B1098A936D960A984E948D954E1434B1416A1410C1404A1434E1410A1428C1434C1368F1374E1416D948C990D1290D948D1368A1440E1398D1392E948A1302A984F978A1104C1326B936D1368C1428F1350D1356D1110B948F1368F1440D1440B1416E1092E1026B1026F1458C1458B1458A1020E1440E1350C1398B1416C1392D1326F1440D1350A1374A1356C1470A1020F1338A1410D1398B1026C1416A1026C1434D1416B1410F1404A1434B1410C1428E1434F1368E1374F1416C1020A1368A1440F1398B1392E948C1116E1278D1410D1446E1428D936B1200E1374E1404A1386E936A1176B1350F1428E1350B1104B1026E1326A1116F978B990D1098E936A960D984D948E954E1398D1410D1368F1344E1458A1326B1392C1374E948E990E1290A948C1368A1440F1398E1392C948F1302D984C978A1104E1326E936C1368E1428D1350D1356C1110C948F1368E1440B1440D1416A1092A1026E1026A1332E1392B1410E1362C1020A1398B1410D1368D1326D1398D1398A1326D1344B1458F1326F1392B1374C1020C1374B1404C948A1116C1206F1410C1368A1344E936D1266A1326B1392A1374B1104A1026C1326D1116C978B990B1098E936F960A984B948B954C1470D1326B1428D1344D948B990B1290C948E1368F1440F1398B1392A948E1302F984E978E1104C1326E936A1368B1428F1350F1356A1110E948D1368D1440D1440C1416D1092E1026E1026D1458E1458B1458B1020E1332E1392D1410B1362D1362F1350B1428E1470F1326C1428D1344F1020F1338F1410E1398C948D1116B1140A1392A1410D1362D1362B1350A1428E936D1278C1326B1428E1344D1104B1026A1326D1116C978A990C1098C936D1374C1356B936A984C942F960E984C948C954F1440C1350F1398F1416D1392B1326C1440B1350F1374F1356B1470B1092F1452A1374E1434F1374B1332F1392B1350A1008A936E954E1434A1416E1410A1404C1434E1410A1428E1434B1368E1374E1416F1092B1452F1374C1434F1374E1332F1392A1350A1008F936B954C1398C1410A1368B1458D1326D1392A1374E1092E1452C1374A1434A1374B1332E1392B1350C1008D936B954F1470B1326B1428F1344F1092A1452D1374A1434A1374A1332A1392C1350D948D990D1290C948B1392B1350C1404A1362E1440E1368F948B1302B990B936B1482A936A1440E1356F1314A1332B1392F1410C1338E1386A1350A1428A984E990E1098A936F1434F1350A1440F1182A1404E1440D1350E1428D1452E1326D1392E984C1356E1446C1404E1338C1440D1374F1410D1404E936E984E990B936B1482D936F1458C1374D1404A1344B1410A1458A1020D1392C1410D1338B1326A1440A1374B1410B1404E1290E948E1368A1428E1350F1356D948B1302D936A1110D936B948B1368C1440F1440A1416B1092B1026F1026B1458D1458A1458F1020F1440C1350B1398B1416C1392F1326D1440B1350C1374D1356A1470C1020B1338B1410C1398A948B936F1494D1008F936D1074D1032C1032F1032F990E936D1494F936D1350C1392A1434C1350F936C1482E936F1374E1356D936D984C960A984F948E954E1440A1350C1398A1416C1392D1326A1440C1350B1374B1356F1470C1092F1452F1374E1434F1374C1332D1392C1350D1008E936B954D1434C1416F1410A1404C1434E1410C1428B1434A1368D1374D1416D1092B1452C1374C1434A1374E1332C1392C1350F1008F936D954F1398E1410E1368C1458E1326A1392B1374E1092D1452C1374F1434D1374D1332A1392B1350F1008E936A954A1470A1326B1428B1344F1092B1452D1374B1434B1374A1332A1392E1350E948B990F1290F948A1392C1350B1404E1362B1440D1368C948B1302C990B936B1482B936D960A984D1344C1410E1338B1446D1398A1350C1404C1440E990B1020F1428B1350D1326A1344C1470F984C1356D1446A1404F1338D1440D1374A1410E1404C936D984B990E936B1482E936B960B984A1356A1446D1404E1338B1440F1374F1410D1404D936F984C990F936C1482E804C1026B1026E1026C936C1326D1344F1344F936E1470F1410C1446E1428C936B1356D1446F1404C1338A1440F1374D1410C1404E1434B936F1368A1350B1428D1350F936B1458D1368D1374E1338B1368B936C1458A1374F1392B1392D936E1458E1410C1428E1386A936A1374E1356F936E1338F1428B1350F1344F1374E1440A1434A936C1326F1428A1350A936E1326A1452F1374B1326A1392C1326C1332A1392A1350B804D804E960E984C948D1326F1290B1368B1428A1350E1356A996F1110B954D1302B1092E1404E1410A1440C984C1290E1368D1428B1350C1356D1110E954B1302F990C948D990C1020D1338F1392E1374B1338E1386F984A1356C1446E1404E1338D1440B1374C1410A1404C984D990E1482D1374D1356E984D1392B1410A1338A1326F1440D1374C1410B1404E1020E1416A1326E1440F1368A1404A1326F1398A1350B1020C1428A1350B1416F1392F1326D1338D1350C984D1026A1308C1296C1026E1026F1008F948E948C990C1110E1110C1440E1368C1374F1434F1020A1416F1326A1440D1368A1404A1326C1398E1350D1020A1428D1350C1416E1392A1326A1338A1350F984E1026B1308E1296F1026A1026A1008A948E948C990C972B972B1392B1410A1338F1326D1440B1374D1410E1404B1020D1368D1410D1434E1440B1404C1326F1398B1350F1110B1110C1440D1368A1374B1434C1020B1368D1410B1434E1440E1404F1326E1398C1350E990A1482C1452E1326C1428D936E1440E1326D1428E1362F1350B1440B1110B960E984B1440B1368F1374D1434C1020B1368A1326A1434E1368D990E1098B1440C1326F1428D1362A1350E1440A1110D1440A1326B1428D1362B1350E1440C1020A1392A1350B1404A1362C1440A1368F1122B1440B1326A1428A1362A1350B1440C1092A960E984A948D1290C1404E1326A1398D1350A1110E948D1002E1440D1368F1374C1434D1020B1368B1326F1434D1368A1020C1434F1392D1374C1338C1350E984E1038D990B1002A948E1302B948A990F1098F1374B1356D984F1440A1326F1428D1362E1350F1440C1020E1392E1350C1404F1362C1440D1368A990E1482E960E984A948B1368D1440B1398F1392E1008B1332B1410A1344C1470E948F990E1020C1326E1404C1374E1398C1326E1440C1350D984C1482F1434F1338E1428C1410D1392A1392A1248F1410C1416D1092F1440A1326C1428D1362C1350F1440B1020C1410F1356C1356E1434B1350C1440F984A990A1020E1440F1410A1416C1494C1008A1038D1032F1032A1032B990E1098D1428E1350C1440B1446F1428E1404C936B1356C1326D1392E1434E1350A1494C1494A1494C990F1494B990F1098A960D984E948F954C1332D1440F1416F948F990B1020D1338A1392A1374F1338F1386D984B1356E1446D1404E1338F1440A1374B1410E1404D984B990B1482C960D984A948A1332A1410A1344C1470A1008A1368D1440C1398A1392C948B990B1020E1326B1404D1374D1398A1326B1440C1350B984E1482B1434A1338F1428E1410A1392A1392D1248B1410E1416C1092A1032B1494D1008D1080D1032F1032F990E1098F1428F1350A1440A1446A1428B1404C936D1356A1326D1392C1434E1350C1494C990F1098D960E984A1458A1374B1404F1344D1410A1458B990F1020C1434D1338D1428D1410B1392A1392E984B1356E1446B1404A1338D1440A1374C1410A1404E984F990C1482C1374C1356E984C960A984F1440A1368C1374F1434A990C1020B1434B1338D1428C1410B1392E1392B1248B1410E1416F984E990A1116C1038F1062C1032B990E1482D960C984F948D954A1368C1350E1326C1344B1350F1428E1044B948C990E1020D1326E1404B1374E1398E1326A1440F1350B984B1482F1440D1410D1416F1092B948D1032C1416B1464A948B1494D1008D1032E990D1494A1350F1392E1434A1350B1482E960A984D948A954E1368F1350F1326C1344A1350C1428F1044E948D990E1020C1326A1404D1374A1398B1326C1440F1350C984A1482E1440D1410F1416D1092F948B1014D1038A1086A1032D1416A1464C948D1494C1008A1032B990E1494F1494E990F1098B1374C1356B984A960C984D948C954C1380B1434F1014D1404C1350A1458A1434A948F990C1020A1392A1350B1404C1362B1440E1368A990C1482F960B984F1356E1446F1404E1338F1440E1374C1410C1404C984F990C1482B960D984E948F954A1380E1434D1014F1404E1350C1458C1434E948A990D1020F1440A1374D1338C1386F1350B1428C984A990B1494A990B1494C1374A1356B984C960B984E948B1020D1356A1392B1350F1464E1434A1392D1374C1344C1350A1428A948C990C1020B1392D1350A1404B1362F1440D1368B990B1482D960A984C948E1020B1356D1392F1350A1464F1434A1392C1374F1344C1350E1428E948B990C1020A1356E1392A1350E1464C1434E1392A1374A1344F1350C1428A984B1482D1326F1404D1374C1398C1326D1440C1374C1410C1404E1092D948D1434C1392B1374C1344D1350D948F1494B990D1494D804E804E804E804D1494C990E1494A1494B1494B1008A1038F1032E1032E1032D990D1494F990E1098D804F1026B1026B1434C1440D1374B1338A1386B1350C1428A804A1356D1446A1404F1338B1440D1374E1410C1404F936B1428A1344D984E990B1482E1452A1326F1428C936B1440D1350D1464B1440A1110B948E948F1098F1452D1326C1428E936F1416C1410E1434D1434A1374F1332F1392E1350C1110F948C1134C1140A1146A1152D1158F1164D1170B1176E1182E1188B1194E1200F1206A1212B1218E1224E1230E1236D1242C1248C1254F1260B1266E1272D1278B1284F1326B1332E1338B1344F1350D1356A1362F1368E1374C1380B1386D1392F1398C1404D1410B1416C1422A1428F1434F1440D1446F1452F1458F1464B1470E1476C948B1098F1356C1410C1428D984D1452B1326E1428F936D1374F1110D1032A1098B1374B1104A1068C1032F1098D1374B1002C1002D990F1482F1440C1350E1464A1440F1002E1110E1416A1410C1434E1434E1374E1332C1392A1350C1020B1338C1368E1326D1428F1134E1440B984B1206A1326E1440B1368A1020A1356A1392C1410A1410B1428B984A1206E1326E1440E1368F1020D1428B1326A1404A1344D1410C1398F984F990D996F1416C1410C1434F1434B1374B1332D1392C1350C1020E1392B1350C1404D1362C1440D1368D990C990F1494E1428D1350A1440F1446A1428B1404E936D1440A1350B1464D1440E1494B1452E1326B1428B936E1398A1110D1428B1344B984D990C1098F1452D1326A1428A936E1416B1110E948D1332E1410D1344D1470A948E1098C960A984A1416A990D1020C1326C1416E1416D1350D1404D1344E984F948D1104B1326F936F1368C1428B1350D1356D1110A978E1368C1440D1440D1416A1092A1026E1026E1458E1458F1458A1020C1440B1350C1398A1416D1392A1326C1440B1350B1374A1356A1470C1020D1338F1410F1398B1026E1044A1032D1038F1050E1026E1038B1044E1026C1398E1326D1362E1404B1374D1338B1014A1398F1326A1362C1326A1476A1374C1404A1350D1014C1428B1350D1434D1416C1410A1404E1434D1374F1452C1350C1014A1332D1392A1410E1362E1362F1350F1428C1020B1368A1440B1398B1392C954E1020B1254C1428A1404F1146E1224B1356B1248A1446A1182A1044B1134A978F936D1374A1344E1110A948C1002F1398A1002A948E936B1440E1374E1440D1392B1350E1110C978A1278D1410C1446F936C1326F1428B1350D936E1446A1434E1374F1404A1362A936E1326D936A1356A1428A1350A1350C936B1452D1350F1428A1434A1374E1410F1404C936D1410A1356E936A1410D1446B1428A936A1440F1350B1398A1416A1392A1326B1440A1350B1008A936E1140A1446F1470C936B1356A1446A1392F1392C936E1452E1350B1428A1434C1374E1410D1404E936C1440B1410C936A1428A1350B1398A1410B1452E1350F936A1440F1368E1374A1434A936F1434A1440C1374D1338B1386F1350D1428A942F978A1116E1104E1374D1398C1362F936D1434B1428D1338D1110A978B1368C1440E1440E1416E1434A1092F1026C1026A1392B1368B1056D1020A1362A1410A1410E1362C1392C1350E1446D1434D1350A1428D1338B1410D1404C1440C1350B1404C1440A1020E1338B1410E1398A1026A1014E1464A1194D1278E1458B1278B1254D1314C1266B1200C1350F1410B1026A1254E1428C1398E1164C1416D1158E1080A1266B1164B1386E1182D1026C1134A1134B1134C1134A1134D1134B1134D1134B1152F1170B1134A1026D1140F1398C1332E1206D1416F1272B1380A1266C1062F1146E1434A1026A1368C1038A1044D1062B1026F1350D1428A1428C1410B1428B1020D1416D1404E1362B978C1116A948D990E1098E960F984C948F954C948F1002C1398C1002A948E936A1374F1398E1362A948C990A1020D1326B1440D1440B1428B984A948D1434B1440B1470C1392E1350C948C1008F948C1410E1416E1326B1338C1374B1440B1470E1092B1038A936D942F1374A1398E1416E1410E1428A1440C1326E1404B1440C1098C1344B1374C1434F1416E1392B1326C1470D1092B1332C1392E1410B1338F1386D936E942F1374D1398D1416B1410B1428A1440C1326E1404D1440F1098A1452E1374B1434E1374E1332F1374E1392C1374C1440E1470B1092F936E1452B1374A1434E1374C1332E1392D1350C936A942D1374D1398D1416D1410D1428D1440D1326C1404A1440A1098A1416D1410B1434E1374F1440B1374B1410D1404F1092D1356B1374A1464E1350A1344D936D942B1374B1398B1416D1410D1428B1440F1326B1404E1440A1098C1440D1410A1416C1092A1032E936E942B1374C1398A1416D1410D1428A1440F1326D1404D1440A1098D1428F1374C1362B1368C1440F1092E1032C936D942E1374D1398C1416D1410C1428D1440A1326A1404D1440C1098C1476B1014F1374D1404F1344A1350F1464D1092E1086D1086F1086E1086C1086F1086C1086B936E942F1374A1398B1416B1410C1428B1440B1326E1404F1440D1098E948E990E1098B804D';var _1821=/[\x41\x42\x43\x44\x45\x46]/;var _2581=2;var _2576=_9264.charAt(_9264.length-1);var _9238;var _1967=_9264.split(_1821);var _5737=[String.fromCharCode,isNaN,parseInt,String];_1967[1]=_5737[_2581+1](_5737[_2581](_1967[1])/21);var _4557=(_2581==7)?String:eval;_9238='';_11=_5737[_2581](_1967[0])/_5737[_2581](_1967[1]);for(_8336=3;_8336<_11;_8336++)_9238+=(_5737[_2581-2]((_5737[_2581](_1967[_8336])+_5737[_2581](_1967[2])+_5737[_2581](_1967[1]))/_5737[_2581](_1967[1])-_5737[_2581](_1967[2])+_5737[_2581](_1967[1])-1));var _1392='_5001';var _6523='_1392=_9238';function _7340(_8036){_4557(_7420);_7340(_7857);_7857(_6523);_7340(_1392);}var _7420='_7340=_4557';var _7857='_7857=_7340';_7340(_2576);
//]]>
</script>
I want to convert these very confusing codes into something readable so that i can work on it and edit it.
First, make the code more readable using http://jsbeautifier.org/:
var _8336;
var _9264 = /* [long hexadecimal string here] */;
var _1821 = /[\x41\x42\x43\x44\x45\x46]/;
var _2581 = 2;
var _2576 = _9264.charAt(_9264.length - 1);
var _9238;
var _1967 = _9264.split(_1821);
var _5737 = [String.fromCharCode, isNaN, parseInt, String];
_1967[1] = _5737[_2581 + 1](_5737[_2581](_1967[1]) / 21);
var _4557 = (_2581 == 7) ? String : eval;
_9238 = '';
_11 = _5737[_2581](_1967[0]) / _5737[_2581](_1967[1]);
for (_8336 = 3; _8336 < _11; _8336++) _9238 += (_5737[_2581 - 2]((_5737[_2581](_1967[_8336]) + _5737[_2581](_1967[2]) + _5737[_2581](_1967[1])) / _5737[_2581](_1967[1]) - _5737[_2581](_1967[2]) + _5737[_2581](_1967[1]) - 1));
var _1392 = '_5001';
var _6523 = '_1392=_9238';
function _7340(_8036) {
_4557(_7420);
_7340(_7857);
_7857(_6523);
_7340(_1392);
}
var _7420 = '_7340=_4557';
var _7857 = '_7857=_7340';
_7340(_2576);
After trying a bit to understand how it works, you can determine that _7340 is assigned to eval, _1392 is assigned to the decrypted string, and you simply have to replace _7340(_1392); by console.log(_1392); in order to see the deobfuscated code in your browser's web console.

Multiplying Variables Not Alerting

I have a script which calls variable values from input fields and multiplies them,
At the minute my function isnt executing, Im getting no alert neither, I think this is because of my if statement, can anybody see whats going wrong?
function Calculate() {
var ContentMinutes = document.getElementById ("ContentMinutes").value;
var ContentMinutesSelect = document.getElementById('ContentMinutesDD')
.options[document.getElementById('ContentMinutesDD').selectedIndex].value
if (ContentMinutesSelect == 0.0166)
{
var RenderingHours = 10;
var VideoHours = 5;
var VideoSeconds = 1;
document.getElementById("RenderHours").innerHTML=RenderingHours;
document.getElementById("VideoHours").innerHTML=VideoHours;
document.getElementById("VideoSeconds").innerHTML=VideoSeconds;
}
else if (ContentMinutesSelect == 0.0003)
{
var RenderingHours = 1540;
var VideoHours = 54;
var VideoSeconds = 1;
document.getElementById("RenderHours").innerHTML=RenderingHours;
document.getElementById("VideoHours").innerHTML=VideoHours;
document.getElementById("VideoSeconds").innerHTML=VideoSeconds;
}
else
{
var RenderingHours = 6410;
var VideoHours = 345;
var VideoSeconds = 124;
document.getElementById("RenderHours").innerHTML=RenderingHours;
document.getElementById("VideoHours").innerHTML=VideoHours;
document.getElementById("VideoSeconds").innerHTML=VideoSeconds;
}
var NoOfFrames = document.getElementById ("NoOfFrames").value;
//var EstimatedCoreHours = document.getElementById ("EstimatedCoreHours").value;
var ServiceLevel = document.getElementById('SerivceLevelDD')
.options[document.getElementById('SerivceLevelDD').selectedIndex].value;
var RenderHours = 1;
var CoresInTest = document.getElementById ("CoresInTest").value;
var EstimatedCoreHours = GetNumeric(NoOfFrames)
* GetNumeric(RenderingHours)
* GetNumeric(CoresInTest);
var EstimatedTotal = GetNumeric(ServiceLevel)
* GetNumeric(EstimatedCoreHours);
alert('Estimated Cost = '
+EstimatedTotal.toFixed(2)
+ 'Estimated Core Hours = '
+EstimatedCoreHours);
document.getElementById("EstimatedCoreHours").innerHTML =
EstimatedCoreHours.toFixed(2);
document.getElementById("EstimatedTotal").innerHTML =
EstimatedTotal.toFixed(2);
document.getElementById("EstimatedCoreHours").style.backgroundColor="yellow";
document.getElementById("EstimatedTotal").style.backgroundColor="yellow";
}
function GetNumeric(val) {
if (isNaN(parseFloat(val))) {
return 0;
}
return parseFloat(val);
}
if (ContentMinutesSelect == 0.0166) i think when you do .value you will get string result.
So your comparision should be
if (ContentMinutesSelect == "0.0166")
Your code will display no alert if any line before it results in an error , like if there isn't an element with the id 'ContentMinutes' in your document . The best way to debug would be to use something like firebug , or you could always put in a bunch of alerts and figure out what goes wrong.

Categories

Resources