diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_text.py b/LunaTranslator/LunaTranslator/gui/setting_display_text.py index e37df856..c4748785 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_text.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_text.py @@ -13,9 +13,11 @@ from gui.usefulwidget import ( getQMessageBox, D_getspinbox, D_getIconButton, + getboxlayout, D_getcolorbutton, getcolorbutton, MySwitch, + getsimpleswitch, D_getsimpleswitch, selectcolor, listediter, @@ -246,8 +248,17 @@ def resetgroudswitchcallback(self, group): self.seletengeinecombo.lastindex = self.seletengeinecombo.currentIndex() if group == "webview" or group == "QWebEngine": _btn = LPushButton("额外的html") - self.goodfontsettingsformlayout.addRow(_btn) _btn.clicked.connect(lambda: extrahtml(self)) + switch = getsimpleswitch( + globalconfig, + "useextrahtml", + callback=lambda x: [ + gobject.baseobject.translation_ui.translate_text.textbrowser.loadextra(0), + _btn.setEnabled(x), + ], + ) + _btn.setEnabled(globalconfig["useextrahtml"]) + self.goodfontsettingsformlayout.addRow(getboxlayout([_btn, switch])) if group == "QWebEngine": group = "webview" __form = LFormLayout() diff --git a/LunaTranslator/LunaTranslator/rendertext/webview.py b/LunaTranslator/LunaTranslator/rendertext/webview.py index 183516fa..508dd02c 100644 --- a/LunaTranslator/LunaTranslator/rendertext/webview.py +++ b/LunaTranslator/LunaTranslator/rendertext/webview.py @@ -109,10 +109,10 @@ class TextBrowser(QWidget, dataget): if not isinstance(self.webivewwidget, WebivewWidget): return self.isfirst = False - self.__loadextra(0) - self.webivewwidget.on_load.connect(self.__loadextra) + self.loadextra(0) + self.webivewwidget.on_load.connect(self.loadextra) - def __loadextra(self, _): + def loadextra(self, _): for _ in [ "userconfig/extrahtml.html", r"LunaTranslator\rendertext\exampleextrahtml.html", @@ -136,6 +136,9 @@ class TextBrowser(QWidget, dataget): self.debugeval(f"clear_all()") def set_extra_html(self, html): + if not globalconfig["useextrahtml"]: + self.debugeval(f'set_extra_html("")') + return html = quote(html) self.debugeval(f'set_extra_html("{html}")') diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 2f402f0c..e6834382 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -17,6 +17,7 @@ "read_translator": 0, "disappear_delay": 5, "network": 1, + "useextrahtml": true, "network_websocket": 1, "webview_textbrowser": false, "imagewrapmode": 0,