mirror of
https://github.com/XIU2/UserScript.git
synced 2026-07-09 10:55:22 +00:00
102 lines
3.5 KiB
JavaScript
102 lines
3.5 KiB
JavaScript
// ==UserScript==
|
||
// @name Google 翻译美化
|
||
// @version 1.0.1
|
||
// @author X.I.U
|
||
// @description 精简多余内容、修复翻译结果溢出屏幕问题
|
||
// @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 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;
|
||
}
|
||
/* 翻译结果选择时显示翻译结果的翻译结果 */
|
||
.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 {
|
||
margin-top: 26px;
|
||
}
|
||
/* 部分元素的边框调整 */
|
||
.gt-lc.gt-lc-mobile .gt-cd,.gt-lc.gt-lc-mobile.show-as-one-card {
|
||
border: .6px solid #eeeeee !important;
|
||
border-radius: 2px !important;
|
||
}
|
||
.main-header {
|
||
border: 1px solid #eee !important;
|
||
box-shadow: none !important;
|
||
}
|
||
.ls-wrap {
|
||
border-top: none !important;
|
||
border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
|
||
}
|
||
.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);
|
||
}
|
||
})(); |