-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc8f7f5
commit 3eedde6
Showing
1 changed file
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/*! | ||
* Copyright 2023 tomyo-code + AdamMady | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
(function(Scratch) { | ||
'use strict'; | ||
|
||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('Clipboard must run unsandboxed'); | ||
} | ||
const vm = Scratch.vm; | ||
const extensionicon = "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSI4MC40NTQ1NCIgaGVpZ2h0PSI4MC40NTQ1NCIgdmlld0JveD0iMCwwLDgwLjQ1NDU0LDgwLjQ1NDU0Ij48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMTk5Ljc3MjcyLC0xMzkuNzcyNzIpIj48ZyBkYXRhLXBhcGVyLWRhdGE9InsmcXVvdDtpc1BhaW50aW5nTGF5ZXImcXVvdDs6dHJ1ZX0iIGZpbGwtcnVsZT0ibm9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mFJWFk1UXZIUXoxbC9KYkt0N0JqM1RuMm5weEJYQXQ0MTZSUlRKMlRyNms0clBPcWxvcTNzR1hVTHlkUUdjamtwbmlad09IWFNrZHZCM3JaWkVjdklNdlJLQlFXRmY4dklNSGNCRHJlRVNodWtyWVR6a3VmNnRrT2N3VTcrQ1hON01sK0ZvV24zMU14Y3NXdTBXRTcrQ0xZTGVkSkx1dmtybWFkNmo0NHdzeE41K2RkUEFsNW1vQXlGZmhaUkZhS2NISi9IcXY3emJsTHF4bEgrL2dTeWcrdDJKbTNaK1o0bWNkVk83eU8vamNSSlgrSEx3U1ZHNHpCNSticU5LZmcxZUN5bTJXRTN6YW56M0d1Q1ozSWVmUlg4NDl5Ung4RDRYa0JKLzJhd2toSEVybGY5MmpISnVNS1lEVnJHeDZEeW1FMFBwVlQ4MmVaQTVlSVo4eHdFdFkyU3BLdm9HbktFNVZKbkdrMG9qZmJlaC9oU2FPUnZFT3ZwM2sxT0JGd1RMWnBXa3d0NW1ld0xwMHJRVGc0S2VIT0UzTzllRFRON2xEQ0JkTzQ4WHpxQW5JenEzcDYwRUxpbmZ3YW5hREREY0N2NUx1MGpQTEVNS3FRZTQ5ODRZRUJMaDhDVGw5UFdoQjhRNStYTEZNQlA4ZjVqR04yQ3N0cTkwQUFBQUFTVVZPUks1Q1lJST0iIGZpbGw9Im5vbmUiIHN0cm9rZS13aWR0aD0iMC41Ii8+PC9nPjwvZz48L3N2Zz4="; | ||
|
||
|
||
var lastPastedText = ''; | ||
|
||
addEventListener("copy", (event) => { | ||
Scratch.vm.runtime.startHats('clipboardExtension_when_something_is_copied') ; | ||
}); | ||
addEventListener("paste", (event) => { | ||
Scratch.vm.runtime.startHats('clipboardExtension_when_something_is_pasted'); | ||
const clipboardData = event.clipboardData || window.clipboardData; | ||
const pastedText = clipboardData.getData('Text'); | ||
lastPastedText = pastedText; | ||
}); | ||
|
||
|
||
class clipboardExtension { | ||
|
||
constructor() { | ||
this.id = 'clipboard'; | ||
} | ||
|
||
getInfo() { | ||
return { | ||
id: 'clipboardExtension', | ||
name: 'Clipboard', | ||
menuIconURI: extensionicon, | ||
color1: '#008080', | ||
color2: '#006666', | ||
blocks: [ | ||
{ | ||
opcode: 'when_something_is_copied', | ||
blockType: Scratch.BlockType.HAT, | ||
text: 'when something is copied', | ||
isEdgeActivated: false | ||
}, //when something is copied | ||
{ | ||
opcode: 'when_something_is_pasted', | ||
blockType: Scratch.BlockType.HAT, | ||
text: 'when something is pasted', | ||
isEdgeActivated: false | ||
}, //when something is copied | ||
'---', | ||
{ | ||
opcode: 'set_clipboard', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'copy to clipboard: [TEXT]', | ||
arguments: { | ||
TEXT: { | ||
acceptReporters: true, | ||
type: Scratch.ArgumentType.STRING, | ||
} | ||
} | ||
}, // copy text to clipboard | ||
{ | ||
opcode: 'resetclipboard', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'reset clipboard' | ||
}, //reset clipboard | ||
'---', | ||
{ | ||
opcode: 'clipboard', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'clipboard' | ||
}, //clipboard | ||
{ | ||
opcode: 'getLastPastedText', | ||
blockType: 'reporter', | ||
text: 'last pasted text', | ||
blockAllThreads: false | ||
} | ||
], | ||
}; | ||
} | ||
|
||
set_clipboard(args) { | ||
navigator.clipboard.writeText(args.TEXT); | ||
} | ||
|
||
resetclipboard() { | ||
navigator.clipboard.writeText('') | ||
} | ||
|
||
clipboard() { | ||
return navigator.clipboard.readText(); | ||
} | ||
|
||
getLastPastedText() { | ||
const pastedText = lastPastedText; | ||
return pastedText; | ||
} | ||
} | ||
|
||
Scratch.extensions.register(new clipboardExtension); | ||
})(Scratch); |