pokemon-showdown-client/crossprotocol.html
Ben Davies e3fcaa492c
Properly set the encoding to UTF-8 on all HTML pages (#1467)
This adds the BOM to all HTTP pages as per the HTML5 spec and ensures
all pages use UTF-8 as their meta charset (which is still kept for
compatibility with older browsers).
2020-02-23 00:13:56 -08:00

70 lines
1.5 KiB
HTML

<!DOCTYPE html>
<meta charset="UTF-8" />
<script src="/js/lib/jquery-2.1.4.min.js"></script>
<script>
var yourOrigin = 'http://play.pokemonshowdown.com';
var myOrigin = 'https://play.pokemonshowdown.com';
function postReply(message) {
return window.parent.postMessage(message, yourOrigin);
}
function messageHandler(e) {
if (e.origin !== yourOrigin) return;
var data = e.data;
// data's first char:
// T: store teams
// P: store prefs
// R: GET request
// S: POST request
switch (data.charAt(0)) {
case 'T':
try {
localStorage.setItem('showdown_teams', data.substr(1));
} catch (e) {}
break;
case 'P':
try {
localStorage.setItem('showdown_prefs', data.substr(1));
} catch (e) {}
break;
case 'R':
case 'S':
var rq = JSON.parse(data.substr(1));
$[(data.charAt(0) === 'R' ? 'get' : 'post')](
rq[0],
rq[1],
function(ajaxdata) {
postReply('r' + JSON.stringify([rq[2], ajaxdata]));
},
rq[3]
);
break;
}
}
window.addEventListener('message', messageHandler);
var storageAvailable = false;
try {
var testVal = '' + Date.now();
localStorage.setItem('showdown_allow3p', testVal);
if (localStorage.getItem('showdown_allow3p') === testVal) {
postReply('a1');
postReply('p' + localStorage.getItem('showdown_prefs'));
postReply('t' + localStorage.getItem('showdown_teams'));
storageAvailable = true;
}
} catch (err) {}
if (!storageAvailable) {
postReply('a0');
}
if (location.protocol + '//' + location.hostname !== myOrigin) {
// This happens sometimes, but we'll pretend it doesn't
}
</script>