Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
2196f026
Commit
2196f026
authored
Oct 12, 2022
by
DepFA
Committed by
GitHub
Oct 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add dynamic entries to context menus
parent
698d303b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
11 deletions
+60
-11
javascript/contextMenus.js
javascript/contextMenus.js
+60
-11
No files found.
javascript/contextMenus.js
View file @
2196f026
...
...
@@ -26,21 +26,38 @@ contextMenuInit = function(){
contextMenu
.
style
.
fontFamily
=
baseStyle
.
fontFamily
contextMenu
.
style
.
top
=
posy
+
'
px
'
contextMenu
.
style
.
left
=
posx
+
'
px
'
contextMenu
.
style
.
width
=
Math
.
min
(
window
.
innerWidth
,
400
)
+
'
px
'
const
contextMenuList
=
document
.
createElement
(
'
ul
'
)
contextMenuList
.
className
=
'
context-menu-items
'
;
contextMenu
.
append
(
contextMenuList
);
menuEntries
.
forEach
(
function
(
entry
){
let
contextMenuEntry
=
document
.
createElement
(
'
a
'
)
contextMenuEntry
.
innerHTML
=
entry
[
'
name
'
]
contextMenuEntry
.
addEventListener
(
"
click
"
,
function
(
e
)
{
entry
[
'
func
'
]();
})
contextMenuList
.
append
(
contextMenuEntry
);
if
(
entry
[
'
isDynamicSubmenu
'
]){
let
contextMenuEntry
=
document
.
createElement
(
'
span
'
)
contextMenuEntry
.
innerHTML
=
entry
[
'
name
'
]
contextMenuEntry
.
style
.
paddingLeft
=
'
5px
'
contextMenuEntry
.
style
.
color
=
'
grey
'
contextMenuList
.
append
(
contextMenuEntry
);
entry
[
'
func
'
]().
forEach
(
function
(
innerEntry
){
let
contextMenuEntry
=
document
.
createElement
(
'
a
'
)
contextMenuEntry
.
innerHTML
=
innerEntry
[
'
name
'
]
contextMenuEntry
.
addEventListener
(
"
click
"
,
function
(
e
)
{
innerEntry
[
'
func
'
]();
})
contextMenuList
.
append
(
contextMenuEntry
);
});
}
else
{
let
contextMenuEntry
=
document
.
createElement
(
'
a
'
)
contextMenuEntry
.
innerHTML
=
entry
[
'
name
'
]
contextMenuEntry
.
addEventListener
(
"
click
"
,
function
(
e
)
{
entry
[
'
func
'
]();
})
contextMenuList
.
append
(
contextMenuEntry
);
}
})
gradioApp
().
getRootNode
().
appendChild
(
contextMenu
)
...
...
@@ -61,7 +78,7 @@ contextMenuInit = function(){
}
function
appendContextMenuOption
(
targetEmementSelector
,
entryName
,
entryFunction
){
function
appendContextMenuOption
(
targetEmementSelector
,
entryName
,
entryFunction
,
isDynamicSubmenu
=
false
,
displayToggleFunc
=
null
){
currentItems
=
menuSpecs
.
get
(
targetEmementSelector
)
...
...
@@ -72,6 +89,8 @@ contextMenuInit = function(){
let
newItem
=
{
'
id
'
:
targetEmementSelector
+
'
_
'
+
uid
(),
'
name
'
:
entryName
,
'
func
'
:
entryFunction
,
'
isDynamicSubmenu
'
:
isDynamicSubmenu
,
'
displayToggleFunc
'
:
displayToggleFunc
,
'
isNew
'
:
true
}
currentItems
.
push
(
newItem
)
...
...
@@ -94,7 +113,8 @@ contextMenuInit = function(){
}
gradioApp
().
addEventListener
(
"
click
"
,
function
(
e
)
{
let
source
=
e
.
composedPath
()[
0
]
if
(
source
.
id
&&
source
.
indexOf
(
'
check_progress
'
)
>-
1
){
console
.
log
(
source
);
if
(
source
.
id
&&
source
.
id
.
indexOf
(
'
check_progress
'
)
>-
1
){
return
}
...
...
@@ -167,11 +187,40 @@ addContextMenuEventListener = initResponse[2];
setTimeout
(
function
(){
rollbutton
.
click
()},
100
)
setTimeout
(
function
(){
rollbutton
.
click
()},
200
)
setTimeout
(
function
(){
rollbutton
.
click
()},
300
)
}
})
function
truncate
(
input
,
len
)
{
if
(
input
.
length
>
len
)
{
return
input
.
substring
(
0
,
len
)
+
'
...
'
;
}
return
input
;
};
appendContextMenuOption
(
'
#txt2img_prompt textarea
'
,
'
Prior prompts
'
,
function
(){
let
l
=
[];
let
n
=
0
;
(
Storage
[
'
promptHistory
'
]
||
[]).
forEach
(
function
(
prompt
){
if
(
n
>
10
){
return
;
}
l
.
push
({
'
name
'
:
truncate
(
prompt
,
20
),
'
func
'
:
function
(){
get_uiCurrentTabContent
().
querySelector
(
'
#txt2img_prompt textarea
'
).
value
=
prompt
}},)
})
return
l
;
},
true
)
})();
//End example Context Menu Items
onUiUpdate
(
function
(){
addContextMenuEventListener
()
if
(
window
.
window
.
getLastGenerationArgs
){
let
priorPrompts
=
Storage
[
'
promptHistory
'
]
||
[];
let
lastPrompt
=
window
.
getLastGenerationArgs
()[
0
];
if
(
priorPrompts
[
priorPrompts
.
length
-
1
]
!=
lastPrompt
){
priorPrompts
.
push
(
lastPrompt
)
}
Storage
[
'
promptHistory
'
]
=
priorPrompts
}
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment