Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web & Device Extension by InfinityLoop #1186

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
311 changes: 311 additions & 0 deletions extensions/InfinityLoopGaming/WebandDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
// Name: Web & Device
// ID: webanddevice_InfinityLoopGaming
// Description: Interacts and gets data from websites, your device, and your network.
// By: InfinityLoopGaming <https://scratch.mit.edu/users/InfinityLoopGaming/>
(function (Scratch) {
"use strict";
if (!Scratch.extensions.unsandboxed) {
throw new Error("This extension must be run unsandboxed!");
}
const paletteIcon =
"data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxMzMuNjY2NjciIGhlaWdodD0iMTMzLjY2NjY3IiB2aWV3Qm94PSIwLDAsMTMzLjY2NjY3LDEzMy42NjY2NyI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE3My41LC0xMTQuNSkiPjxnIGRhdGEtcGFwZXItZGF0YT0ieyZxdW90O2lzUGFpbnRpbmdMYXllciZxdW90Ozp0cnVlfSIgZmlsbC1ydWxlPSJub256ZXJvIiBzdHJva2U9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJidXR0IiBzdHJva2UtbGluZWpvaW49Im1pdGVyIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIHN0cm9rZS1kYXNoYXJyYXk9IiI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NTEgLTMuMDg3LDAuNzczIC00LjY2NywxLjI4M2MyLjU2NSw0LjI0MyA2LjYzMiw3LjQ3NyAxMS40NTksOC45NjN6TTI1Ny40ODU1LDE4OS4yNDE1Yy0xLjA1NCwtMC4zNTIgLTIuNjEsLTAuODEzIC00LjU4NCwtMS4yNThjLTEuNDIzLDMuODc3IC0zLjczMSw3LjM4NiAtNi43NTIsMTAuMjM4YzQuNzgyLC0xLjUxOCA4LjgwMywtNC43NTQgMTEuMzM2LC04Ljk4ek0yNDYuMTUwNSwxNTkuMzc1NWMzLjAwOSwyLjg0MiA1LjMxMSw2LjMzNyA2LjczNiwxMC4xOTdjMS41MDIsLTAuMzQ1IDMuMDI5LC0wLjc1OCA0LjU3OCwtMS4yNTVjLTIuNTM1LC00LjIwOCAtNi41NDgsLTcuNDMgLTExLjMxNCwtOC45NDJ6TTIyMi41MzE1LDE2OC4zMjc1YzEuMDU0LDAuMzUyIDIuNjQ0LDAuODMgNC42NzQsMS4yODdjMS40MzIsLTMuOTAxIDMuNzYxLC03LjQzIDYuODEsLTEwLjI5MWMtNC44NDMsMS40OTIgLTguOTIsNC43NDIgLTExLjQ4NCw5LjAwNHoiIGZpbGw9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMSIvPjwvZz48L2c+PC9zdmc+";
class WebAndDevice {
getInfo() {
return {
id: "webanddevice_InfinityLoopGaming",
name: "Web & Device",
color1: "#348ceb",
color2: "#5b95d4",
color3: "#84a3c4",
menuIconURI: paletteIcon,
blocks: [
{
opcode: "setTitle",
blockType: Scratch.BlockType.COMMAND,
text: Scratch.translate("set page title to [title]"),
arguments: {
title: {
type: Scratch.ArgumentType.STRING,
},
},
},
{
opcode: "pageTitle",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("page title"),
},
"---",
{
opcode: "enterFullscreen",
blockType: Scratch.BlockType.COMMAND,
text: Scratch.translate("enter fullscreen"),
},
{
opcode: "exitFullscreen",
blockType: Scratch.BlockType.COMMAND,
text: Scratch.translate("exit fullscreen"),
},
{
opcode: "isFullscreen",
blockType: Scratch.BlockType.BOOLEAN,
text: Scratch.translate("is page fullscreen?"),
},
"---",
{
opcode: "connected_to_internet",
blockType: Scratch.BlockType.BOOLEAN,
text: "connected to internet?",
},
{
opcode: "networktype",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("network type"),
},
{
opcode: "networkgeneration",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("network generation"),
},
"---",
{
opcode: "open_url",
blockType: Scratch.BlockType.COMMAND,
text: Scratch.translate("open url [url] in new tab"),
arguments: {
url: {
type: Scratch.ArgumentType.STRING,
},
},
},
{
opcode: "redirect_url",
blockType: Scratch.BlockType.COMMAND,
text: "redirect to url [url]",
arguments: {
url: {
type: Scratch.ArgumentType.STRING,
},
},
},
{
opcode: "currenturl",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("current link"),
},
{
opcode: "getdatafromurl",
blockType: Scratch.BlockType.REPORTER,
text: "get data from url [url]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"get" in the text of reporters is discouraged

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that the only word in Fetch?

Copy link
Collaborator

@CST1229 CST1229 Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fetch there isn't any other noun the block could use (e.g naming the block ([url]) would be weird), and it's also called that because it makes a GET request.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what should I use instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use fetch

arguments: {
url: {
type: Scratch.ArgumentType.STRING,
},
},
},
"---",
{
opcode: "browser",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("browser"),
},
{
opcode: "operatingsystem",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("operating system"),
},
{
opcode: "devicememory",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("device memory"),
},
"---",
{
opcode: "screenWidth",
text: "screen width",
blockType: Scratch.BlockType.REPORTER,
},
{
opcode: "screenHeight",
text: "screen height",
blockType: Scratch.BlockType.REPORTER,
},
"---",
{
opcode: "set_clipboard",
blockType: Scratch.BlockType.COMMAND,
text: "Set clipboard to [text]",
arguments: {
text: {
type: Scratch.ArgumentType.STRING,
},
},
},

{
opcode: "get_clipboard",
blockType: Scratch.BlockType.REPORTER,
text: "get clipboard",
},
],
};
}

setTitle(args) {
document.title = args.title;
}
pageTitle() {
return document.title;
}
enterFullscreen() {
if (document.fullscreenElement === null) {
document.documentElement.requestFullscreen();
}
}
exitFullscreen() {
if (document.fullscreenElement !== null) {
document.exitFullscreen();
}
}
isFullscreen() {
return document.fullscreenElement !== null;
}
networktype() {
try {
switch (navigator.connection.type) {
case "bluetooth":
return "bluetooth";
case "cellular":
return "cellular";
case "ethernet":
return "ethernet";
case "wifi":
return "wi-fi";
case "wimax":
return "wimax";
default:
return "";
}
} catch (err) {
return "";
}
}
networkgeneration() {
try {
switch (navigator.connection.effectiveType) {
case "slow-2g":
case "2g":
return "2g";
case "3g":
return "3g";
case "4g":
return "4g";
default:
return "";
}
} catch (err) {
return "";
}
}
currenturl() {
try {
return document.URL || "";
} catch (err) {
return "";
}
}
browser() {
try {
let has = (input) => navigator.userAgent.includes(input);
if (has("Firefox")) return "firefox";
if (has("SamsungBrowser")) return "samsung internet";
if ((has("Opera") || has("OPR")) && has("GX")) return "opera gx";
if (has("Opera") || has("OPR")) return "opera";
if (has("Trident")) return "internet explorer";
if (has("Edge")) return "legacy";
if (has("Edg")) return "edge";
if (has("YaBrowser") || has("YaSearchBrowser")) return "yandex";
if (has("Miui")) return "mi browser";
if (has("UBrowser")) return "uc browser";
if (has("Chrome")) return "chromium";
if (has("Safari")) return "safari";
return "";
} catch (err) {
return "";
}
}
operatingsystem() {
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";
}
devicememory() {
// @ts-expect-error
if (navigator.deviceMemory === undefined) {
return "Unsupported";
} else {
// @ts-expect-error
return navigator.deviceMemory;
}
}
open_url({ url }) {
Scratch.openWindow(url);
}
redirect_url({ url }) {
Scratch.redirect(url);
}
connected_to_internet() {
try {
return navigator.onLine;
} catch (err) {
return false;
}
}
screenWidth() {
return window.screen.width;
}
screenHeight() {
return window.screen.height;
}
getdatafromurl(args) {
return Scratch.fetch(args.URL)
.then((r) => r.text())
.catch(() => "");
}
set_clipboard(args) {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(args.text);
}
}

get_clipboard() {
if (navigator.clipboard && navigator.clipboard.readText) {
return Scratch.canReadClipboard().then((allowed) => {
if (allowed) {
return navigator.clipboard.readText();
}
return "";
});
}
return "";
}
}
Scratch.extensions.register(new WebAndDevice());
})(Scratch);

//Credits to Network, Navigator, Fetch, and Window Controls extensions for help with scripts.
3 changes: 2 additions & 1 deletion extensions/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@
"itchio",
"gamejolt",
"obviousAlexC/newgroundsIO",
"Lily/McUtils"
"Lily/McUtils",
"InfinityLoopGaming/WebandDevice"
]