obfuscating urls from the javascript side will not stop any dedicated individual
displayContent
is an unfortunate name for the function, it does not give away that all it does it setting a listener, considersetFindCarListener
var obfuscated = []
is considered better thanvar obfuscated = new Array();
It is considered better form to have a single
var
statementreverseReg
is an unfortunate name, it is unclear to me what it is supposed to containDon't assign
onsubmit
, useaddEventListener
insteadA loop that will only run twice should get unrolled (
for (i = 0; i <= 1; i++) {
), I would put the code in the loop block inside a helper functionYou have some indentation trouble, consider using jsbeautifier
obf_index++
increasesobf_index
after evaluating it, so you can dofor (i = 0; i <= 6; i++) { obfuscated[obf_index++] = refArray[i]; obfuscated[obf_index++] = reverseReg[i]; }
Since you start from
0
, you are really simulatingpush
, so you could also dofor (i = 0; i <= 6; i++) { obfuscated.push( refArray[i] ); obfuscated.push( reverseReg[i] ); }
lowerCamelCase is preferred in JavaScript so
obf_index
->obfIndex
->obfuscatedIndex
You use both single quotes and double quotes for strings, stick to single quotes
Use JsHint.com, you are not declaring every variable with
var
refArray
is like reverse polish notation, postfixing the type of the variable,regChars
would be a better name, it tells me that this contains the characters of the reg(istration)
All in all ( this is untested ), I would go with something like this:
function addCameraEntries( array , cameraSize ) {
array.push( cameraSize + "/f" );
array.push( cameraSize + "/i" );
array.push( cameraSize + "/6" );
array.push( cameraSize + "/5" );
array.push( cameraSize + "/4" );
array.push( cameraSize + "/r" );
}
function setFindCarListener() {
document.getElementById("findCar").addEvenListener( "submit", function onSubmit() {
var registration = document.getElementById("regPlate").value,
reference = document.getElementById("stockRef").value,
referenceChars = reference.split(''),
ninthReference = referenceChars[10];
registrationChars = registration.split('').reverse(),
obfuscated = [],
camera = [];
for (i = 0; i <= 6; i++) {
obfuscated.push( referenceChars[i] );
obfuscated.push( registrationChars[i] );
}
obfuscated.push(ninthReference);
obfuscatedString = obfuscated.join("");
addCameraEntries( camera , '350' );
addCameraEntries( camera , '800' );
for (i = 0; i <= 11; i++) {
var img = new Image();
img.src = 'http://imagecache.arnoldclark.com/imageserver/" + obfuscatedString + "/" + camera[i] + "'
document.body.appendChild(img);
}
return false;
};
}