Skip to content

Commit

Permalink
✨ feat: sideload from url in editor
Browse files Browse the repository at this point in the history
Signed-off-by: SimonShiki <sinangentoo@gmail.com>
  • Loading branch information
SimonShiki committed Oct 27, 2023
1 parent 44f262d commit 8aa54f3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Chibi 是一个用户脚本,可以在任何基于 Scratch 的编辑器中加
# 🔥 使用方法
1. 安装一个用户脚本管理器扩展, 例如 Tampermonkey 或 Greasymonkey。
2. 打开[发布页](https://github.com/SimonShiki/chibi/releases), 点击一个版本来安装。
3. 在'自定义积木'分类栏中找到'😎 Chibi Management'按钮,点击它即可侧载你的扩展。(你可能需要 5 秒来等待按钮出现)
3. 在'自定义积木'分类栏中找到'Open Frontend'按钮,点击它即可侧载你的扩展。(你可能需要 5 秒来等待按钮出现)

> 嗯...也许因为编辑器差异,按钮并不会正常显示。不过别担心,你还可以通过其他的方式来侧载你的扩展!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Chibi is a userscript which can load 3rd-party extensions in any Scratch-based e
# 🔥 Usage
1. Install UserScript Manager like Tampermonkey or Greasymonkey.
2. Open [release](https://github.com/SimonShiki/chibi/releases), Then click one release to install.
3. Find '😎 Chibi Management' button in 'My Blocks' category. you can sideload your extension by clicking it. You may have to wait 5 seconds to make the button appeared.
3. Find 'Open Frontend' button in 'My Blocks' category. you can sideload your extension by clicking it. You may have to wait 5 seconds to make the button appeared.

> Or... Due to editor differences, the button may not appear. There are other ways you can sideload extensions.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chibi",
"displayName": "Chibi",
"version": "3",
"version": "4",
"description": "Load scratch extension everywhere.",
"repository": "https://github.com/SimonShiki/chibi",
"author": "SimonShiki",
Expand Down
46 changes: 43 additions & 3 deletions src/injector/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,35 @@ export function inject (vm: ChibiCompatibleVM) {
...args: unknown[]
) {
const xmlList = originalProcedureCallback.call(this, workspace, ...args);
// Add separator and label
const sep = document.createElement('sep');
sep.setAttribute('gap', '36');
xmlList.push(sep);
const label = document.createElement('label');
label.setAttribute('text', '😎 Chibi');
xmlList.push(label);

// Add dashboard button
const dashboardButton = document.createElement('button');
dashboardButton.setAttribute('text', '😎 Chibi Management');
dashboardButton.setAttribute('text', 'Open Frontend');
dashboardButton.setAttribute('callbackKey', 'CHIBI_FRONTEND');
workspace.registerButtonCallback('CHIBI_FRONTEND', () => {
window.chibi.openFrontend();
});
xmlList.push(dashboardButton);

// Add load from url button
const sideloadButton = document.createElement('button');
sideloadButton.setAttribute('text', 'Sideload from URL');
sideloadButton.setAttribute('callbackKey', 'CHIBI_SIDELOAD_FROM_URL');
workspace.registerButtonCallback('CHIBI_SIDELOAD_FROM_URL', () => {
const url = prompt('Enter URL');
if (!url) return;
const mode = confirm('Running in sandbox?') ? 'sandboxed' : 'unsandboxed';
window.chibi.loader.load(url, mode);
});
xmlList.push(sideloadButton);

// Add chibi detection
const mutation = document.createElement('mutation');
mutation.setAttribute('chibi', 'installed');
Expand All @@ -226,15 +246,36 @@ export function inject (vm: ChibiCompatibleVM) {
xmlList: unknown[],
...args: unknown[]
) {
originalAddCreateButton_.call(this, workspace, xmlList, ...args);
// Add separator and label
const sep = document.createElement('sep');
sep.setAttribute('gap', '36');
xmlList.push(sep);
const label = document.createElement('label');
label.setAttribute('text', '😎 Chibi');
xmlList.push(label);

// Add dashboard button
const dashboardButton = document.createElement('button');
dashboardButton.setAttribute('text', '😎 Chibi Management');
dashboardButton.setAttribute('text', 'Open Frontend');
dashboardButton.setAttribute('callbackKey', 'CHIBI_FRONTEND');
workspace.registerButtonCallback('CHIBI_FRONTEND', () => {
window.chibi.openFrontend();
});
xmlList.push(dashboardButton);

// Add load from url button
const sideloadButton = document.createElement('button');
sideloadButton.setAttribute('text', 'Sideload from URL');
sideloadButton.setAttribute('callbackKey', 'CHIBI_SIDELOAD_FROM_URL');
workspace.registerButtonCallback('CHIBI_SIDELOAD_FROM_URL', () => {
const url = prompt('Enter URL');
if (!url) return;
const mode = confirm('Running in sandbox?') ? 'sandboxed' : 'unsandboxed';
window.chibi.loader.load(url, mode);
});
xmlList.push(sideloadButton);

// Add chibi detection
const mutation = document.createElement('mutation');
mutation.setAttribute('chibi', 'installed');
Expand All @@ -247,7 +288,6 @@ export function inject (vm: ChibiCompatibleVM) {
block.appendChild(field);
block.appendChild(mutation);
xmlList.push(block);
originalAddCreateButton_.call(this, workspace, xmlList, ...args);
};
const workspace = blockly.getMainWorkspace();
workspace.getToolbox().refreshSelection();
Expand Down

0 comments on commit 8aa54f3

Please sign in to comment.