Daily Lucky Numbers:
8
11
19
29
40
42

HTML5 new save code file (v2)

Started by Chen Zhen, October 25, 2020, 02:48:37 PM

Previous topic - Next topic

Chen Zhen

This one works for Invision Arcade & SMF Arcade

Updated: Oct. 29 / 2020

possible file: arcade.html52.js
/*
 * Save code for IBP Arcade & SMF Arcade
 */
function getArcadeUrlParamHtml52(name)
{
var qs = (function(a) {
if (a == "")
return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split("=", 2);
if (p.length == 1)
b[p[0]] = "";
else
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(parent.window.location.search.substr(1).split(";"));
return qs[name] !== "undefined" ? qs[name] : "";
}
function Html52_scorepostExec(gamescore, gameid, gamename, gametoken) {
saveHtml5GameHtml52(gamescore, gamename);
}
function Html52_scorepost(href, named, scored, scoreid, scoretoken, scoretimex, gamepop, gamefull, gameexit, savetype) {
var currentArcadeTime = Math.floor(new Date().getTime() / 1000);
var gform = document.createElement('form');
gform.method = 'post';
gform.action = href;
gform.id = "anygameid";
gform.target = '_parent';
var input = document.createElement('input');
input.setAttribute('name', 'game_name');
input.setAttribute('value', named);
gform.appendChild(input);
var input2 = document.createElement('input');
input2.setAttribute('name', 'score');
input2.setAttribute('value', scored);
gform.appendChild(input2);
var input3 = document.createElement('input');
input3.setAttribute('name', 'game');
input3.setAttribute('value', scoreid);
gform.appendChild(input3);
var input4 = document.createElement('input');
input4.setAttribute('name', 'gtime');
input4.setAttribute('value', currentArcadeTime);
gform.appendChild(input4);
var input5 = document.createElement('input');
input5.setAttribute('name', 'gamesessid');
input5.setAttribute('value', scoretoken);
gform.appendChild(input5);
var input6 = document.createElement('input');
input6.setAttribute('name', 'popup');
input6.setAttribute('value', gamepop);
gform.appendChild(input6);
var input7 = document.createElement('input');
input7.setAttribute('name', 'smfgametime');
input7.setAttribute('value', scoretimex);
gform.appendChild(input7);
var input8 = document.createElement('input');
input8.setAttribute('name', 'gameSmfFullscreen');
input8.setAttribute('value', gamefull);
gform.appendChild(input8);
var input9 = document.createElement('input');
input9.setAttribute('name', 'gameexit');
input9.setAttribute('value', gameexit);
gform.appendChild(input9);
var input10 = document.createElement('input');
input10.setAttribute('name', 'html52');
input10.setAttribute('value', savetype);
gform.appendChild(input10);
document.body.appendChild(gform);
gform.submit();
document.body.removeChild(gform);
return true;
}
function Html52_scorepostSimple(href, named, scored) {
var currentArcadeTime = Math.floor(new Date().getTime() / 1000);
var gform = document.createElement('form');
gform.id = "anygameid";
gform.method = 'post';
gform.action = href;
gform.target = '_parent';
var input = document.createElement('input');
input.setAttribute('name', 'gname');
input.setAttribute('value', named);
gform.appendChild(input);
var input2 = document.createElement('input');
input2.setAttribute('name', 'gscore');
input2.setAttribute('value', scored);
gform.appendChild(input2);
document.body.appendChild(gform);
gform.submit();
document.body.removeChild(gform);
return true;
}
function saveHtml5GameHtml52(newhighscore, gamename)
{
var gamename = typeof gamename != "undefined" ? gamename : "";
if (parent.document.getElementById("gameSmfToken") && parent.document.getElementById("gameSmfToken").value)
var gameSessid = parent.document.getElementById("gameSmfToken").value;
else
gameSessid = "";

if (gameSessid != "")
{
var siteUrl = parent.document.getElementById("html5smfGameUrl").value;
var gameFull = parent.document.getElementById("gameSmfFullscreen").value;
var gameExit = parent.document.getElementById("gameexit").value;
var gameTimex = parent.document.getElementById("smfgametime").value;
var gameId = parent.document.getElementById("game").value;
var gname = parent.document.getElementById("game_name").value;
var gamePop = parent.document.getElementById("popup").value;
var gameSessid = parent.document.getElementById("gameSmfToken").value;
var gscore = parseInt(newhighscore);
var saveType = "html5";
var n = siteUrl.lastIndexOf("/");
//send data using Ajax
// sessionStorage.clear();
if (gameSessid && !sessionStorage.getItem("scoreLoop_" + gameSessid))
{
var newUrl = siteUrl.slice(0, n) + "/index.php?action=arcade;sa=html52Game";
sessionStorage.setItem("scoreLoop_" + gameSessid, new Date().getTime() / 1000);
Html52_scorepost(newUrl, gname, gscore, gameId, gameSessid, gameTimex, gamePop, gameFull, gameExit, saveType);
throw new Error("saving score...");
}
else
{
//sessionStorage.setItem("scoreLoop_" + gameSessid, new Date().getTime() / 1000);
if (new Date().getTime() / 1000 - (sessionStorage.getItem("scoreLoop_" + gameSessid)) < 1)
throw new Error("saving score...");
else
throw new Error("");
//window.location.assign(siteUrl.slice(0, n) + "/index.php?action=arcade;sa=highscore;game=" + gameId);
}
}
else
{
var gameFrameSrc, ibpFull = false;
if (typeof getArcadeUrlParamHtml52 === "function") {
arcadeHtml52Pop = getArcadeUrlParamHtml52("pop");
}
else
arcadeHtml52Pop = 0;

if (arcadeHtml52Pop == 1)
gameFrameSrc = window.location.href;
else if (window.parent.location.href.includes("/playfull/"))
{
gameFrameSrc = window.parent.location.href;
ibpFull = true;
}
else
gameFrameSrc = typeof window.frameElement.src != "undefined" ? window.frameElement.src : "";

var gameSessid = parent.document.getElementById("gameSmfToken") && parent.document.getElementById("gameSmfToken").value ? parent.document.getElementById("gameSmfToken").value : "";
var gnameQuery = gameFrameSrc.substr(gameFrameSrc.lastIndexOf('/') + 1);
var gscore = parseInt(newhighscore);
var gname = gamename;
var gameId = parent.document.getElementById("game") && parent.document.getElementById("game").value ? parent.document.getElementById("game").value : 0;
if (ibpFull == true) {
var siteUrl = window.parent.location.href.replace("playfull", "playgame");
var n = siteUrl.lastIndexOf("/");
}
else {
var siteUrl = window.parent.location.href;
var n = siteUrl.lastIndexOf("/");
}


var newUrl = siteUrl.slice(0, n) + "/index.php?act=Arcade&do=newscore";

//send data using Ajax
if (gameSessid && !sessionStorage.getItem("scoreLoop_" + gameSessid))
{
sessionStorage.setItem("scoreLoop_" + gameSessid, new Date().getTime() / 1000);
Html52_scorepostSimple(newUrl, gname, gscore);
throw new Error("saving score...");
}
else if(siteUrl.includes("playgame"))
{
var o = siteUrl.lastIndexOf("/index.php");
var newInvisionUrl = siteUrl.slice(0, o) + "/index.php?act=Arcade&do=newscore";
Html52_scorepostSimple(newInvisionUrl, gname, gscore);
throw new Error("saving score...");
}
else
{
sessionStorage.setItem("scoreLoop_" + gameSessid, new Date().getTime() / 1000);
}
}
return false;
}

Chen Zhen


This code has been updated.

Tested:

SMF Arcade -> game container, popup & fullscreen

IBP Arcade -> game container, fullscreen


Vincent Titus

Nice , I'm gonna play around with some games and this code maybe learn something lol