Skip to content

Commit 514d1e9

Browse files
committed
新增 脚本菜单
1 parent 88da32d commit 514d1e9

1 file changed

Lines changed: 60 additions & 9 deletions

File tree

GoogleTranslate-Beautification.user.js

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,61 @@
11
// ==UserScript==
22
// @name Google 翻译美化
3-
// @version 1.0.0
3+
// @version 1.0.1
44
// @author X.I.U
55
// @description 精简多余内容、修复翻译结果溢出屏幕问题
6-
// @icon https://translate.google.cn/favicon.ico
76
// @match *://translate.google.cn/*
87
// @match *://translate.google.com/*
8+
// @icon https://translate.google.cn/favicon.ico
9+
// @grant GM_registerMenuCommand
10+
// @grant GM_unregisterMenuCommand
11+
// @grant GM_openInTab
12+
// @grant GM_getValue
13+
// @grant GM_setValue
14+
// @grant GM_notification
915
// @license GPL-3.0 License
1016
// @run-at document-start
1117
// @namespace https://greasyfork.org/scripts/413721
1218
// ==/UserScript==
1319

1420
(function() {
15-
var style_Add = document.createElement('style');
16-
style_Add.innerHTML = `
17-
/* 清理多余内容 */
18-
.input-button-container,.ft-icon-row,.frame:before,.app-download-bar,#gb,.gp-footer,.feedback-link,#gt-input-tool {
19-
display: none !important;
20-
}
21+
var menu_streamline = GM_getValue('xiu2_menu_streamline');
22+
var menu_streamline_ID, menu_feedBack_ID;
23+
if (menu_streamline == null){menu_streamline = true; GM_setValue('xiu2_menu_streamline', menu_streamline)};
24+
registerMenuCommand();
25+
addStyle();
26+
27+
// 注册脚本菜单
28+
function registerMenuCommand() {
29+
var menu_streamline_;
30+
if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
31+
GM_unregisterMenuCommand(menu_streamline_ID);
32+
GM_unregisterMenuCommand(menu_feedBack_ID);
33+
menu_streamline = GM_getValue('xiu2_menu_streamline');
34+
}
35+
36+
if (menu_streamline){menu_streamline_ = "√";}else{menu_streamline_ = "×";}
37+
38+
menu_streamline_ID = GM_registerMenuCommand(`[ ${menu_streamline_} ] 精简美化`, function(){menu_switch(menu_streamline,'xiu2_menu_streamline','精简美化')});
39+
menu_feedBack_ID = GM_registerMenuCommand('反馈 & 建议', function () {window.GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true});});
40+
}
41+
42+
// 菜单开关
43+
function menu_switch(menu_status, Name, Tips) {
44+
if (menu_status){
45+
GM_setValue(`${Name}`, false);
46+
GM_notification(`已关闭 [${Tips}] 功能\n(刷新网页后生效)`);
47+
}else{
48+
GM_setValue(`${Name}`, true);
49+
GM_notification(`已开启 [${Tips}] 功能\n(刷新网页后生效)`);
50+
}
51+
registerMenuCommand(); // 重新注册脚本菜单
52+
};
53+
54+
55+
// 添加样式
56+
function addStyle() {
57+
var style,
58+
style_1 = `
2159
/* 翻译结果的选择列表宽度 */
2260
.alt-menu {
2361
max-width: 35% !important;
@@ -26,6 +64,11 @@
2664
.goog-menu.round-trip-content {
2765
white-space: normal !important;
2866
word-break: break-all !important;
67+
}`,
68+
style_2 = `
69+
/* 清理多余内容 */
70+
.input-button-container,.ft-icon-row,.frame:before,.app-download-bar,#gb,.gp-footer,.feedback-link,#gt-input-tool {
71+
display: none !important;
2972
}
3073
/* 主体顶部留白 */
3174
.homepage-content-wrap {
@@ -46,6 +89,14 @@
4689
}
4790
.results-container.empty {
4891
border-left: 1px solid rgba(0, 0, 0, 0.06) !important;
49-
}`;
92+
}`,
93+
style_Add = document.createElement('style');
94+
if (menu_streamline) {
95+
style = style_1 + style_2;
96+
}else{
97+
style = style_1;
98+
}
99+
style_Add.innerHTML = style;
50100
document.head.appendChild(style_Add);
101+
}
51102
})();

0 commit comments

Comments
 (0)