From d9f6468934d7f415ec1283970ff1316646e1b1d1 Mon Sep 17 00:00:00 2001 From: NexusKitten <127152751+NexusKitten@users.noreply.github.com> Date: Sun, 20 Aug 2023 20:38:22 -0400 Subject: [PATCH 1/5] Create browserutils.js again --- extensions/NexusKitten/browserutils.js | 231 +++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 extensions/NexusKitten/browserutils.js diff --git a/extensions/NexusKitten/browserutils.js b/extensions/NexusKitten/browserutils.js new file mode 100644 index 0000000000..0f62fa61cf --- /dev/null +++ b/extensions/NexusKitten/browserutils.js @@ -0,0 +1,231 @@ +// Name: Browser Utilities +// ID: nkbrowserutils +// Description: Access and modify webpage information. Works best packaged to HTML. +// By: NamelessCat + +(function(Scratch) { + 'use strict'; + + if (!Scratch.extensions.unsandboxed) { + throw new Error('Browser Utilities must run unsandboxed'); + } + + class BrowserUtils { + getInfo() { + return { + id: 'nkbrowserutils', + name: 'Browser Utilities', + color1: '#504d6f', + color2: '#36344b', + blocks: [ + { + opcode: 'isonline', + blockType: Scratch.BlockType.BOOLEAN, + text: 'is online?' + }, + { + opcode: 'ismobile', + blockType: Scratch.BlockType.BOOLEAN, + text: 'is mobile?' + }, + '---', + { + opcode: 'getOS', + blockType: Scratch.BlockType.REPORTER, + text: 'user operating system' + }, + { + opcode: 'getbrowser', + blockType: Scratch.BlockType.REPORTER, + text: 'user browser' + }, + { + opcode: 'geturl', + blockType: Scratch.BlockType.REPORTER, + text: 'current url' + }, + '---', + { + opcode: 'setfavicon', + blockType: Scratch.BlockType.COMMAND, + text: 'set page favicon to [ICO]', + arguments: { + ICO: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'https://turbowarp.org/favicon.ico' + } + } + }, + { + opcode: 'settitle', + blockType: Scratch.BlockType.COMMAND, + text: 'set page title to [TITLE]', + arguments: { + TITLE: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'My Page' + } + } + }, + { + opcode: 'reload', + blockType: Scratch.BlockType.COMMAND, + text: 'reload page', + }, + '---', + { + opcode: 'tabactive', + blockType: Scratch.BlockType.BOOLEAN, + text: 'is tab active?', + }, + { + opcode: 'darkmode', + blockType: Scratch.BlockType.BOOLEAN, + text: 'is dark mode?', + }, + '---', + { + opcode: 'getMemory', + blockType: Scratch.BlockType.REPORTER, + text: 'device memory in GB' + }, + '---', + { + opcode: 'alertBlock', + blockType: Scratch.BlockType.COMMAND, + text: 'alert [STRING]', + arguments: { + STRING: { + type: Scratch.ArgumentType.STRING, + defaultValue: '' + } + } + }, + { + opcode: 'inputPromptBlock', + blockType: Scratch.BlockType.REPORTER, + text: 'prompt [STRING]', + disableMonitor: true, + arguments: { + STRING: { + type: Scratch.ArgumentType.STRING, + defaultValue: '' + } + } + }, + { + opcode: 'confirmationBlock', + blockType: Scratch.BlockType.BOOLEAN, + text: 'confirm [STRING]', + arguments: { + STRING: { + type: Scratch.ArgumentType.STRING, + defaultValue: '' + } + } + } + ] + }; + } + 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; + return userAgent.includes('Android') || userAgent.includes('iPhone') || userAgent.includes('iPod') || userAgent.includes('iPad') || userAgent.includes('BlackBerry') || userAgent.includes('IEMobile') || userAgent.includes('Opera Mini'); + } + getbrowser () { + const userAgent = navigator.userAgent; + if (userAgent.includes('Edg')) { + return 'Microsoft Edge'; + } else if (userAgent.includes('OPR')) { + return 'Opera'; + } else if (userAgent.includes('Firefox')) { + return 'Firefox'; + } else if (userAgent.includes('Windows NT')) { + return 'Internet Explorer'; + } else if (userAgent.includes('Chrome')) { + return 'Chrome'; + } else { + return 'Other'; + } + } + geturl () { + return location.href; + } + + settitle (args) { + document.title = args.TITLE; + } + + 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; + } + } + + reload () { + location.reload(); + } + + tabactive () { + return !document.hidden; + } + + darkmode () { + return !!window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; + } + + // The following blocks were originally from LMS Utilities, repurposed with permission. + alertBlock(args) { + alert(args.STRING); + } + + inputPromptBlock(args) { + return prompt(args.STRING); + } + + confirmationBlock(args) { + return confirm(args.STRING); + } + + // The following blocks were originally from Navigator, repurposed as suggested by GarboMuffin. + getOS () { + const userAgent = navigator.userAgent; + if (userAgent.includes('Windows')) { + return 'Windows'; + } else if (userAgent.includes('Android')) { + return 'Android'; + } else if (userAgent.includes('iPhone') || userAgent.includes('iPod') || userAgent.includes('iPad')) { + return 'iOS'; + } else if (userAgent.includes('Linux')) { + return 'Linux'; + } else if (userAgent.includes('CrOS')) { + return 'ChromeOS'; + } else if (userAgent.includes('Mac OS')) { + return 'macOS'; + } + return 'Other'; + } + + getMemory () { + // @ts-expect-error + if (navigator.deviceMemory == undefined) { + return 'Unsupported'; + } else { + // @ts-expect-error + return navigator.deviceMemory; + } + } + } + Scratch.extensions.register(new BrowserUtils()); +})(Scratch); From db76ad84f20d6f52b9c6a7f215a661e01f2780df Mon Sep 17 00:00:00 2001 From: NexusKitten <127152751+NexusKitten@users.noreply.github.com> Date: Sun, 20 Aug 2023 20:38:56 -0400 Subject: [PATCH 2/5] Update extensions.json --- extensions/extensions.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/extensions.json b/extensions/extensions.json index 7ec0ffa91d..2fdb67bdb7 100644 --- a/extensions/extensions.json +++ b/extensions/extensions.json @@ -23,7 +23,7 @@ "Lily/ClonesPlus", "Lily/LooksPlus", "NexusKitten/moremotion", - "navigator", + "NexusKitten/browserutils", "battery", "TheShovel/CustomStyles", "mdwalters/notifications", @@ -69,4 +69,4 @@ "gamejolt", "obviousAlexC/newgroundsIO", "Lily/McUtils" -] \ No newline at end of file +] From e6729aaa8e447b22bc19da6e8178586327fd707c Mon Sep 17 00:00:00 2001 From: NexusKitten <127152751+NexusKitten@users.noreply.github.com> Date: Sun, 20 Aug 2023 20:40:52 -0400 Subject: [PATCH 3/5] Eslint --- extensions/NexusKitten/browserutils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/NexusKitten/browserutils.js b/extensions/NexusKitten/browserutils.js index 0f62fa61cf..e64d3b0f1e 100644 --- a/extensions/NexusKitten/browserutils.js +++ b/extensions/NexusKitten/browserutils.js @@ -197,7 +197,7 @@ confirmationBlock(args) { return confirm(args.STRING); } - + // The following blocks were originally from Navigator, repurposed as suggested by GarboMuffin. getOS () { const userAgent = navigator.userAgent; From 7c722a684ff9f8421e0b09c0f6534848115d70a0 Mon Sep 17 00:00:00 2001 From: NexusKitten <127152751+NexusKitten@users.noreply.github.com> Date: Fri, 25 Aug 2023 20:17:15 -0400 Subject: [PATCH 4/5] Update browserutils.js --- extensions/NexusKitten/browserutils.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/extensions/NexusKitten/browserutils.js b/extensions/NexusKitten/browserutils.js index e64d3b0f1e..5dda58554a 100644 --- a/extensions/NexusKitten/browserutils.js +++ b/extensions/NexusKitten/browserutils.js @@ -78,10 +78,21 @@ blockType: Scratch.BlockType.BOOLEAN, text: 'is tab active?', }, + '---', { opcode: 'darkmode', blockType: Scratch.BlockType.BOOLEAN, - text: 'is dark mode?', + text: 'user prefers dark mode?', + }, + { + opcode: "getPreferredReducedMotion", + blockType: Scratch.BlockType.BOOLEAN, + text: "user prefers reduced motion?", + }, + { + opcode: "getPreferredContrast", + blockType: Scratch.BlockType.BOOLEAN, + text: "user prefers more contrast?", }, '---', { @@ -226,6 +237,14 @@ return navigator.deviceMemory; } } + + getPreferredReducedMotion() { + return !!window.matchMedia("(prefers-reduced-motion: reduce)").matches; + } + + getPreferredContrast() { + return !!window.matchMedia("(prefers-contrast: more)").matches; + } } Scratch.extensions.register(new BrowserUtils()); })(Scratch); From 62d673cfa5cf8d3fdad760317a2ccfec9d2aa8cc Mon Sep 17 00:00:00 2001 From: NexusKitten <127152751+NexusKitten@users.noreply.github.com> Date: Wed, 30 Aug 2023 00:24:31 -0400 Subject: [PATCH 5/5] Update extensions.json It was rather outdated --- extensions/extensions.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extensions/extensions.json b/extensions/extensions.json index 2fdb67bdb7..973415dd6a 100644 --- a/extensions/extensions.json +++ b/extensions/extensions.json @@ -15,6 +15,8 @@ "Skyhigh173/bigint", "utilities", "sound", + "Lily/Video", + "iframe", "Xeltalliv/clippingblending", "clipboard", "penplus", @@ -22,14 +24,21 @@ "obviousAlexC/SensingPlus", "Lily/ClonesPlus", "Lily/LooksPlus", + "Lily/MoreEvents", "NexusKitten/moremotion", + "CubesterYT/WindowControls", + "veggiecan/browserfullscreen", + "shreder95ua/resolution", "NexusKitten/browserutils", "battery", "TheShovel/CustomStyles", + "TheShovel/ColorPicker", + "NexusKitten/controlcontrols", "mdwalters/notifications", "XeroName/Deltatime", "ar", "encoding", + "Lily/SoundExpanded", "Lily/TempVariables2", "Lily/MoreTimers", "clouddata-ping", @@ -39,11 +48,13 @@ "true-fantom/regexp", "true-fantom/couplers", "Lily/AllMenus", + "Lily/HackedBlocks", "Lily/Cast", "-SIPC-/time", "-SIPC-/consoles", "ZXMushroom63/searchApi", "TheShovel/ShovelUtils", + "DNin/wake-lock", "Skyhigh173/json", "cs2627883/numericalencoding", "DT/cameracontrols", @@ -57,6 +68,7 @@ "NOname-awa/more-comparisons", "JeremyGamer13/tween", "rixxyx", + "Lily/lmsutils", "qxsck/data-analysis", "qxsck/var-and-list", "vercte/dictionaries",