Spaces:
Runtime error
Runtime error
Create userscript.js
Browse files
src/addons/addons/paint-default-smoothing/userscript.js
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export default async function ({ addon }) {
|
2 |
+
// Wait until the paint editor is loaded
|
3 |
+
await addon.tab.traps.getPaper();
|
4 |
+
|
5 |
+
const defaultBrush = 10;
|
6 |
+
const defaultEraser = 10;
|
7 |
+
const defaultPen = 2;
|
8 |
+
const setDefaults = (enabled) => {
|
9 |
+
const userBrush = addon.settings.get("brush");
|
10 |
+
const userEraser = addon.settings.get("eraser");
|
11 |
+
const userPen = addon.settings.get("pen");
|
12 |
+
|
13 |
+
const currentState = ReduxStore.getState();
|
14 |
+
const currentStatePaint = currentState.scratchPaint;
|
15 |
+
if (enabled) {
|
16 |
+
if (currentStatePaint.brushMode.simplifySize === defaultBrush) {
|
17 |
+
ReduxStore.dispatch({
|
18 |
+
type: 'scratch-paint/brush-mode/CHANGE_SIMPLIFY_SIZE',
|
19 |
+
simplifySize: userBrush
|
20 |
+
});
|
21 |
+
}
|
22 |
+
if (currentStatePaint.eraserMode.simplifySize === defaultEraser) {
|
23 |
+
ReduxStore.dispatch({
|
24 |
+
type: 'scratch-paint/eraser-mode/CHANGE_ERASER_SIMPLIFY_SIZE',
|
25 |
+
simplifySize: userEraser
|
26 |
+
});
|
27 |
+
}
|
28 |
+
if (currentStatePaint.penMode.simplifySize === defaultPen) {
|
29 |
+
ReduxStore.dispatch({
|
30 |
+
type: 'scratch-paint/pen-mode/CHANGE_PEN_SIMPLIFY_SIZE',
|
31 |
+
simplifySize: userPen
|
32 |
+
});
|
33 |
+
}
|
34 |
+
} else {
|
35 |
+
if (currentStatePaint.brushMode.simplifySize === userBrush) {
|
36 |
+
ReduxStore.dispatch({
|
37 |
+
type: 'scratch-paint/brush-mode/CHANGE_SIMPLIFY_SIZE',
|
38 |
+
simplifySize: defaultBrush
|
39 |
+
});
|
40 |
+
}
|
41 |
+
if (currentStatePaint.eraserMode.simplifySize === userEraser) {
|
42 |
+
ReduxStore.dispatch({
|
43 |
+
type: 'scratch-paint/eraser-mode/CHANGE_ERASER_SIMPLIFY_SIZE',
|
44 |
+
simplifySize: defaultEraser
|
45 |
+
});
|
46 |
+
}
|
47 |
+
if (currentStatePaint.penMode.simplifySize === userPen) {
|
48 |
+
ReduxStore.dispatch({
|
49 |
+
type: 'scratch-paint/pen-mode/CHANGE_PEN_SIMPLIFY_SIZE',
|
50 |
+
simplifySize: defaultPen
|
51 |
+
});
|
52 |
+
}
|
53 |
+
}
|
54 |
+
};
|
55 |
+
|
56 |
+
setDefaults(true);
|
57 |
+
addon.self.addEventListener("disabled", () => {
|
58 |
+
setDefaults(false);
|
59 |
+
});
|
60 |
+
addon.self.addEventListener("reenabled", () => {
|
61 |
+
setDefaults(true);
|
62 |
+
});
|
63 |
+
}
|