Skip to content

Commit 9ee250e

Browse files
committedJan 18, 2024
add seperator policy
·
v2.0.1v1.1.1
1 parent fc537e8 commit 9ee250e

File tree

7 files changed

+111
-35
lines changed

7 files changed

+111
-35
lines changed
 

‎README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22
A SiYuan Plugin that able to remove the buttons in menu that you don't really use.
33
It currently support removing top bar icons, side bar icons, and menus with id `commonMenu`, which are two icons on top right corner of each doc, and calling from the right side of each paragraph.
44

5+
# Download
6+
go to release page or go to SiYuan's market and search `siyuan_rmv_btn`
7+
8+
59
## changelog 1.1.0 2024.01.12
610
- Add icons for reference in setting panel.
711
- Not anymore detect or read old config.
812
- Delete config data after uninstall, but not when turn off plugin.
913

14+
## changelog 1.1.1 2024.01.19
15+
- add seperator policy:
16+
- two meet each other, hide one
17+
- hide all
18+
- don't touch
19+
1020
# Warning
1121
- If you removed too much items and end up stopped working, please go to your workspace and delete the entire ``siyuan_rmv_btn`` folder.
1222
- The handler handle main interface of SiYuan as soon as DOM changes. In which case if you added too many items, the performance would be influenced.

‎README_zh_CN.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@
44
现阶段支持移除顶栏指定按钮,侧栏指定按钮,右键菜单项内容。
55
本插件在MIT协议下开源,没有联网行为,也没有从远端fetch恶意代码的能力。
66

7+
# 下载
8+
到release页面下载,或者到思源集市搜索“移除按钮”
9+
710
## changelog 1.1.0 2024.01.12
811
- Add icons for reference in setting panel.
912
- Not anymore detect or read old config.
1013
- Delete config data after uninstall, but not when turn off plugin.
1114

15+
## changelog 1.1.1 2024.01.19
16+
- add seperator policy:
17+
- two meet each other, hide one
18+
- hide all
19+
- don't touch
20+
1221
# 链接
1322
repo/源码:https://github.com/zxkmm/siyuan_rmv_btn
1423

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "siyuan_rmv_btn",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"type": "module",
55
"description": "A plugin to remove menu items you don't really need.",
66
"repository": "https://github.com/zxkmm/siyuan_rmv_btn",

‎plugin.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "siyuan_rmv_btn",
33
"author": "zxkmm",
44
"url": "https://github.com/zxkmm/siyuan_rmv_btn",
5-
"version": "1.1.0",
5+
"version": "1.1.1",
66
"minAppVersion": "2.10.14",
77
"backends": [
88
"windows",
@@ -41,6 +41,7 @@
4141
"菜单",
4242
"remove",
4343
"hide",
44-
"menu"
44+
"menu",
45+
"siyuan_rmv_btn"
4546
]
4647
}

‎src/i18n/en_US.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
"rm_side_desc": "<head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><style>#siyuan_rmv_btn_setting_table svg {border: 1px;width: 1em;height: 1em;vertical-align: middle;}#siyuan_rmv_btn_setting_table table {border-collapse: collapse;width: 100%;margin: 0 auto;}#siyuan_rmv_btn_setting_table td {border: 1px;padding: 10px;text-align: right;}#siyuan_rmv_btn_setting_table th {border: 1px;padding: 10px;text-align: left;font-weight: bold;}#siyuan_rmv_btn_setting_table tr:hover {box-shadow: inset 0 0 10px #999;}</style></head><body> Enter the provided label name strings (e.g., \"outline, tag\" without quotes)<br>Separate with English or Chinesehalf-width commas, i.e., \",\" or \",\".<br>Options:<br><table id=\"siyuan_rmv_btn_setting_table\"><thead><tr><th>Items to Hide</th><th>Input String (Double-click to select)</th></tr></thead><tbody><tr><th><svg><use xlink:href=\"#iconAlignCenter\"></use></svg> Outline Icon</th><td>outline</td></tr><tr><th><svg><use xlink:href=\"#iconInbox\"></use></svg> Inbox Icon</th><td>inbox</td></tr><tr><th><svg><use xlink:href=\"#iconBookmark\"></use></svg> Bookmark Icon</th><td>bookmark</td></tr><tr><th><svg><use xlink:href=\"#iconTags\"></use></svg> Tag Icon</th><td>tag</td></tr><tr><th><svg><use xlink:href=\"#iconLink\"></use></svg> Backlink Icon</th><td>backlink</td></tr><tr><th><svg><use xlink:href=\"#iconGlobalGraph\"></use></svg> Global Graph Icon</th><td>globalGraph</td></tr><tr><th><svg><use xlink:href=\"#iconGraph\"></use></svg> Notebook Graph Icon</th><td>graph</td></tr></tbody></table></body>",
1414
"ignore_warning": "remove button plugin: the warning above is just because you choosed a high performance observing implementation, if you don't like it, you may choose the other two selections in the setting panel. thank you",
1515
"uninstall_hint": "Succesfully uninstalled Remove Button Plugin.",
16-
"hintTitle": "About v1.1.0",
16+
"seperateHandlePolicy": "Menu item separator hide policy",
17+
"seperateHandlePolicydesc": "If you want to hide the menu item separators, please select a hide policy here",
18+
"seperateHandlePolicyDontTouch": "Don't handle",
19+
"seperateHandlePolicyHideAll": "Hide all",
20+
"seperateHandlePolicyHideIfTwoMeetEachOther": "Hide one if two adjacent separators meet",
21+
"hintTitle": "About v1.1.1",
1722
"hintDesc": "<ul><li>● By <a href='https://github.com/zxkmm'>zxkmm</a> and open source under the MIT license.</li><li>● Please star⭐ my GitHub repository if you like this plugin.</li><li>● Link: <a href='https://github.com/zxkmm/siyuan_rmv_btn'>https://github.com/zxkmm/siyuan_rmv_btn</a></li><li>● If you want to hide elements related to SiYuan's commercial part, please consider donating to the makers of SiYuan (AKA @D and @V) (not me) before using.</li></ul>"
1823
}

‎src/i18n/zh_CN.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
"rm_side_desc": "<head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><style>#siyuan_rmv_btn_setting_table svg {border: 1px;width: 1em;height: 1em;vertical-align: middle;}#siyuan_rmv_btn_setting_table table {border-collapse: collapse;width: 100%;margin: 0 auto;}#siyuan_rmv_btn_setting_table td {border: 1px;padding: 10px;text-align: right;}#siyuan_rmv_btn_setting_table th {border: 1px;padding: 10px;text-align: left;font-weight: bold;}#siyuan_rmv_btn_setting_table tr:hover {box-shadow: inset 0 0 10px #999;}</style></head><body>填写提供的标签名字符串(如“outline,tag”(不包括双引号))<br>用英文或中文半角逗号,即\",\"或\",\"隔开。<br>选项:<br><table id=\"siyuan_rmv_btn_setting_table\"><thead><tr><th>要隐藏的项目</th><th>输入的字符串(双击选中)</th></tr></thead><tbody><tr><th><svg><use xlink:href=\"#iconAlignCenter\"></use></svg> 大纲图标</th><td>outline</td></tr><tr><th><svg><use xlink:href=\"#iconInbox\"></use></svg> 收件箱图标</th><td>inbox</td></tr><tr><th><svg><use xlink:href=\"#iconBookmark\"></use></svg> 书签图标</th><td>bookmark</td></tr><tr><th><svg><use xlink:href=\"#iconTags\"></use></svg> 标签图标</th><td>tag</td></tr><tr><th><svg><use xlink:href=\"#iconLink\"></use></svg> 反链图标</th><td>backlink</td></tr><tr><th><svg><use xlink:href=\"#iconGlobalGraph\"></use></svg> 全局图谱图标</th><td>globalGraph</td></tr><tr><th><svg><use xlink:href=\"#iconGraph\"></use></svg> 单个笔记本图谱图标</th><td>graph</td></tr></tbody></table></body>",
1414
"ignore_warning": "移除按钮插件: 上方的warning是因为您选择了高性能的监听方式,若不喜欢,请在设置页面选择另外两种方式,谢谢",
1515
"uninstall_hint": "移除按钮插件: 成功卸载",
16-
"hintTitle": "关于 v1.1.0",
16+
"seperateHandlePolicy":"菜单项分割线隐藏策略",
17+
"seperateHandlePolicydesc":"如果您想隐藏菜单项分割线,请在这里选择隐藏策略",
18+
"seperateHandlePolicyDontTouch":"不处理",
19+
"seperateHandlePolicyHideAll":"全部隐藏",
20+
"seperateHandlePolicyHideIfTwoMeetEachOther":"如果出现两个相邻,则隐藏一个",
21+
"hintTitle": "关于 v1.1.1",
1722
"hintDesc": "<ul><li>● 由<a href='https://github.com/zxkmm'>zxkmm</a>制作, MIT 协议开源。</li><li>● 如果您喜欢这个插件,请给我的 GitHub 仓库点亮免费的星星⭐(Star)。</li><li>● 链接:<a href='https://github.com/zxkmm/siyuan_rmv_btn'>https://github.com/zxkmm/siyuan_rmv_btn</a></li><li>● 如果您想隐藏与思源商业部分相关的元素,请在使用前考虑向思源的制作者(即@D和@V)捐赠(不是捐给我)。</li></ul>"
1823
}

‎src/index.ts

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,81 @@ export default class siyuan_rmv_btn extends Plugin {
3030
}
3131
}
3232

33-
rmvMenuItems(_toRemoveListArray_, _monitorImplementation_) {
34-
if (_monitorImplementation_ == 1) { //DOMNodeInserted
35-
targetNode.addEventListener('DOMNodeInserted', function (e) {
36-
const buttons = Array.from(targetNode.getElementsByTagName('button'));
33+
rmvMenuItems(_toRemoveListArray_, _monitorImplementation_, _seperateHidingPolicy_) {
34+
35+
//seperate pilocy: 1; don't touch
36+
// 2: hide all
37+
// 3: hide if two meet each other
38+
39+
function hideButtonsAndSeparators(_items_) {
3740

38-
buttons.forEach((button) => {
39-
let labelElement = button.getElementsByClassName('b3-menu__label')[0];
41+
for (let i = 0; i < _items_.length; i++) { //hide btns
42+
let item = _items_[i];
43+
if (item.classList.contains('b3-menu__item')) {
44+
let labelElement = item.getElementsByClassName('b3-menu__label')[0];
4045
if (labelElement) {
4146
let span_text = labelElement.textContent.trim();
4247
if (_toRemoveListArray_.includes(span_text)) {
43-
button.style.display = 'none';
48+
item.style.display = 'none';
4449
}
4550
}
46-
});
51+
}
52+
}
4753

54+
if (_seperateHidingPolicy_ == 3) {
55+
// test seperate and hide if two meet each other
56+
// TODO: didn't handle the situation that more than two seperators meet each other....
57+
// 烧脑。。。
58+
let startSeparatorIndex = -1;
59+
let previousSeparatorHidden = false;
60+
for (let i = 0; i < _items_.length; i++) {
61+
if (_items_[i].classList.contains('b3-menu__separator')) {
62+
if (startSeparatorIndex === -1) {
63+
startSeparatorIndex = i;
64+
} else {
65+
let allButtonsHidden = true;
66+
for (let j = startSeparatorIndex + 1; j < i; j++) {
67+
if (_items_[j].style.display !== 'none') {
68+
allButtonsHidden = false;
69+
break;
70+
}
71+
}
72+
if (allButtonsHidden && !previousSeparatorHidden) {
73+
_items_[startSeparatorIndex].style.display = 'none';
74+
previousSeparatorHidden = true;
75+
} else {
76+
previousSeparatorHidden = false;
77+
}
78+
startSeparatorIndex = i;
79+
}
80+
}
81+
}
82+
} else if (_seperateHidingPolicy_ == 2) {
83+
// hide all
84+
for (let i = 0; i < _items_.length; i++) {
85+
if (_items_[i].classList.contains('b3-menu__separator')) {
86+
_items_[i].style.display = 'none';
87+
}
88+
}
89+
}
90+
91+
92+
}
93+
94+
95+
if (_monitorImplementation_ == 1) { //DOMNodeInserted
96+
targetNode.addEventListener('DOMNodeInserted', function (e) {
97+
const buttons = Array.from(targetNode.getElementsByTagName('button'));
98+
hideButtonsAndSeparators(buttons);
4899
}, false);
49100
console.log(this.i18n.ignore_warning);
50101

51102
} else if (_monitorImplementation_ == 2) { //MutationObserver
52103
var observer = new MutationObserver(function (mutationsList, observer) {
53104
for (let mutation of mutationsList) {
54-
// if((mutation.type === 'childList') || (mutation.type === 'subtree')) {
55105
if (mutation.type) {
56106
const buttons = Array.from(document.getElementById('commonMenu').getElementsByTagName('button'));
57-
58-
buttons.forEach((button) => {
59-
let labelElement = button.getElementsByClassName('b3-menu__label')[0];
60-
if (labelElement) {
61-
let span_text = labelElement.textContent.trim();
62-
if (_toRemoveListArray_.includes(span_text)) {
63-
button.style.display = 'none';
64-
}
65-
}
66-
});
107+
hideButtonsAndSeparators(buttons);
67108
}
68109
}
69110
});
@@ -74,16 +115,7 @@ export default class siyuan_rmv_btn extends Plugin {
74115
for (let mutation of mutationsList) {
75116
if ((mutation.type === 'childList') || (mutation.type === 'subtree')) {
76117
const buttons = Array.from(document.getElementById('commonMenu').getElementsByTagName('button'));
77-
78-
buttons.forEach((button) => {
79-
let labelElement = button.getElementsByClassName('b3-menu__label')[0];
80-
if (labelElement) {
81-
let span_text = labelElement.textContent.trim();
82-
if (_toRemoveListArray_.includes(span_text)) {
83-
button.style.display = 'none';
84-
}
85-
}
86-
});
118+
hideButtonsAndSeparators(buttons);
87119
}
88120
}
89121
});
@@ -92,6 +124,7 @@ export default class siyuan_rmv_btn extends Plugin {
92124
}
93125
}
94126

127+
95128
rmvTopButtonBarIcons(_toRemoveListArray_) {
96129
_toRemoveListArray_.forEach(elementType => {
97130
const styleElement = document.createElement('style');
@@ -163,6 +196,18 @@ export default class siyuan_rmv_btn extends Plugin {
163196
3: "MutationObserver(type hard coded)"
164197
}
165198
});
199+
this.settingUtils.addItem({
200+
key: "seperateHandlePolicy",
201+
value: 1,
202+
type: "select",
203+
title: this.i18n.seperateHandlePolicy,
204+
description: this.i18n.seperateHandlePolicydesc,
205+
options: {
206+
1: this.i18n.seperateHandlePolicyDontTouch,
207+
2: this.i18n.seperateHandlePolicyHideAll,
208+
3: this.i18n.seperateHandlePolicyHideIfTwoMeetEachOther,
209+
}
210+
});
166211
this.settingUtils.addItem({
167212
key: "unwantedMenuItem",
168213
value: "",
@@ -215,7 +260,8 @@ export default class siyuan_rmv_btn extends Plugin {
215260
this.convertStringToArray(
216261
this.settingUtils.get("unwantedMenuItem")
217262
),
218-
this.settingUtils.get("listenImplementation")
263+
this.settingUtils.get("listenImplementation"),
264+
this.settingUtils.get("seperateHandlePolicy")
219265
)
220266
}
221267
}

0 commit comments

Comments
 (0)
Please sign in to comment.