status-react/resources/js/webview.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

(function () {
function bridgeSend(data){
WebViewBridge.send(JSON.stringify(data));
}
var history = window.history;
var pushState = history.pushState;
history.pushState = function(state) {
setTimeout(function () {
bridgeSend({
type: 'history-state-changed',
navState: { url: location.href, title: document.title }
});
}, 100);
return pushState.apply(history, arguments);
};
window.addEventListener('message', function (event) {
if (!event.data || !event.data.type) { return; }
if (event.data.type === 'STATUS_API_REQUEST') {
bridgeSend({
type: 'status-api-request',
permissions: event.data.permissions,
host: window.location.hostname
});
}
else if (event.data.type === 'ETHEREUM_PROVIDER_REQUEST') {
bridgeSend({
type: 'status-api-request',
permissions: ['WEB3'],
host: window.location.hostname
});
}
});
}());