KaiOS: be more careful detecting the presence of KaiAds

Now that we catch JavaScript errors and report them to the user, I could
tell that the way we were detecting the presence of getKaiAd() didn't
work because it caused an alert every time a build without KaiAds was
started.  Detecting the presence of a global variable is slightly
tricky, but explicitly looking for it on "window" works and isn't very
ugly.
This commit is contained in:
Ben Harris
2023-03-22 22:54:08 +00:00
parent b66a38bbdc
commit 255744676c

View File

@ -11,7 +11,7 @@
(function() {
// To run, we need to be on KaiOS with the KaiAds SDK and the
// Open Web Apps API.
if (getKaiAd === undefined || navigator.mozApps === undefined ||
if (window.getKaiAd === undefined || navigator.mozApps === undefined ||
navigator.userAgent.toLowerCase().indexOf('kaios') == -1) return;
// If those prerequisites are satisfied, install the button.
var advertbutton = document.createElement("button");