From 514d1e9d8fe2eb24e6fb55c40cd25aff2ec45ce7 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Fri, 30 Oct 2020 12:04:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoogleTranslate-Beautification.user.js | 69 ++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/GoogleTranslate-Beautification.user.js b/GoogleTranslate-Beautification.user.js index a7371d2..2be5ff7 100644 --- a/GoogleTranslate-Beautification.user.js +++ b/GoogleTranslate-Beautification.user.js @@ -1,23 +1,61 @@ // ==UserScript== // @name Google 翻译美化 -// @version 1.0.0 +// @version 1.0.1 // @author X.I.U // @description 精简多余内容、修复翻译结果溢出屏幕问题 -// @icon https://translate.google.cn/favicon.ico // @match *://translate.google.cn/* // @match *://translate.google.com/* +// @icon https://translate.google.cn/favicon.ico +// @grant GM_registerMenuCommand +// @grant GM_unregisterMenuCommand +// @grant GM_openInTab +// @grant GM_getValue +// @grant GM_setValue +// @grant GM_notification // @license GPL-3.0 License // @run-at document-start // @namespace https://greasyfork.org/scripts/413721 // ==/UserScript== (function() { - var style_Add = document.createElement('style'); - style_Add.innerHTML = ` -/* 清理多余内容 */ -.input-button-container,.ft-icon-row,.frame:before,.app-download-bar,#gb,.gp-footer,.feedback-link,#gt-input-tool { - display: none !important; -} + var menu_streamline = GM_getValue('xiu2_menu_streamline'); + var menu_streamline_ID, menu_feedBack_ID; + if (menu_streamline == null){menu_streamline = true; GM_setValue('xiu2_menu_streamline', menu_streamline)}; + registerMenuCommand(); + addStyle(); + + // 注册脚本菜单 + function registerMenuCommand() { + var menu_streamline_; + if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单 + GM_unregisterMenuCommand(menu_streamline_ID); + GM_unregisterMenuCommand(menu_feedBack_ID); + menu_streamline = GM_getValue('xiu2_menu_streamline'); + } + + if (menu_streamline){menu_streamline_ = "√";}else{menu_streamline_ = "×";} + + menu_streamline_ID = GM_registerMenuCommand(`[ ${menu_streamline_} ] 精简美化`, function(){menu_switch(menu_streamline,'xiu2_menu_streamline','精简美化')}); + menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});}); + } + + // 菜单开关 + function menu_switch(menu_status, Name, Tips) { + if (menu_status){ + GM_setValue(`${Name}`, false); + GM_notification(`已关闭 [${Tips}] 功能\n(刷新网页后生效)`); + }else{ + GM_setValue(`${Name}`, true); + GM_notification(`已开启 [${Tips}] 功能\n(刷新网页后生效)`); + } + registerMenuCommand(); // 重新注册脚本菜单 + }; + + + // 添加样式 + function addStyle() { + var style, + style_1 = ` /* 翻译结果的选择列表宽度 */ .alt-menu { max-width: 35% !important; @@ -26,6 +64,11 @@ .goog-menu.round-trip-content { white-space: normal !important; word-break: break-all !important; +}`, + style_2 = ` +/* 清理多余内容 */ +.input-button-container,.ft-icon-row,.frame:before,.app-download-bar,#gb,.gp-footer,.feedback-link,#gt-input-tool { + display: none !important; } /* 主体顶部留白 */ .homepage-content-wrap { @@ -46,6 +89,14 @@ } .results-container.empty { border-left: 1px solid rgba(0, 0, 0, 0.06) !important; -}`; +}`, + style_Add = document.createElement('style'); + if (menu_streamline) { + style = style_1 + style_2; + }else{ + style = style_1; + } + style_Add.innerHTML = style; document.head.appendChild(style_Add); + } })(); \ No newline at end of file