forked from stashapp/CommunityScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstashNotes.js
More file actions
108 lines (108 loc) · 3.05 KB
/
stashNotes.js
File metadata and controls
108 lines (108 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"use strict";
(function () {
const api = window.PluginApi;
const React = api.React;
const { Button, Modal } = api.libraries.Bootstrap;
const { faNoteSticky } = api.libraries.FontAwesomeSolid;
const NotesComponent = () => {
const storageKey = "Stash Notes";
const [display, setDisplay] = React.useState(false);
const [notes, setNotes] = React.useState("");
const enableModal = () => setDisplay(true);
const disableModal = () => setDisplay(false);
const saveNotes = (notes) => {
localStorage.setItem(storageKey, notes);
disableModal();
};
React.useEffect(() => {
const notesFromStorage = localStorage.getItem(storageKey);
if (notesFromStorage) {
setNotes(notesFromStorage);
}
}, []);
return React.createElement(
React.Fragment,
null,
React.createElement(NavButton, { onClickHandler: enableModal }),
React.createElement(NotesModal, {
displayState: display,
onCloseHandler: disableModal,
onSaveHandler: saveNotes,
notesState: notes,
notesChangeHandler: (n) => setNotes(n),
})
);
};
const NavButton = ({ onClickHandler }) => {
const { Icon } = api.components;
return React.createElement(
React.Fragment,
null,
React.createElement(
Button,
{
className: "nav-utility minimal",
title: "Notes",
onClick: onClickHandler,
},
React.createElement(Icon, { icon: faNoteSticky })
)
);
};
const NotesModal = ({
displayState,
onCloseHandler,
onSaveHandler,
notesState,
notesChangeHandler,
}) => {
return React.createElement(
Modal,
{ show: displayState, onHide: onCloseHandler },
React.createElement(
Modal.Header,
{ closeButton: true },
React.createElement(Modal.Title, null, "Notes")
),
React.createElement(
Modal.Body,
null,
React.createElement("textarea", {
className: "text-input form-control",
rows: 10,
value: notesState,
onChange: (e) => notesChangeHandler(e.target.value),
}),
React.createElement("hr", null),
React.createElement("h5", null, "Important!"),
"Notes are stored as plain text in your browser's local storage. Do not save sensitive information. Notes will be lost after closing a browser in incognito mode."
),
React.createElement(
Modal.Footer,
null,
React.createElement(
Button,
{ variant: "secondary", onClick: onCloseHandler },
"Close"
),
React.createElement(
Button,
{ variant: "primary", onClick: () => onSaveHandler(notesState) },
"Save Changes"
)
)
);
};
api.patch.before("MainNavBar.UtilityItems", function (props) {
return [
{
children: React.createElement(
React.Fragment,
null,
props.children,
React.createElement(NotesComponent, null)
),
},
];
});
})();