Detailed launch example

A more real-world usage example below.

Adding a script with api_key and certain app_id. Such invocation will download available test scripts.

<link href="https://hybridapptester.com/scripter.css" rel="stylesheet" type="text/css">
<script src="https://hybridapptester.com/scripter/?api_key=keyname&app_id=222&no_preload=1"></script>

Changing application initialiation to check if app start should proceed normaly or HAT should be started.

function app_pre_init()
{
// This function makes a switch, depending on activities needed
if (window.localStorage.getItem("hat_continue")) {
hatvar.script_continue();
// Not cleaning data since we are presuming regular app restart
app_init_real();
} else if (window.localStorage.getItem("hat_display_script_chooser")) {
hatvar.script_chooser_start({
cancel:function() {
// HAT disable was choosen by user
window.localStorage.removeItem("hat_display_script_chooser");
app_init_real();
},
success:function() {
// Some script was choosen to run by user
// To ensure correct clean start, cleaning all data
// (assuming your app stores login, password or sid in localStorage)
window.localStorage.removeItem("app_login");
window.localStorage.removeItem("app_password");
window.localStorage.removeItem("app_sid");
app_init_real();
}
});
} else {
app_init_real();
}
}

function app_init_real()
{
// some original code there
$(".button.enable_hap").bind("click",in_app_button_hap_enable);
}

// function to be called to enable HAT in application
function in_app_button_hap_enable()
{
window.localStorage.setItem("hat_display_script_chooser",1);
document.location.reload();
}