Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0aa2747

Browse files
authored
Merge pull request#95 from swilcock0/main
Modification to add menu item in new UI
2 parents14824e3 +0351a2e commit0aa2747

File tree

1 file changed

+85
-30
lines changed

1 file changed

+85
-30
lines changed

‎js/save-as-script.js‎

Lines changed: 85 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,37 @@ app.registerExtension({
1010
});
1111
},
1212
asyncsetup(){
13+
functionsavePythonScript(){
14+
varfilename=prompt("Save script as:");
15+
if(filename===undefined||filename===null||filename===""){
16+
return
17+
}
18+
19+
app.graphToPrompt().then(async(p)=>{
20+
constjson=JSON.stringify({name:filename+".json",workflow:JSON.stringify(p.output,null,2)},null,2);// convert the data to a JSON string
21+
varresponse=awaitapi.fetchApi(`/saveasscript`,{method:"POST",body:json});
22+
if(response.status==200){
23+
constblob=newBlob([awaitresponse.text()],{type:"text/python;charset=utf-8"});
24+
consturl=URL.createObjectURL(blob);
25+
if(!filename.endsWith(".py")){
26+
filename+=".py";
27+
}
28+
29+
consta=$el("a",{
30+
href:url,
31+
download:filename,
32+
style:{display:"none"},
33+
parent:document.body,
34+
});
35+
a.click();
36+
setTimeout(function(){
37+
a.remove();
38+
window.URL.revokeObjectURL(url);
39+
},0);
40+
}
41+
});
42+
}
43+
1344
constmenu=document.querySelector(".comfy-menu");
1445
constseparator=document.createElement("hr");
1546

@@ -19,37 +50,61 @@ app.registerExtension({
1950

2051
constsaveButton=document.createElement("button");
2152
saveButton.textContent="Save as Script";
22-
saveButton.onclick=()=>{
23-
varfilename=prompt("Save script as:");
24-
if(filename===undefined||filename===null||filename===""){
25-
return
26-
}
27-
28-
app.graphToPrompt().then(async(p)=>{
29-
constjson=JSON.stringify({name:filename+".json",workflow:JSON.stringify(p.output,null,2)},null,2);// convert the data to a JSON string
30-
varresponse=awaitapi.fetchApi(`/saveasscript`,{method:"POST",body:json});
31-
if(response.status==200){
32-
constblob=newBlob([awaitresponse.text()],{type:"text/python;charset=utf-8"});
33-
consturl=URL.createObjectURL(blob);
34-
if(!filename.endsWith(".py")){
35-
filename+=".py";
36-
}
37-
38-
consta=$el("a",{
39-
href:url,
40-
download:filename,
41-
style:{display:"none"},
42-
parent:document.body,
43-
});
44-
a.click();
45-
setTimeout(function(){
46-
a.remove();
47-
window.URL.revokeObjectURL(url);
48-
},0);
49-
}
50-
});
51-
}
53+
saveButton.onclick=()=>savePythonScript();
5254
menu.append(saveButton);
55+
56+
57+
// Also load to new style menu
58+
constdropdownMenu=document.querySelectorAll(".p-menubar-submenu ")[0];
59+
// Get submenu items
60+
constlistItems=dropdownMenu.querySelectorAll("li");
61+
letnewSetsize=listItems.length;
62+
63+
constseparatorMenu=document.createElement("li");
64+
separatorMenu.setAttribute("id","pv_id_8_0_"+(newSetsize-1).toString());
65+
separatorMenu.setAttribute("class","p-menubar-separator");
66+
separatorMenu.setAttribute("role","separator");
67+
separatorMenu.setAttribute("data-pc-section","separator");
68+
69+
dropdownMenu.append(separatorMenu);
70+
71+
// Adjust list items within to increase setsize
72+
listItems.forEach((item)=>{
73+
// First check if it's a separator
74+
if(item.getAttribute("data-pc-section")!=="separator"){
75+
item.setAttribute("aria-setsize",newSetsize);
76+
}
77+
});
78+
79+
console.log(newSetsize);
80+
81+
// Here's the format of list items
82+
constsaveButtonText=document.createElement("li");
83+
saveButtonText.setAttribute("id","pv_id_8_0_"+newSetsize.toString());
84+
saveButtonText.setAttribute("class","p-menubar-item relative");
85+
saveButtonText.setAttribute("role","menuitem");
86+
saveButtonText.setAttribute("aria-label","Save as Script");
87+
saveButtonText.setAttribute("aria-level","2");
88+
saveButtonText.setAttribute("aria-setsize",newSetsize.toString());
89+
saveButtonText.setAttribute("aria-posinset",newSetsize.toString());
90+
saveButtonText.setAttribute("data-pc-section","item");
91+
saveButtonText.setAttribute("data-p-active","false");
92+
saveButtonText.setAttribute("data-p-focused","false");
93+
94+
saveButtonText.innerHTML=`
95+
<div class="p-menubar-item-content" data-pc-section="itemcontent">
96+
<a class="p-menubar-item-link" tabindex="-1" aria-hidden="true" data-pc-section="itemlink" target="_blank">
97+
<span class="p-menubar-item-icon pi pi-book"></span>
98+
<span class="p-menubar-item-label">Save as Script</span>
99+
</a>
100+
</div>
101+
`
102+
103+
saveButtonText.onclick=()=>savePythonScript();
104+
105+
dropdownMenu.append(saveButtonText);
106+
107+
53108

54109
console.log("SaveAsScript loaded");
55110
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp