From 247bb38e7dfcd12c5a503bb1ca3aee320a122d8c Mon Sep 17 00:00:00 2001 From: GarboMuffin Date: Thu, 29 Jun 2023 21:57:50 -0500 Subject: [PATCH] review pass 1 --- extensions/NexusKitten/browserutils.js | 49 +++++++------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/extensions/NexusKitten/browserutils.js b/extensions/NexusKitten/browserutils.js index ff047990e5..33ad435052 100644 --- a/extensions/NexusKitten/browserutils.js +++ b/extensions/NexusKitten/browserutils.js @@ -111,13 +111,9 @@ ] }; } - async isonline() { - try { - const response = await Scratch.fetch('https://extensions.turbowarp.org/hello.txt'); - return true; - } catch (error){ - return false; - } + isonline() { + // TODO: we want to do better, but no good reliable way for us to do that right now + return navigator.onLine; } ismobile () { const userAgent = navigator.userAgent; @@ -140,56 +136,37 @@ } } geturl () { - try { - const currentUrl = window.location.href; - return currentUrl; - } catch (error){ - return ''; - } + return location.href; } settitle (args) { - try { - document.title = args.TITLE; - } catch (error){ - } + document.title = args.TITLE; } - setfavicon (args) { - try { - // Not sure why this code shows up with errors in visual studio, however it works. - var link = document.querySelector("link[rel~='icon']"); + async setfavicon (args) { + // This can cause a network request, so we need to get permission + if (await Scratch.canFetch(args.ICO)) { + /** @type {HTMLLinkElement} */ + let link = document.querySelector("link[rel~='icon']"); if (!link) { link = document.createElement('link'); link.rel = 'icon'; document.head.appendChild(link); } link.href = args.ICO; - } catch (error){ } } reload () { - try { - location.reload(); - } catch (error){ - } + location.reload(); } tabactive () { - try { - return !document.hidden; - } catch (error){ - return true; - } + return !document.hidden; } darkmode () { - try { - return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; - } catch (error){ - return false; - } + return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; } // The following blocks were originally from LMS Utilities, repurposed with permission.