fix to_clipboard from non-localhost access (#1576)

tested on edge(windows&android)
This commit is contained in:
御坂IO 2023-12-28 23:54:59 +08:00 committed by GitHub
parent 48b1324a26
commit ad158450e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 8 deletions

View File

@ -43,14 +43,29 @@ def log(img, dic):
"</style>"
)
js = (
"<script>"
"function to_clipboard(txt) { "
"txt = decodeURIComponent(txt);"
"navigator.clipboard.writeText(txt);"
"alert('Copied to Clipboard!\\nPaste to prompt area to load parameters.\\nCurrent clipboard content is:\\n\\n' + txt);"
"}"
"</script>"
js = (
"""<script>
function to_clipboard(txt) {
txt = decodeURIComponent(txt);
if (navigator.clipboard && navigator.permissions) {
navigator.clipboard.writeText(txt)
} else {
const textArea = document.createElement('textArea')
textArea.value = txt
textArea.style.width = 0
textArea.style.position = 'fixed'
textArea.style.left = '-999px'
textArea.style.top = '10px'
textArea.setAttribute('readonly', 'readonly')
document.body.appendChild(textArea)
textArea.select()
document.execCommand('copy')
document.body.removeChild(textArea)
}
alert('Copied to Clipboard!\\nPaste to prompt area to load parameters.\\nCurrent clipboard content is:\\n\\n' + txt);
}
</script>"""
)
begin_part = f"<html><head><title>Fooocus Log {date_string}</title>{css_styles}</head><body>{js}<p>Fooocus Log {date_string} (private)</p>\n<p>All images are clean, without any hidden data/meta, and safe to share with others.</p><!--fooocus-log-split-->\n\n"