Based on the "deobfuscated" output posted by @Supreme, the code appears to be encoding very basic information about the click event when the user clicks on a video's play button. Here it is tidied up, with some comments:
var alreadyClicked = false;
$(document).on("click", "#play", function(e) {
e.preventDefault();
if (!alreadyClicked) {
$(".loading").text("Loading video... Please wait.");
// Generate random numbers between 10-20
var idLength1 = Math.floor(Math.random() * (20 - 10 + 1)) + 10;
var idLength2 = Math.floor(Math.random() * (20 - 10 + 1)) + 10;
// Generate random numbers between 0-9
var randInt1 = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
var randInt2 = Math.floor(Math.random() * (9 - 0 + 1)) + 0;
// Create "ID" with random IDs + the event name and mouse X/Y coordinates
var encodedId = randInt1 + "" + idLength1 + "" + generateId(idLength1) + "" + btoa(String(e.originalEvent) + "*" + e.pageX + "*" + e.pageY) + "" + generateId(idLength2) + "" + idLength2 + "" + randInt2;
// Prevent submitting the form again if #play is clicked
alreadyClicked = true;
$("#playID").val(encodedId);
$("#playForm").submit();
}
})
function generateId(length) {
var id = "";
var idCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++) {
id = id + idCharacters.charAt(Math.floor(Math.random() * idCharacters.length));
}
return id;
}
The encodedId
variable would look something like:
"618iNXtzD0htGiVKXSV9EW29iamVjdCBNb3VzZUV2ZW50XSo4ODYqNzY56i9zvoRJQ16pPj143"
Reversing this is fairly trivial as we can see how it's constructed in the above code.
- Remove the first and last characters as they will always be a single character. The string is now
18iNXtzD0htGiVKXSV9EW29iamVjdCBNb3VzZUV2ZW50XSo4ODYqNzY56i9zvoRJQ16pPj14
.
- Read the first two characters as a number and remove that amount of characters from the beginning. In this case,
18
, becoming W29iamVjdCBNb3VzZUV2ZW50XSo4ODYqNzY56i9zvoRJQ16pPj14
.
- Do the same again for the last two characters,
14
- W29iamVjdCBNb3VzZUV2ZW50XSo4ODYqNzY5
.
- Decode from Base64:
atob("W29iamVjdCBNb3VzZUV2ZW50XSo4ODYqNzY5") == "[object MouseEvent]*886*769"
.
- We can now see the
#play
element was triggered by a MouseEvent at X 886 / Y 769.
Guess: this is probably a basic method of checking for bots.