🐛 停止改写共享前端模块
This commit is contained in:
1 parent
bf68e8dded
commit
5427c187d4
2 files changed
+12
-29
No files matched your search
@@ -26,22 +26,12 @@ def patch_file_manage(path: Path) -> bool:
|
||||
|
||||
|
||||
def patch_clipboard(path: Path) -> bool:
|
||||
text = path.read_text(encoding='utf-8')
|
||||
old = text
|
||||
pattern = re.compile(
|
||||
r'const (?P<name>[A-Za-z_$][\w$]*)=async\(a,e=\{\}\)=>\{.*?\},'
|
||||
r'(?=[A-Za-z_$][\w$]*=async\(a,e=\{\}\)=>\{)',
|
||||
re.S,
|
||||
)
|
||||
match = pattern.search(text)
|
||||
if not match:
|
||||
return False
|
||||
name = match.group('name')
|
||||
replacement = f'''const {name}=async(a,e={{}})=>{{const{{successMsg:t="复制成功",errorMsg:n="复制失败,请手动复制",showMsg:s=!0,notify:c}}=e,l=(r,d)=>{{s&&c?.(r,d)}},q=()=>{{try{{window.prompt("复制下面内容",a)}}catch{{}}}};try{{if(navigator.clipboard&&window.isSecureContext)try{{await navigator.clipboard.writeText(a);return l(t,"success"),!0}}catch{{}}const r=document.createElement("textarea");r.value=a,r.setAttribute("readonly","");r.className="fcbx-copy-fallback";r.style.cssText="position:fixed;left:0;top:0;width:1px;height:1px;opacity:0;z-index:-1";document.body.appendChild(r);r.focus();r.select();r.setSelectionRange(0,r.value.length);let d=!1;try{{d=document.execCommand("copy")}}finally{{document.body.removeChild(r)}}if(d)return l(t,"success"),!0;q();l("已打开手动复制窗口","warning");return!1}}catch(r){{return console.error("复制失败:",r),q(),l(n,"error"),!1}}}},'''
|
||||
text = text[:match.start()] + replacement + text[match.end():]
|
||||
if text != old:
|
||||
rewrite(path, text)
|
||||
return True
|
||||
"""Never rewrite Vite's shared clipboard chunk after compilation.
|
||||
|
||||
The source utility already implements Clipboard API, DOM and manual-copy
|
||||
fallbacks. Rewriting a minified ESM module can invalidate every page that
|
||||
imports it, including FileManageView.
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user