Skip to content
Open
Changes from all commits
Commits
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
217 changes: 217 additions & 0 deletions extensions/unavatools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
// Name: Unavatar tools
// Id: unavatartools
// What it does: it gets unavatar images easily instead of external websites
// includes: 6 blocks, runs unsandboxed because of 2 blocks, doesn't use math, only
// strings, 4 reporters, 2 commands, what it can do, gets url images, opens tabs
Comment on lines +1 to +5
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just a small tip, you may want to replace this header with something like:

// Name: Unavatar Tools
// ID: unavatartools
// Description: Get Unavatar images easily instead of external websites.
// By: OrangeHub10 <https://scratch.mit.edu/users/IF-YOU-HAVE-A-SCRATCH-ACCOUNT-PUT-ITS-USERNAME-HERE/>
// Original: OnlyIfYourExtensionIsAForkOfAnother
// License: MPL-2.0

Your current header is very likely to fail CI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would tend to agree

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That can be an alternative header(+ i have a scratch account)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That can be an alternative header(+ i have a scratch account)

That header is required to comply with the contributing guidelines.


(function (Scratch) {
"use strict";

class Unavatar {
getInfo() {
return {
id: "unavatartools",
name: "Unavatar Tools",

Check failure on line 14 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Extension name should usually be translated
color1: "#4a4a4a",
color2: "#333333",
blocks: [
{
opcode: "getProfilePic",
blockType: Scratch.BlockType.REPORTER,
text: "get pfp unavatar user image with provider [PROVIDER] size [SIZE] user [USERNAME] fallback [FALLBACK]",

Check failure on line 21 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Block text should usually be translated
arguments: {
PROVIDER: {
type: Scratch.ArgumentType.STRING,
menu: "providersMenu",
defaultValue: "github",
},
USERNAME: {
type: Scratch.ArgumentType.STRING,
defaultValue: "kikobeats",
},
SIZE: { type: Scratch.ArgumentType.NUMBER, defaultValue: 400 },
FALLBACK: { type: Scratch.ArgumentType.STRING, defaultValue: "" },
},
},
{
opcode: "getAvatarByEmail",
blockType: Scratch.BlockType.REPORTER,
text: "unavatar of email [EMAIL] size [SIZE]",

Check failure on line 39 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Block text should usually be translated
arguments: {
EMAIL: {
type: Scratch.ArgumentType.STRING,
defaultValue: "hello@microlink.io",
},
SIZE: { type: Scratch.ArgumentType.NUMBER, defaultValue: 400 },
},
},
{
opcode: "getDomainLogo",
blockType: Scratch.BlockType.REPORTER,
text: "logo of website [DOMAIN] via Google size [SIZE]",

Check failure on line 51 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Block text should usually be translated
arguments: {
DOMAIN: {
type: Scratch.ArgumentType.STRING,
defaultValue: "turbowarp.org",
},
SIZE: { type: Scratch.ArgumentType.NUMBER, defaultValue: 400 },
},
},
{
opcode: "GetDomainLogoNoGoogle",
blockType: Scratch.BlockType.REPORTER,
text: "Get domain logo [DOMAINLOGO] size [SIZEDOMAINLOGO]",

Check failure on line 63 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Block text should usually be translated
arguments: {
DOMAINLOGO: {
type: Scratch.ArgumentType.STRING,
defaultValue: "hello@microlink.io",
},
SIZEDOMAINLOGO: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 400,
},
},
},
{
opcode: "openProfile",
blockType: Scratch.BlockType.COMMAND,
text: "Open profile of [PROVIDER] user [USERNAME]",

Check failure on line 78 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Block text should usually be translated
arguments: {
PROVIDER: {
type: Scratch.ArgumentType.STRING,
menu: "allProvidersMenu",
defaultValue: "github",
},
USERNAME: {
type: Scratch.ArgumentType.STRING,
defaultValue: "kikobeats",
},
},
},
{
opcode: "GetProfilePicSize",
blockType: Scratch.BlockType.COMMAND,
text: "Open unavatar image in new tab [PROVIDERSIZE] user [USERSIZE] size [SIZE]",

Check failure on line 94 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Block text should usually be translated
arguments: {
PROVIDERSIZE: {
type: Scratch.ArgumentType.STRING,
menu: "providersMenu",
defaultValue: "github",
},
USERSIZE: {
type: Scratch.ArgumentType.STRING,
defaultValue: "kikobeats",
},
SIZE: { type: Scratch.ArgumentType.NUMBER, defaultValue: 400 },
},
},
],
menus: {
providersMenu: {
acceptReporters: true,
items: [
"github",
"twitter",
"instagram",
"youtube",
"facebook",
"reddit",
"tiktok",
"twitch",
"soundcloud",
"telegram",
"duckduckgo",
"deviantart",
"dribbble",
"bluesky",
"mastodon",
"threads",
],
},
allProvidersMenu: {
acceptReporters: true,
items: [
"github",
"twitter",
"instagram",
"youtube",
"facebook",
"reddit",
"tiktok",
"twitch",
"soundcloud",
"telegram",
"apple-music",
"spotify",
"patreon",
],
},
},
};
}

_buildUrl(path, size, fallback) {
const s = size || 400;
let url = `https://unavatar.io/${path}?size=${s}`;
if (fallback) {
url += `&fallback=${encodeURIComponent(fallback)}`;
}
return url;
}

getProfilePic(args) {
const provider = String(args.PROVIDER).toLowerCase().trim();
const user = encodeURIComponent(args.USERNAME);
return this._buildUrl(`${provider}/${user}`, args.SIZE, args.FALLBACK);
}

getAvatarByEmail(args) {
const email = encodeURIComponent(args.EMAIL);
return this._buildUrl(email, args.SIZE);
}

getDomainLogo(args) {
const domain = encodeURIComponent(args.DOMAIN);
return this._buildUrl(`google/${domain}`, args.SIZE);
}

GetDomainLogoNoGoogle(args) {
const domain = encodeURIComponent(args.DOMAINLOGO);
return this._buildUrl(domain, args.SIZEDOMAINLOGO);
}

openProfile(args) {
const provider = String(args.PROVIDER).toLowerCase().trim();
const userEnc = encodeURIComponent(args.USERNAME);

const profiles = {
github: `https://github.com/${userEnc}`,
twitter: `https://twitter.com/${userEnc}`,
instagram: `https://instagram.com{/$ userEnc}`,
youtube: `https://youtube.com/${userEnc}`,
twitch: `https://twitch.tv/${userEnc}`,
"apple-music": `https://music.apple.com/${userEnc}`,
spotify: `https://open.spotify.com/${userEnc}`,
patreon: `https://www.patreon.com/${userEnc}`,
};

const url =
profiles[provider] || `https://unavatar.io{provider}/${userEnc}`;
if (typeof window !== "undefined")
window.open(url, "_blank", "noopener,noreferrer");

Check failure on line 201 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Use Scratch.openWindow() instead of window.open()
}

GetProfilePicSize(args) {
const url = this.getProfilePic({
PROVIDER: args.PROVIDERSIZE,
USERNAME: args.USERSIZE,
SIZE: args.SIZE,
FALLBACK: "",
});
if (typeof window !== "undefined")
window.open(url, "_blank", "noopener,noreferrer");

Check failure on line 212 in extensions/unavatools.js

View workflow job for this annotation

GitHub Actions / lint

Use Scratch.openWindow() instead of window.open()
}
}

Scratch.extensions.register(new Unavatar());
})(Scratch);
Loading