The script writes the slider indicator position value to the xml file. But it fails to read and set the xml value.
The alert box in the save/read xml functions lists the xml variables. I am expecting the slider indicator to match the numerical vlaue in the xml variable.
I have a feeling the issue is with the switch statements in the read/write xml functions. Are these lines correct?
Read function:
case 'slider': myXML[a] = o[a].value; break;
Write function:
case 'slider': o[a].value = myXML[a] != '' ? (myXML[a] == 'true' ? 1 : 0) : o[a].value; break;
Reference screenshots. The slider indicator is at 0 instead of 63.
var w = new Window("dialog","test",undefined,{closeButton: true});
var group1 = w.add("group");
mySlider = group1.add("slider");
mySlider.minvalue = 0;
mySlider.maxvalue = 100;
//mySlider.value = 0;
mySlider.preferredSize.length = 195;
mySlider.preferredSize.height = 15;
mySliderEtxt = group1.add("edittext",undefined,"0");
mySliderEtxt.preferredSize=[50,20];
mySlider.onChanging = function(){
mySliderEtxt.text = mySlider.value;
}
mySliderEtxt.onChanging = function(){
mySlider.value = mySliderEtxt.text;
}
ok = group1.add("button", undefined, "Set", { name: "set" })
cancel = group1.add("button", undefined, "Close", { name: "close" })
settingsSlider1 = { sliderOne: mySlider, textItemOne: mySliderEtxt}
ok.onClick = function () {
w.close()
saveToXML(settingsSlider1, 'Simple Sider')
}
cancel.onClick = function () {
w.close()
}
w.onShow = function () {
readFromXML(settingsSlider1, 'Simple Sider')
}
w.show();
function saveToXML(o, xmlName) {
var f = new File(Folder.desktop + '/' + xmlName + '.xml'),
myXML = new XML('<variables></variables>');
for (var a in o) {
switch (o[a].type) {
case 'edittext': myXML[a] = o[a].text; break;
case 'checkbox': myXML[a] = o[a].value; break;
case 'radiobutton': myXML[a] = o[a].value; break;
case 'dropdownlist': myXML[a] = o[a].selection ? o[a].selection.text : ''; break;
case 'slider': myXML[a] = o[a].value; break;
}
}
alert('Save XML \n'+myXML);
f.encoding = "UTF8"
f.open('w');
f.write(myXML.toXMLString())
f.close();
}
function readFromXML(o, xmlName) {
var f = new File(Folder.desktop + '/' + xmlName + '.xml');
f.encoding = "UTF8";
f.open('r');
var myXML = new XML(f.read());
f.close();
for (var a in o) {
switch (o[a].type) {
case 'edittext': o[a].text = myXML[a] != '' ? myXML[a] : o[a].text; break;
case 'checkbox': o[a].value = myXML[a] != '' ? (myXML[a] == 'true' ? 1 : 0) : o[a].value; break;
case 'radiobutton': o[a].value = myXML[a] != '' ? (myXML[a] == 'true' ? 1 : 0) : o[a].value; break;
case 'dropdownlist': o[a].selection = myXML[a] != '' ? o[a].find(myXML[a]) : 0; break;
case 'slider': o[a].value = myXML[a] != '' ? (myXML[a] == 'true' ? 1 : 0) : o[a].value; break;
}
}
alert('Read XML \n'+myXML);
f.encoding = "UTF8"
f.open('w');
f.write(myXML.toXMLString())
f.close();
}
You have to add one line:
w.onShow = function () {
readFromXML(settingsSlider1, 'Simple Sider');
mySlider.value = mySliderEtxt.text; // <-------------- HERE
}
I got this script that seems to be obfuscated, and the original programmer is not reachable. I've tried many methods to decode it, but the best I get are variables and functions that don't make much sense.
Could someone provide me some help?
var _0x1b5a=['\x74\x61\x62\x6c\x65','\x72\x65\x74\x75\x72\x6e\x20\x28\x66\x75\x6e\x63\x74\x69\x6f\x6e\x28\x29\x20','\x70\x6a\x75\x66\x4a','\x74\x72\x61\x63\x65','\x69\x6e\x66\x6f','\x53\x48\x45\x61\x61','\x61\x70\x65\x6c\x69\x64\x6f','\x6c\x6f\x67\x67\x65\x64','\x71\x74\x64\x55\x73\x75\x61\x72\x69\x6f\x73\x4f\x6e\x6c\x69\x6e\x65','\x4c\x70\x6a\x55\x72','\x63\x6f\x6e\x6e\x65\x63\x74\x65\x64','\x74\x65\x6c\x61','\x41\x53\x75\x51\x51','\x4f\x4d\x78\x61\x55','\x5e\x28\x5b\x5e\x20\x5d\x2b\x28\x20\x2b\x5b\x5e\x20\x5d\x2b\x29\x2b\x29\x2b\x5b\x5e\x20\x5d\x7d','\x33\x7c\x30\x7c\x37\x7c\x32\x7c\x35\x7c\x31\x7c\x34\x7c\x36','\x65\x72\x72\x6f','\x73\x61\x6c\x76\x61\x72','\x76\x65\x72\x73\x61\x6f\x43\x6c\x61\x73\x73','\x48\x71\x4d\x72\x4a','\x65\x7a\x61\x45\x4e','\x63\x6f\x6e\x73\x6f\x6c\x65','\x70\x72\x65\x76\x65\x6e\x74\x44\x65\x66\x61\x75\x6c\x74','\x73\x65\x6e\x68\x61\x42\x65\x74\x33\x36\x35','\x31\x7c\x33\x7c\x32\x7c\x34\x7c\x30','\x77\x61\x72\x6e','\x76\x65\x72\x73\x69\x6f\x6e','\x76\x65\x72\x73\x61\x6f','\x73\x74\x61\x74\x75\x73','\x74\x63\x55\x56\x72','\x61\x70\x70\x6c\x79','\x73\x65\x6e\x64\x4d\x65\x73\x73\x61\x67\x65','\x64\x6f\x4c\x6f\x67\x6f\x75\x74','\x67\x65\x74','\x69\x73\x45\x6e\x76\x69\x61\x6e\x64\x6f\x46\x6f\x72\x6d','\x66\x71\x53\x4d\x61','\x63\x6f\x6e\x66\x69\x67\x43\x61\x73\x61\x41\x70\x6f\x73\x74\x61','\x6c\x6c\x72\x71\x71','\x79\x62\x63\x69\x4b','\x73\x76\x77\x4a\x72','\x72\x75\x6e\x74\x69\x6d\x65','\x77\x79\x79\x52\x64','\x5a\x4a\x4e\x56\x7a','\x73\x70\x6c\x69\x74','\x73\x74\x6f\x72\x61\x67\x65','\x76\x61\x6c\x6f\x72\x55\x6e\x69\x64\x61\x64\x65\x42\x65\x74\x33\x36\x35','\x65\x72\x72\x6f\x72','\x65\x6d\x61\x69\x6c','\x6f\x6e\x4d\x65\x73\x73\x61\x67\x65','\x23\x6d\x61\x69\x6e','\x63\x54\x54\x77\x45','\x73\x65\x6e\x68\x61','\x64\x65\x62\x75\x67','\x72\x65\x74\x75\x72\x6e\x20\x2f\x22\x20\x2b\x20\x74\x68\x69\x73\x20\x2b\x20\x22\x2f','\x61\x64\x64\x4c\x69\x73\x74\x65\x6e\x65\x72','\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72','\x6c\x6f\x67','\x74\x69\x70\x6f\x55\x73\x65\x72','\x65\x78\x63\x65\x70\x74\x69\x6f\x6e','\x6f\x6e\x6c\x6f\x61\x64','\x4c\x49\x55\x59\x76','\x53\x66\x70\x69\x77','\x45\x59\x7a\x48\x6f','\x7b\x7d\x2e\x63\x6f\x6e\x73\x74\x72\x75\x63\x74\x6f\x72\x28\x22\x72\x65\x74\x75\x72\x6e\x20\x74\x68\x69\x73\x22\x29\x28\x20\x29','\x6d\x73\x67','\x65\x6e\x76\x69\x61\x6e\x64\x6f\x46\x6f\x72\x6d','\x49\x46\x4a\x50\x6b','\x64\x61\x74\x61','\x74\x41\x55\x55\x4f','\x63\x6f\x6e\x66\x69\x67','\x67\x65\x74\x4d\x61\x6e\x69\x66\x65\x73\x74','\x6b\x65\x79\x43\x6f\x64\x65','\x75\x73\x75\x61\x72\x69\x6f\x42\x65\x74\x33\x36\x35'];(function(_0x16ab9f,_0x1b5a7a){var _0x2ba715=function(_0x5cec0c){while(--_0x5cec0c){_0x16ab9f['push'](_0x16ab9f['shift']());}};var _0x1af375=function(){var _0xdd7ef1={'data':{'key':'cookie','value':'timeout'},'setCookie':function(_0x243201,_0x564c0f,_0x1228c2,_0xf84db7){_0xf84db7=_0xf84db7||{};var _0x216cfb=_0x564c0f+'='+_0x1228c2;var _0x140083=0x0;for(var _0xc0ade0=0x0,_0x206be6=_0x243201['length'];_0xc0ade0<_0x206be6;_0xc0ade0++){var _0x3fe404=_0x243201[_0xc0ade0];_0x216cfb+=';\x20'+_0x3fe404;var _0x51f2c6=_0x243201[_0x3fe404];_0x243201['push'](_0x51f2c6);_0x206be6=_0x243201['length'];if(_0x51f2c6!==!![]){_0x216cfb+='='+_0x51f2c6;}}_0xf84db7['cookie']=_0x216cfb;},'removeCookie':function(){return'dev';},'getCookie':function(_0x58d2f1,_0x19b3fc){_0x58d2f1=_0x58d2f1||function(_0x158582){return _0x158582;};var _0x1ae707=_0x58d2f1(new RegExp('(?:^|;\x20)'+_0x19b3fc['replace'](/([.$?*|{}()[]\/+^])/g,'$1')+'=([^;]*)'));var _0x4e5b62=function(_0x12d18a,_0x28a461){_0x12d18a(++_0x28a461);};_0x4e5b62(_0x2ba715,_0x1b5a7a);return _0x1ae707?decodeURIComponent(_0x1ae707[0x1]):undefined;}};var _0x44a2e0=function(){var _0x32210f=new RegExp('\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*[\x27|\x22].+[\x27|\x22];?\x20*}');return _0x32210f['test'](_0xdd7ef1['removeCookie']['toString']());};_0xdd7ef1['updateCookie']=_0x44a2e0;var _0x32ceda='';var _0x5638a9=_0xdd7ef1['updateCookie']();if(!_0x5638a9){_0xdd7ef1['setCookie'](['*'],'counter',0x1);}else if(_0x5638a9){_0x32ceda=_0xdd7ef1['getCookie'](null,'counter');}else{_0xdd7ef1['removeCookie']();}};_0x1af375();}(_0x1b5a,0xc3));var _0x2ba7=function(_0x16ab9f,_0x1b5a7a){_0x16ab9f=_0x16ab9f-0x0;var _0x2ba715=_0x1b5a[_0x16ab9f];return _0x2ba715;};var _0x243201=function(){var _0x11fd75=!![];return function(_0xa74c1d,_0xe3c57c){var _0x261b9c=_0x11fd75?function(){if(_0xe3c57c){var _0x469a37=_0xe3c57c[_0x2ba7('\x30\x78\x33\x36')](_0xa74c1d,arguments);_0xe3c57c=null;return _0x469a37;}}:function(){};_0x11fd75=![];return _0x261b9c;};}();var _0x5638a9=_0x243201(this,function(){var _0x3f1742={};_0x3f1742[_0x2ba7('\x30\x78\x32\x31')]=_0x2ba7('\x30\x78\x32\x36');_0x3f1742[_0x2ba7('\x30\x78\x33\x35')]=function(_0x48b5c5){return _0x48b5c5();};var _0x4a31ce=_0x3f1742;var _0x2c0b21=function(){var _0x154f12=_0x2c0b21[_0x2ba7('\x30\x78\x36')](_0x2ba7('\x30\x78\x34'))()['\x63\x6f\x6d\x70\x69\x6c\x65'](_0x4a31ce['\x4c\x70\x6a\x55\x72']);return!_0x154f12['\x74\x65\x73\x74'](_0x5638a9);};return _0x4a31ce[_0x2ba7('\x30\x78\x33\x35')](_0x2c0b21);});_0x5638a9();var _0xdd7ef1=function(){var _0x5b5961=!![];return function(_0xc7fbe8,_0x2ab9fd){var _0x224de1=_0x5b5961?function(){if(_0x2ab9fd){var _0x52ffb5=_0x2ab9fd[_0x2ba7('\x30\x78\x33\x36')](_0xc7fbe8,arguments);_0x2ab9fd=null;return _0x52ffb5;}}:function(){};_0x5b5961=![];return _0x224de1;};}();var _0x5cec0c=_0xdd7ef1(this,function(){var _0x57fc36={};_0x57fc36[_0x2ba7('\x30\x78\x34\x32')]=_0x2ba7('\x30\x78\x32\x37');_0x57fc36[_0x2ba7('\x30\x78\x63')]=function(_0x14e3ce,_0x46080d){return _0x14e3ce(_0x46080d);};_0x57fc36[_0x2ba7('\x30\x78\x33\x66')]=function(_0x2afa66,_0x5be2bf){return _0x2afa66+_0x5be2bf;};_0x57fc36[_0x2ba7('\x30\x78\x33\x64')]=function(_0x50bad1){return _0x50bad1();};var _0xd46126=_0x57fc36;var _0x478f98=_0x2ba7('\x30\x78\x33\x30')['\x73\x70\x6c\x69\x74']('\x7c');var _0x5437c0=0x0;while(!![]){switch(_0x478f98[_0x5437c0++]){case'\x30':if(!_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')]){_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')]=function(_0x429b35){var _0x231c56={};_0x231c56['\x6c\x6f\x67']=_0x429b35;_0x231c56['\x77\x61\x72\x6e']=_0x429b35;_0x231c56[_0x2ba7('\x30\x78\x33')]=_0x429b35;_0x231c56[_0x2ba7('\x30\x78\x31\x63')]=_0x429b35;_0x231c56[_0x2ba7('\x30\x78\x34\x36')]=_0x429b35;_0x231c56[_0x2ba7('\x30\x78\x39')]=_0x429b35;_0x231c56[_0x2ba7('\x30\x78\x31\x38')]=_0x429b35;_0x231c56[_0x2ba7('\x30\x78\x31\x62')]=_0x429b35;return _0x231c56;}(_0x3d5d81);}else{var _0x478062=_0xd46126[_0x2ba7('\x30\x78\x34\x32')]['\x73\x70\x6c\x69\x74']('\x7c');var _0x203db5=0x0;while(!![]){switch(_0x478062[_0x203db5++]){case'\x30':_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')][_0x2ba7('\x30\x78\x33\x31')]=_0x3d5d81;continue;case'\x31':_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')][_0x2ba7('\x30\x78\x39')]=_0x3d5d81;continue;case'\x32':_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')][_0x2ba7('\x30\x78\x31\x63')]=_0x3d5d81;continue;case'\x33':_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')][_0x2ba7('\x30\x78\x37')]=_0x3d5d81;continue;case'\x34':_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')]['\x74\x61\x62\x6c\x65']=_0x3d5d81;continue;case'\x35':_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')][_0x2ba7('\x30\x78\x34\x36')]=_0x3d5d81;continue;case'\x36':_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')]['\x74\x72\x61\x63\x65']=_0x3d5d81;continue;case'\x37':_0x5dce2d[_0x2ba7('\x30\x78\x32\x64')][_0x2ba7('\x30\x78\x33')]=_0x3d5d81;continue;}break;}}continue;case'\x31':var _0x45d015={};_0x45d015['\x53\x48\x45\x61\x61']=function(_0x1573c4,_0x47601e){return _0xd46126['\x53\x66\x70\x69\x77'](_0x1573c4,_0x47601e);};_0x45d015['\x74\x41\x55\x55\x4f']=function(_0x16739e,_0xdaebce){return _0xd46126[_0x2ba7('\x30\x78\x33\x66')](_0x16739e,_0xdaebce);};_0x45d015['\x70\x6a\x75\x66\x4a']=_0x2ba7('\x30\x78\x31\x39');_0x45d015[_0x2ba7('\x30\x78\x32\x62')]=_0x2ba7('\x30\x78\x65');var _0x1dbc61=_0x45d015;continue;case'\x32':var _0x56a491=function(){var _0x31dab6;try{_0x31dab6=_0x1dbc61[_0x2ba7('\x30\x78\x31\x64')](Function,_0x1dbc61[_0x2ba7('\x30\x78\x31\x33')](_0x1dbc61[_0x2ba7('\x30\x78\x31\x33')](_0x1dbc61[_0x2ba7('\x30\x78\x31\x61')],_0x1dbc61[_0x2ba7('\x30\x78\x32\x62')]),'\x29\x3b'))();}catch(_0x4901f7){_0x31dab6=window;}return _0x31dab6;};continue;case'\x33':var _0x3d5d81=function(){};continue;case'\x34':var _0x5dce2d=_0xd46126[_0x2ba7('\x30\x78\x33\x64')](_0x56a491);continue;}break;}});_0x5cec0c();function main(){var _0x2efbad={};_0x2efbad[_0x2ba7('\x30\x78\x64')]=_0x2ba7('\x30\x78\x33\x38');_0x2efbad[_0x2ba7('\x30\x78\x33\x62')]='\x64\x6f\x4c\x6f\x67\x69\x6e';_0x2efbad[_0x2ba7('\x30\x78\x62')]=_0x2ba7('\x30\x78\x32\x39');_0x2efbad[_0x2ba7('\x30\x78\x32\x63')]=function(_0x3f39bb,_0x27794a){return _0x3f39bb==_0x27794a;};_0x2efbad[_0x2ba7('\x30\x78\x31')]=_0x2ba7('\x30\x78\x31\x34');_0x2efbad[_0x2ba7('\x30\x78\x34\x31')]=_0x2ba7('\x30\x78\x32\x38');_0x2efbad['\x49\x46\x4a\x50\x6b']='\x67\x65\x74\x53\x74\x61\x74\x75\x73';_0x2efbad[_0x2ba7('\x30\x78\x32\x35')]=_0x2ba7('\x30\x78\x30');var _0x13ebaf=_0x2efbad;var _0x5b2666={};_0x5b2666[_0x2ba7('\x30\x78\x31\x66')]=![];_0x5b2666['\x69\x64']='';_0x5b2666[_0x2ba7('\x30\x78\x31\x65')]='';_0x5b2666['\x65\x6d\x61\x69\x6c']='';_0x5b2666[_0x2ba7('\x30\x78\x31\x37')]='';_0x5b2666[_0x2ba7('\x30\x78\x32')]='';_0x5b2666[_0x2ba7('\x30\x78\x32\x66')]='';_0x5b2666[_0x2ba7('\x30\x78\x32\x32')]=![];_0x5b2666[_0x2ba7('\x30\x78\x32\x38')]='';_0x5b2666['\x76\x61\x6c\x6f\x72\x55\x6e\x69\x64\x61\x64\x65\x42\x65\x74\x33\x36\x35']=0.5;_0x5b2666[_0x2ba7('\x30\x78\x38')]=0x1;_0x5b2666[_0x2ba7('\x30\x78\x33\x33')]=chrome[_0x2ba7('\x30\x78\x34\x30')][_0x2ba7('\x30\x78\x31\x35')]()[_0x2ba7('\x30\x78\x33\x32')];_0x5b2666[_0x2ba7('\x30\x78\x32\x61')]='';_0x5b2666['\x74\x65\x6c\x61']='';_0x5b2666['\x65\x6e\x76\x69\x61\x6e\x64\x6f\x46\x6f\x72\x6d']=![];_0x5b2666[_0x2ba7('\x30\x78\x32\x30')]=0x0;var _0x2f4180={};_0x2f4180[_0x2ba7('\x30\x78\x33\x61')]=function(){return this[_0x2ba7('\x30\x78\x31\x30')];};app=new Vue({'\x65\x6c':_0x13ebaf[_0x2ba7('\x30\x78\x32\x35')],'\x64\x61\x74\x61':_0x5b2666,'\x6d\x65\x74\x68\x6f\x64\x73':{'\x6c\x6f\x67\x6f\x75\x74':function(){var _0x18b8e6={};_0x18b8e6[_0x2ba7('\x30\x78\x66')]=_0x13ebaf[_0x2ba7('\x30\x78\x64')];chrome[_0x2ba7('\x30\x78\x34\x30')][_0x2ba7('\x30\x78\x33\x37')](_0x18b8e6);},'\x6c\x6f\x67\x69\x6e':function(_0xcd676a){var _0x27c34c='\x34\x7c\x31\x7c\x32\x7c\x30\x7c\x33'[_0x2ba7('\x30\x78\x34\x33')]('\x7c');var _0x1420a9=0x0;while(!![]){switch(_0x27c34c[_0x1420a9++]){case'\x30':var _0xdeec2a={};_0xdeec2a[_0x2ba7('\x30\x78\x66')]=_0x13ebaf[_0x2ba7('\x30\x78\x33\x62')];_0xdeec2a[_0x2ba7('\x30\x78\x34\x37')]=this[_0x2ba7('\x30\x78\x34\x37')];_0xdeec2a[_0x2ba7('\x30\x78\x32')]=this['\x73\x65\x6e\x68\x61'];chrome[_0x2ba7('\x30\x78\x34\x30')][_0x2ba7('\x30\x78\x33\x37')](_0xdeec2a);continue;case'\x31':app['\x65\x72\x72\x6f']='';continue;case'\x32':_0xcd676a[_0x2ba7('\x30\x78\x32\x65')]();continue;case'\x33':return![];case'\x34':app[_0x2ba7('\x30\x78\x31\x30')]=!![];continue;}break;}},'\x62\x74\x53\x61\x6c\x76\x61\x72':function(){var _0x27e90f={};_0x27e90f[_0x2ba7('\x30\x78\x34\x35')]=this[_0x2ba7('\x30\x78\x34\x35')];_0x27e90f['\x75\x73\x75\x61\x72\x69\x6f\x42\x65\x74\x33\x36\x35']=this[_0x2ba7('\x30\x78\x31\x37')];_0x27e90f[_0x2ba7('\x30\x78\x32\x66')]=this[_0x2ba7('\x30\x78\x32\x66')];var _0xc15cf1={};_0xc15cf1[_0x2ba7('\x30\x78\x66')]=_0x13ebaf[_0x2ba7('\x30\x78\x62')];_0xc15cf1[_0x2ba7('\x30\x78\x31\x32')]=_0x27e90f;chrome[_0x2ba7('\x30\x78\x34\x30')]['\x73\x65\x6e\x64\x4d\x65\x73\x73\x61\x67\x65'](_0xc15cf1);app['\x74\x65\x6c\x61']='';},'\x6f\x6e\x6c\x79\x4e\x75\x6d\x62\x65\x72':function(_0x629849){if(_0x13ebaf[_0x2ba7('\x30\x78\x32\x63')](_0x629849[_0x2ba7('\x30\x78\x31\x36')],0x2e)){_0x629849[_0x2ba7('\x30\x78\x32\x65')]();}},'\x62\x74\x43\x6f\x6e\x66\x69\x67':function(){app[_0x2ba7('\x30\x78\x32\x33')]=_0x13ebaf[_0x2ba7('\x30\x78\x31')];},'\x62\x74\x56\x6f\x6c\x74\x61\x72':function(){app[_0x2ba7('\x30\x78\x32\x33')]='';}},'\x63\x6f\x6d\x70\x75\x74\x65\x64':_0x2f4180,'\x63\x72\x65\x61\x74\x65\x64':function(){var _0x457076={};_0x457076[_0x2ba7('\x30\x78\x33\x65')]=_0x2ba7('\x30\x78\x33\x63');_0x457076['\x41\x53\x75\x51\x51']=_0x13ebaf[_0x2ba7('\x30\x78\x34\x31')];var _0x927392=_0x457076;chrome[_0x2ba7('\x30\x78\x34\x30')][_0x2ba7('\x30\x78\x34\x38')][_0x2ba7('\x30\x78\x35')](function(_0x471314,_0x3da1bf,_0x55f11d){switch(_0x471314[_0x2ba7('\x30\x78\x66')]){case _0x2ba7('\x30\x78\x33\x34'):app[_0x2ba7('\x30\x78\x31\x30')]=![];app[_0x2ba7('\x30\x78\x31\x66')]=_0x471314['\x6c\x6f\x67\x67\x65\x64']?_0x471314[_0x2ba7('\x30\x78\x31\x66')]:![];app['\x61\x70\x65\x6c\x69\x64\x6f']=_0x471314[_0x2ba7('\x30\x78\x31\x65')]?_0x471314['\x61\x70\x65\x6c\x69\x64\x6f']:'';app[_0x2ba7('\x30\x78\x32\x32')]=_0x471314[_0x2ba7('\x30\x78\x32\x32')];app[_0x2ba7('\x30\x78\x38')]=_0x471314['\x74\x69\x70\x6f\x55\x73\x65\x72'];app[_0x2ba7('\x30\x78\x32\x33')]=_0x471314[_0x2ba7('\x30\x78\x32\x33')]?_0x471314['\x74\x65\x6c\x61']:'';app[_0x2ba7('\x30\x78\x32\x30')]=_0x471314[_0x2ba7('\x30\x78\x32\x30')];app[_0x2ba7('\x30\x78\x32\x61')]=_0x471314[_0x2ba7('\x30\x78\x32\x61')];chrome[_0x2ba7('\x30\x78\x34\x34')]['\x6c\x6f\x63\x61\x6c'][_0x2ba7('\x30\x78\x33\x39')]([_0x927392[_0x2ba7('\x30\x78\x33\x65')]],_0x40dfc8=>{if(_0x40dfc8[_0x2ba7('\x30\x78\x33\x63')]){app[_0x2ba7('\x30\x78\x31\x37')]=_0x40dfc8[_0x2ba7('\x30\x78\x33\x63')][_0x2ba7('\x30\x78\x31\x37')];app['\x73\x65\x6e\x68\x61\x42\x65\x74\x33\x36\x35']=_0x40dfc8['\x63\x6f\x6e\x66\x69\x67\x43\x61\x73\x61\x41\x70\x6f\x73\x74\x61'][_0x2ba7('\x30\x78\x32\x66')];app[_0x2ba7('\x30\x78\x34\x35')]=_0x40dfc8[_0x2ba7('\x30\x78\x33\x63')][_0x2ba7('\x30\x78\x34\x35')];}});app['\x65\x72\x72\x6f']='';break;case _0x927392[_0x2ba7('\x30\x78\x32\x34')]:app[_0x2ba7('\x30\x78\x31\x30')]=![];app[_0x2ba7('\x30\x78\x32\x38')]=_0x471314[_0x2ba7('\x30\x78\x34\x36')];_0x471314['\x74\x65\x6c\x61']='';break;}_0x55f11d();});var _0x4e2e02={};_0x4e2e02[_0x2ba7('\x30\x78\x66')]=_0x13ebaf[_0x2ba7('\x30\x78\x31\x31')];chrome['\x72\x75\x6e\x74\x69\x6d\x65'][_0x2ba7('\x30\x78\x33\x37')](_0x4e2e02);}});}var app;window[_0x2ba7('\x30\x78\x61')]=main;
I've seen a very similar question here: Encoded JavaScript: How to decode?
But couldn't quite follow the instructions.
The decoder just keeps breaking down and it keeps giving me an Unable error.
https://beautifier.io/ is all you need. Just make sure to toggle this setting
Unescape printable chars encoded as \xNN or \uNNNN?
So your original 15k lines of code becomes
(function(_0x16ab9f, _0x1b5a7a) {
var _0x2ba715 = function(_0x5cec0c) {
while (--_0x5cec0c) {
_0x16ab9f['push'](_0x16ab9f['shift']());
}
};
var _0x1af375 = function() {
var _0xdd7ef1 = {
'data': {
'key': 'cookie',
'value': 'timeout'
},
'setCookie': function(_0x243201, _0x564c0f, _0x1228c2, _0xf84db7) {
_0xf84db7 = _0xf84db7 || {};
var _0x216cfb = _0x564c0f + '=' + _0x1228c2;
var _0x140083 = 0x0;
for (var _0xc0ade0 = 0x0, _0x206be6 = _0x243201['length']; _0xc0ade0 < _0x206be6; _0xc0ade0++) {
var _0x3fe404 = _0x243201[_0xc0ade0];
_0x216cfb += '; ' + _0x3fe404;
var _0x51f2c6 = _0x243201[_0x3fe404];
_0x243201['push'](_0x51f2c6);
_0x206be6 = _0x243201['length'];
if (_0x51f2c6 !== !![]) {
_0x216cfb += '=' + _0x51f2c6;
}
}
_0xf84db7['cookie'] = _0x216cfb;
},
'removeCookie': function() {
return 'dev';
},
'getCookie': function(_0x58d2f1, _0x19b3fc) {
_0x58d2f1 = _0x58d2f1 || function(_0x158582) {
return _0x158582;
};
var _0x1ae707 = _0x58d2f1(new RegExp('(?:^|; )' + _0x19b3fc['replace'](/([.$?*|{}()[]\/+^])/g, '$1') + '=([^;]*)'));
var _0x4e5b62 = function(_0x12d18a, _0x28a461) {
_0x12d18a(++_0x28a461);
};
_0x4e5b62(_0x2ba715, _0x1b5a7a);
return _0x1ae707 ? decodeURIComponent(_0x1ae707[0x1]) : undefined;
}
};
var _0x44a2e0 = function() {
var _0x32210f = new RegExp('\\w+ *\\(\\) *{\\w+ *[\'|\"].+[\'|\"];? *}');
return _0x32210f['test'](_0xdd7ef1['removeCookie']['toString']());
};
_0xdd7ef1['updateCookie'] = _0x44a2e0;
var _0x32ceda = '';
var _0x5638a9 = _0xdd7ef1['updateCookie']();
if (!_0x5638a9) {
_0xdd7ef1['setCookie'](['*'], 'counter', 0x1);
} else if (_0x5638a9) {
_0x32ceda = _0xdd7ef1['getCookie'](null, 'counter');
} else {
_0xdd7ef1['removeCookie']();
}
};
_0x1af375();
}(_0x1b5a, 0xc3));
var _0x2ba7 = function(_0x16ab9f, _0x1b5a7a) {
_0x16ab9f = _0x16ab9f - 0x0;
var _0x2ba715 = _0x1b5a[_0x16ab9f];
return _0x2ba715;
};
var _0x243201 = function() {
var _0x11fd75 = !![];
return function(_0xa74c1d, _0xe3c57c) {
var _0x261b9c = _0x11fd75 ? function() {
if (_0xe3c57c) {
var _0x469a37 = _0xe3c57c[_0x2ba7('0x36')](_0xa74c1d, arguments);
_0xe3c57c = null;
return _0x469a37;
}
} : function() {};
_0x11fd75 = ![];
return _0x261b9c;
};
}();
var _0x5638a9 = _0x243201(this, function() {
var _0x3f1742 = {};
_0x3f1742[_0x2ba7('0x21')] = _0x2ba7('0x26');
_0x3f1742[_0x2ba7('0x35')] = function(_0x48b5c5) {
return _0x48b5c5();
};
var _0x4a31ce = _0x3f1742;
var _0x2c0b21 = function() {
var _0x154f12 = _0x2c0b21[_0x2ba7('0x6')](_0x2ba7('0x4'))()['compile'](_0x4a31ce['LpjUr']);
return !_0x154f12['test'](_0x5638a9);
};
return _0x4a31ce[_0x2ba7('0x35')](_0x2c0b21);
});
_0x5638a9();
var _0xdd7ef1 = function() {
var _0x5b5961 = !![];
return function(_0xc7fbe8, _0x2ab9fd) {
var _0x224de1 = _0x5b5961 ? function() {
if (_0x2ab9fd) {
var _0x52ffb5 = _0x2ab9fd[_0x2ba7('0x36')](_0xc7fbe8, arguments);
_0x2ab9fd = null;
return _0x52ffb5;
}
} : function() {};
_0x5b5961 = ![];
return _0x224de1;
};
}();
var _0x5cec0c = _0xdd7ef1(this, function() {
var _0x57fc36 = {};
_0x57fc36[_0x2ba7('0x42')] = _0x2ba7('0x27');
_0x57fc36[_0x2ba7('0xc')] = function(_0x14e3ce, _0x46080d) {
return _0x14e3ce(_0x46080d);
};
_0x57fc36[_0x2ba7('0x3f')] = function(_0x2afa66, _0x5be2bf) {
return _0x2afa66 + _0x5be2bf;
};
_0x57fc36[_0x2ba7('0x3d')] = function(_0x50bad1) {
return _0x50bad1();
};
var _0xd46126 = _0x57fc36;
var _0x478f98 = _0x2ba7('0x30')['split']('|');
var _0x5437c0 = 0x0;
while (!![]) {
switch (_0x478f98[_0x5437c0++]) {
case '0':
if (!_0x5dce2d[_0x2ba7('0x2d')]) {
_0x5dce2d[_0x2ba7('0x2d')] = function(_0x429b35) {
var _0x231c56 = {};
_0x231c56['log'] = _0x429b35;
_0x231c56['warn'] = _0x429b35;
_0x231c56[_0x2ba7('0x3')] = _0x429b35;
_0x231c56[_0x2ba7('0x1c')] = _0x429b35;
_0x231c56[_0x2ba7('0x46')] = _0x429b35;
_0x231c56[_0x2ba7('0x9')] = _0x429b35;
_0x231c56[_0x2ba7('0x18')] = _0x429b35;
_0x231c56[_0x2ba7('0x1b')] = _0x429b35;
return _0x231c56;
}(_0x3d5d81);
} else {
var _0x478062 = _0xd46126[_0x2ba7('0x42')]['split']('|');
var _0x203db5 = 0x0;
while (!![]) {
switch (_0x478062[_0x203db5++]) {
case '0':
_0x5dce2d[_0x2ba7('0x2d')][_0x2ba7('0x31')] = _0x3d5d81;
continue;
case '1':
_0x5dce2d[_0x2ba7('0x2d')][_0x2ba7('0x9')] = _0x3d5d81;
continue;
case '2':
_0x5dce2d[_0x2ba7('0x2d')][_0x2ba7('0x1c')] = _0x3d5d81;
continue;
case '3':
_0x5dce2d[_0x2ba7('0x2d')][_0x2ba7('0x7')] = _0x3d5d81;
continue;
case '4':
_0x5dce2d[_0x2ba7('0x2d')]['table'] = _0x3d5d81;
continue;
case '5':
_0x5dce2d[_0x2ba7('0x2d')][_0x2ba7('0x46')] = _0x3d5d81;
continue;
case '6':
_0x5dce2d[_0x2ba7('0x2d')]['trace'] = _0x3d5d81;
continue;
case '7':
_0x5dce2d[_0x2ba7('0x2d')][_0x2ba7('0x3')] = _0x3d5d81;
continue;
}
break;
}
}
continue;
case '1':
var _0x45d015 = {};
_0x45d015['SHEaa'] = function(_0x1573c4, _0x47601e) {
return _0xd46126['Sfpiw'](_0x1573c4, _0x47601e);
};
_0x45d015['tAUUO'] = function(_0x16739e, _0xdaebce) {
return _0xd46126[_0x2ba7('0x3f')](_0x16739e, _0xdaebce);
};
_0x45d015['pjufJ'] = _0x2ba7('0x19');
_0x45d015[_0x2ba7('0x2b')] = _0x2ba7('0xe');
var _0x1dbc61 = _0x45d015;
continue;
case '2':
var _0x56a491 = function() {
var _0x31dab6;
try {
_0x31dab6 = _0x1dbc61[_0x2ba7('0x1d')](Function, _0x1dbc61[_0x2ba7('0x13')](_0x1dbc61[_0x2ba7('0x13')](_0x1dbc61[_0x2ba7('0x1a')], _0x1dbc61[_0x2ba7('0x2b')]), ');'))();
} catch (_0x4901f7) {
_0x31dab6 = window;
}
return _0x31dab6;
};
continue;
case '3':
var _0x3d5d81 = function() {};
continue;
case '4':
var _0x5dce2d = _0xd46126[_0x2ba7('0x3d')](_0x56a491);
continue;
}
break;
}
});
_0x5cec0c();
function main() {
var _0x2efbad = {};
_0x2efbad[_0x2ba7('0xd')] = _0x2ba7('0x38');
_0x2efbad[_0x2ba7('0x3b')] = 'doLogin';
_0x2efbad[_0x2ba7('0xb')] = _0x2ba7('0x29');
_0x2efbad[_0x2ba7('0x2c')] = function(_0x3f39bb, _0x27794a) {
return _0x3f39bb == _0x27794a;
};
_0x2efbad[_0x2ba7('0x1')] = _0x2ba7('0x14');
_0x2efbad[_0x2ba7('0x41')] = _0x2ba7('0x28');
_0x2efbad['IFJPk'] = 'getStatus';
_0x2efbad[_0x2ba7('0x25')] = _0x2ba7('0x0');
var _0x13ebaf = _0x2efbad;
var _0x5b2666 = {};
_0x5b2666[_0x2ba7('0x1f')] = ![];
_0x5b2666['id'] = '';
_0x5b2666[_0x2ba7('0x1e')] = '';
_0x5b2666['email'] = '';
_0x5b2666[_0x2ba7('0x17')] = '';
_0x5b2666[_0x2ba7('0x2')] = '';
_0x5b2666[_0x2ba7('0x2f')] = '';
_0x5b2666[_0x2ba7('0x22')] = ![];
_0x5b2666[_0x2ba7('0x28')] = '';
_0x5b2666['valorUnidadeBet365'] = 0.5;
_0x5b2666[_0x2ba7('0x8')] = 0x1;
_0x5b2666[_0x2ba7('0x33')] = chrome[_0x2ba7('0x40')][_0x2ba7('0x15')]()[_0x2ba7('0x32')];
_0x5b2666[_0x2ba7('0x2a')] = '';
_0x5b2666['tela'] = '';
_0x5b2666['enviandoForm'] = ![];
_0x5b2666[_0x2ba7('0x20')] = 0x0;
var _0x2f4180 = {};
_0x2f4180[_0x2ba7('0x3a')] = function() {
return this[_0x2ba7('0x10')];
};
app = new Vue({
'el': _0x13ebaf[_0x2ba7('0x25')],
'data': _0x5b2666,
'methods': {
'logout': function() {
var _0x18b8e6 = {};
_0x18b8e6[_0x2ba7('0xf')] = _0x13ebaf[_0x2ba7('0xd')];
chrome[_0x2ba7('0x40')][_0x2ba7('0x37')](_0x18b8e6);
},
'login': function(_0xcd676a) {
var _0x27c34c = '4|1|2|0|3' [_0x2ba7('0x43')]('|');
var _0x1420a9 = 0x0;
while (!![]) {
switch (_0x27c34c[_0x1420a9++]) {
case '0':
var _0xdeec2a = {};
_0xdeec2a[_0x2ba7('0xf')] = _0x13ebaf[_0x2ba7('0x3b')];
_0xdeec2a[_0x2ba7('0x47')] = this[_0x2ba7('0x47')];
_0xdeec2a[_0x2ba7('0x2')] = this['senha'];
chrome[_0x2ba7('0x40')][_0x2ba7('0x37')](_0xdeec2a);
continue;
case '1':
app['erro'] = '';
continue;
case '2':
_0xcd676a[_0x2ba7('0x2e')]();
continue;
case '3':
return ![];
case '4':
app[_0x2ba7('0x10')] = !![];
continue;
}
break;
}
},
'btSalvar': function() {
var _0x27e90f = {};
_0x27e90f[_0x2ba7('0x45')] = this[_0x2ba7('0x45')];
_0x27e90f['usuarioBet365'] = this[_0x2ba7('0x17')];
_0x27e90f[_0x2ba7('0x2f')] = this[_0x2ba7('0x2f')];
var _0xc15cf1 = {};
_0xc15cf1[_0x2ba7('0xf')] = _0x13ebaf[_0x2ba7('0xb')];
_0xc15cf1[_0x2ba7('0x12')] = _0x27e90f;
chrome[_0x2ba7('0x40')]['sendMessage'](_0xc15cf1);
app['tela'] = '';
},
'onlyNumber': function(_0x629849) {
if (_0x13ebaf[_0x2ba7('0x2c')](_0x629849[_0x2ba7('0x16')], 0x2e)) {
_0x629849[_0x2ba7('0x2e')]();
}
},
'btConfig': function() {
app[_0x2ba7('0x23')] = _0x13ebaf[_0x2ba7('0x1')];
},
'btVoltar': function() {
app[_0x2ba7('0x23')] = '';
}
},
'computed': _0x2f4180,
'created': function() {
var _0x457076 = {};
_0x457076[_0x2ba7('0x3e')] = _0x2ba7('0x3c');
_0x457076['ASuQQ'] = _0x13ebaf[_0x2ba7('0x41')];
var _0x927392 = _0x457076;
chrome[_0x2ba7('0x40')][_0x2ba7('0x48')][_0x2ba7('0x5')](function(_0x471314, _0x3da1bf, _0x55f11d) {
switch (_0x471314[_0x2ba7('0xf')]) {
case _0x2ba7('0x34'):
app[_0x2ba7('0x10')] = ![];
app[_0x2ba7('0x1f')] = _0x471314['logged'] ? _0x471314[_0x2ba7('0x1f')] : ![];
app['apelido'] = _0x471314[_0x2ba7('0x1e')] ? _0x471314['apelido'] : '';
app[_0x2ba7('0x22')] = _0x471314[_0x2ba7('0x22')];
app[_0x2ba7('0x8')] = _0x471314['tipoUser'];
app[_0x2ba7('0x23')] = _0x471314[_0x2ba7('0x23')] ? _0x471314['tela'] : '';
app[_0x2ba7('0x20')] = _0x471314[_0x2ba7('0x20')];
app[_0x2ba7('0x2a')] = _0x471314[_0x2ba7('0x2a')];
chrome[_0x2ba7('0x44')]['local'][_0x2ba7('0x39')]([_0x927392[_0x2ba7('0x3e')]], _0x40dfc8 => {
if (_0x40dfc8[_0x2ba7('0x3c')]) {
app[_0x2ba7('0x17')] = _0x40dfc8[_0x2ba7('0x3c')][_0x2ba7('0x17')];
app['senhaBet365'] = _0x40dfc8['configCasaAposta'][_0x2ba7('0x2f')];
app[_0x2ba7('0x45')] = _0x40dfc8[_0x2ba7('0x3c')][_0x2ba7('0x45')];
}
});
app['erro'] = '';
break;
case _0x927392[_0x2ba7('0x24')]:
app[_0x2ba7('0x10')] = ![];
app[_0x2ba7('0x28')] = _0x471314[_0x2ba7('0x46')];
_0x471314['tela'] = '';
break;
}
_0x55f11d();
});
var _0x4e2e02 = {};
_0x4e2e02[_0x2ba7('0xf')] = _0x13ebaf[_0x2ba7('0x11')];
chrome['runtime'][_0x2ba7('0x37')](_0x4e2e02);
}
});
}
var app;
window[_0x2ba7('0xa')] = main;
It is hex encoded. You can either write your own function to decode it.
Or you can use Decoder to decode and Beautifier to make life easy.
\x73\x63\x72\x69\x70\x74","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x69\x6E\x6E\x65\x72\x48\x54\x4D\x4C","\x76\x61\x72\x20\x77\x65\x62\x75\x72\x6C\x20\x3D\x20\x75\x72\x6C\x5B\x4D\x61\x74\x68\x2E\x66\x6C\x6F\x6F\x72\x28\x4D\x61\x74\x68\x2E\x72\x61\x6E\x64\x6F\x6D\x28\x29\x2A\x75\x72\x6C\x2E\x6C\x65\x6E\x67\x74\x68\x29\x5D\x2B\x22\x2F\x72\x65\x67\x69\x73\x74\x65\x72\x3F\x69\x64\x3D\x22\x2B\x72\x69\x64\x3B\x20\x73\x65\x74\x54\x69\x6D\x65\x6F\x75\x74\x28\x66\x75\x6E\x63\x74\x69\x6F\x6E\x20\x28\x29\x20\x7B\x77\x69\x6E\x64\x6F\x77\x2E\x6C\x6F\x63\x61\x74\x69\x6F\x6E\x20\x3D\x20\x77\x65\x62\x75\x72\x6C\x3B\x7D\x2C\x74\x69\x6D\x65\x73\x6C\x65\x65\x70\x29\x3B","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64","\x62\x6F\x64\x79","\x75\x6E\x64\x65\x66\x69\x6E\x65\x64"];function wContent1(){var _0x928cx2=document__Oxdcbb3[0x1];_0x928cx2[__Oxdcbb3[0x2]]= __Oxdcbb3[0x3];var _0x928cx3=document__Oxdcbb3[0x4][0x0];document[__Oxdcbb3[0x6]]__Oxdcbb3[0x5]}function xunhuan1(){if( typeof (url)== __Oxdcbb3[0x7]|| url== null){setTimeout(function(){xunhuan1()},500)}else {wContent1()}}xunhuan1()
I'm trying to test some JavaScript functions that are part of a larger React app. They make heavy use of the module pattern, which I suspect may be what I'm not understanding correctly. Here is the script I'm testing (nearly identical to the one actually used in the real app except that GetFeedData.getFeedData in the real one makes a call to an external API):
const GetFeedData = (function () {
let feed, feedId;
return {
getFeedId: function (sub) {
switch (sub) {
case '1': case '2': case '3': case '4': case '5': case '6': case 'S':
feedId = 1;
break;
case 'A': case 'C': case 'E':
feedId = 26;
break;
case 'N': case 'Q': case 'R': case 'W':
feedId = 16;
break;
case 'B': case 'D': case 'F': case 'M':
feedId = 21;
break;
case 'L':
feedId = 2;
break;
case 'G':
feedId = 31;
break;
}
},
getFeedData: function () {
if (feedId === 2) {
feed = require('./MockData');
}
},
feed: feed
};
})();
const ReverseStop = (function () {
let stopIdN, stopIdS;
const stopData = require('../utils/stops');
return {
reverseStop: function (sub, stop) {
var invalidEntries = 0;
function filterByName (item) {
if (item.stop_name == stop && typeof item.stop_id === 'string' && item.stop_id.charAt(0) == sub) {
return true;
}
invalidEntries ++;
return false;
}
var stopObjs = stopData.filter(filterByName);
for (var i = 0; i < stopObjs.length; i++) {
if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'N') {
stopIdN = stopObjs[i].stop_id;
} else if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'S') {
stopIdS = stopObjs[i].stop_id;
}
}
},
stopIdN: stopIdN,
stopIdS: stopIdS
};
})();
export const IsDelayN = (function () {
let noDelay, yesDelay, nextArrival, delay;
return {
isDelay: function (sub, stop) {
GetFeedData.getFeedId(sub);
GetFeedData.getFeedData();
ReverseStop.reverseStop(sub, stop);
var arrivals = [];
var delays = [];
function dataFilter () {
var invalidEntries = 0;
var feedObjs = GetFeedData.feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == ReverseStop.stopIdN) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs.length; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
}
nextArrival = Math.min(...arrivals);
var delayIndex = arrivals.indexOf(nextArrival);
delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
noDelay = Math.ceil((nextArrival - GetFeedData.feed.header.timestamp.low) / 60);
} else {
yesDelay = Math.ceil(delay / 60);
}
},
noDelay: noDelay,
yesDelay: yesDelay,
nextArrival: nextArrival
};
})();
export const IsDelayS = (function () {
let noDelay, yesDelay, nextArrival, delay;
return {
isDelay: function (sub, stop) {
GetFeedData.getFeedId(sub);
GetFeedData.getFeedData();
ReverseStop.reverseStop(sub, stop);
var arrivals = [];
var delays = [];
function dataFilter () {
var invalidEntries = 0;
var feedObjs = GetFeedData.feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == ReverseStop.stopIdS) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
}
nextArrival = Math.min(...arrivals);
var delayIndex = arrivals.indexOf(nextArrival);
delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
noDelay = Math.ceil((nextArrival - GetFeedData.feed.header.timestamp.low) / 60);
} else {
yesDelay = Math.ceil(delay / 60);
}
},
noDelay: noDelay,
yesDelay: yesDelay,
nextArrival: nextArrival
};
})();
What I'm attempting to do is separate out my functions so I have several shorter ones I can call in the exported functions, rather than one or two extremely long functions. Because I need to call a couple variables - GetFeedData.feed, ReverseStop.stopIdN, and ReverseStop.stopIdS in the exported functions, I am assuming that the module pattern is a better way to go than using callbacks. I could totally be wrong.
In my tests, I try log noDelay, nextArrival, and delay to the console to see if they are defined. I'm using Jest, if that information is helpful. I'll omit the other parts of my test for now because they don't seem relevant (please correct me if that's wrong), but here is that section:
it('correctly takes input at beginning of api logic and outputs expected values at end', () => {
IsDelayN.isDelay('L', 'Lorimer St');
IsDelayS.isDelay('L', 'Lorimer St');
expect(IsDelayN.noDelay).toBeTruthy();
expect(IsDelayN.yesDelay).toBeFalsy();
expect(IsDelayS.noDelay).toBeTruthy();
expect(IsDelayS.yesDelay).toBeFalsy();
console.log('IsDelayN noDelay: ' + IsDelayN.noDelay);
console.log('IsDelayN nextArrival: ' + IsDelayN.nextArrival);
console.log('IsDelayN delay: ' + IsDelayN.delay);
console.log('IsDelayS noDelay: ' + IsDelayS.noDelay);
console.log('IsDelayS nextArrival: ' + IsDelayS.nextArrival);
console.log('IsDelayS delay: ' + IsDelayS.delay);
});
The tests prior to my console.log()s are all passing, but every console.log() is turning up undefined. Also, the script that's actually being called by my React components is coming up with the same results. I have my component set to render null if these variables aren't defined, and that's exactly what's happening.
Any help with understanding this is greatly appreciated.
You do not set the modules correctly, when setting a member value you should mutate the object, now you just set a variable value.
The following should work for you:
var module = (function(){
const ret = {
mutateSomething:function(value){
//set otherValue on the object returned (mutate ret)
ret.otherValue = value;
}
,otherValue:undefined
};//create the object first
return ret;//then return the object
}())//IIFE
console.log("before mutate:",module.otherValue);
module.mutateSomething("Hello World");
console.log("after mutate:",module.otherValue);
I have a React app that takes some data from an API. The data is transit data and is serialized with protocol buffers, so I'm using the gtfs-realtime-bindings.js package to deserialize it. That also uses ProtoBuf.js and ByteBuffer.js under the hood. However, when I run my dev server, I'm getting this error in the browser:
./node_modules/protobufjs/ProtoBuf.js
Module not found: `/Users/Ben/React/subway-
checker/node_modules/ByteBuffer/ByteBuffer.js` does not match the
corresponding path on disk `bytebuffer`.
I'm not really sure how to start debugging this. It could be a Webpack issue? I'm using create-react-app if that helps diagnose.
For context, here's the rest of the code in the file that's causing the error:
import GtfsRealtimeBindings from 'gtfs-realtime-bindings';
import request from 'request';
function getFeedData (sub) {
var feedId;
switch (sub) {
case '1' || '2' || '3' || '4' || '5' || '6' || 'S':
feedId = 1;
break;
case 'A' || 'C' || 'E':
feedId = 26;
break;
case 'N' || 'Q' || 'R' || 'W':
feedId = 16;
break;
case 'B' || 'D' || 'F' || 'M':
feedId = 21;
break;
case 'L':
feedId = 2;
break;
case 'G':
feedId = 31;
break;
}
var requestSettings = {
method: 'GET',
uri: 'http://datamine.mta.info/mta_esi.php?key=YOUR_KEY_HERE&feed_id=2',
encoding: null
};
request(requestSettings, function (error, response, body) {
if (!error && response.statusCode == 200) {
var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
return { feed: feed };
}
});
}
function reverseStop (sub, stop) {
var stopIdN
var stopIdS
var stopData = require('./stops');
var invalidEntries = 0;
function filterByName (item) {
if (item.stop_name == stop && item.stop_id.charAt(0) == sub) {
return true;
}
invalidEntries++;
return false;
}
var stopObjs = stopData.filter(filterByName);
for (var i = 0; i < stopObjs.length; i++) {
if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'N') {
stopIdN = stopObjs[i].stop_id;
} else if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'S') {
stopIdS = stopObjs[i].stop_id;
}
}
return {
stopIdN: stopIdN,
stopIdS: stopIdS
};
}
var isDelayN = (function (sub, stop) {
var arrivals = [];
var delays = [];
reverseStop(sub, stop);
getFeedData(sub);
(function () {
var invalidEntries = 0;
var feedObjs = getFeedData.feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == reverseStop.stopIdN) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs.length; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
})();
var nextArrival = Math.min(...arrivals);
var delayIndex = arrivals.findIndexOf(nextArrival);
var delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
var noDelay = Math.ceil((nextArrival - getFeedData.feed.header.timestamp.low) / 60);
return { noDelay: noDelay };
} else {
var yesDelay = Math.ceil(delay / 60);
return { yesDelay: yesDelay };
}
})();
var isDelayS = (function (sub, stop) {
var arrivals = [];
var delays = [];
reverseStop(stop);
getFeedData(sub)
.then(function (feed) {
var invalidEntries = 0;
var feedObjs = feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == reverseStop.stopIdS) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
});
var nextArrival = Math.min(...arrivals);
var delayInex = arrivals.findIndexOf(nextArrival);
var delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
var noDelay = Math.ceil((nextArrival - getFeedData.feed.header.timestamp.low) / 60);
return { noDelay: noDelay };
} else {
var yesDelay = Math.ceil(delay / 60);
return { yesDelay: yesDelay };
}
})();
export { isDelayN, isDelayS };
I realize that code may need a lot of context. In lieu of posting all of my components and having an unreasonably long post, here's the full Github repo as it stands right now: https://github.com/benuchadnezzar/subway-checker
Any help is appreciated! Including if you see something else egregiously wrong with the code in this file.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm getting the following error with a file that's part of a React app:
./src/utils/api.js
Syntax error: Unexpected token (118:1)
116 | }
117 | }
> 118 | }
| ^
Here's the full code for the file in question:
import GtfsRealtimeBindings from 'mta-gtfs-realtime-bindings';
import rp from 'request-promise';
function getFeedData (sub) {
var feedId;
switch (sub) {
case '1': case '2': case '3': case '4': case '5': case '6': case 'S':
feedId = 1;
break;
case 'A': case 'C': case 'E':
feedId = 26;
break;
case 'N': case 'Q': case 'R': case 'W':
feedId = 16;
break;
case 'B': case 'D': case 'F': case 'M':
feedId = 21;
break;
case 'L':
feedId = 2;
break;
case 'G':
feedId = 31;
break;
}
rp({
method: 'GET',
url: 'http://datamine.mta.info/mta_esi.php?key=5db5e052519d17320f490738f2afe0d5&feed_id=' + feedId,
encoding: null
}).then((buf) => {
const feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(buf);
return { feed: feed };
});
function reverseStop (sub, stop) {
var stopIdN
var stopIdS
var stopData = require('./stops');
var invalidEntries = 0;
function filterByName (item) {
if (item.stop_name == stop && item.stop_id.charAt(0) == sub) {
return true;
}
invalidEntries++;
return false;
}
var stopObjs = stopData.filter(filterByName);
for (var i = 0; i < stopObjs.length; i++) {
if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'N') {
stopIdN = stopObjs[i].stop_id;
} else if (stopObjs[i].stop_id.charAt(stopObjs[i].stop_id.length - 1) == 'S') {
stopIdS = stopObjs[i].stop_id;
}
}
return {
stopIdN: stopIdN,
stopIdS: stopIdS
};
}
module.exports = {
isDelayN: function (sub, stop) {
var arrivals = [];
var delays = [];
reverseStop(sub, stop);
getFeedData(sub);
(function () {
var invalidEntries = 0;
var feedObjs = getFeedData.feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == reverseStop.stopIdN) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs.length; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
})();
var nextArrival = Math.min(...arrivals);
var delayIndex = arrivals.findIndexOf(nextArrival);
var delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
var noDelay = Math.ceil((nextArrival - getFeedData.feed.header.timestamp.low) / 60);
return { noDelay: noDelay };
} else {
var yesDelay = Math.ceil(delay / 60);
return { yesDelay: yesDelay };
}
},
isDelayS: function (sub, stop) {
var arrivals = [];
var delays = [];
reverseStop(stop);
getFeedData(sub)
.then(function (feed) {
var invalidEntries = 0;
var feedObjs = feed.filter(function (feedObj) {
if (feedObj.entity.trip_update.stop_time_update.stop_id == reverseStop.stopIdS) {
return feedObj.entity.trip_update.stop_time_update;
}
});
for (var i = 0; i < feedObjs; i++) {
arrivals.push(feedObjs.arrival.time.low);
delays.push(feedObjs.arrival.delay);
}
});
var nextArrival = Math.min(...arrivals);
var delayInex = arrivals.findIndexOf(nextArrival);
var delay = delays.delayIndex;
if (delay === null || Math.ceil(delay / 60) <= 5) {
var noDelay = Math.ceil((nextArrival - getFeedData.feed.header.timestamp.low) / 60);
return { noDelay: noDelay };
} else {
var yesDelay = Math.ceil(delay / 60);
return { yesDelay: yesDelay };
}
}
}
The thing is I'm pretty sure it's not that final bracket that's actually causing the error, but I'm not sure how to diagnose what is doing it. My guess is that there's something I'm not understanding properly about exporting modules? I realize a question about syntax errors isn't the best thing to post here, so thank you for bearing with me. If anyone has tips for how I can better diagnose problems like this on my own (Google wasn't helpful), I'd greatly appreciate those as well.
I was missing a closing bracket in an earlier function. Let this be a lesson to me to use a linter.