Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zxkmm committed Jan 12, 2024
1 parent 9f664a0 commit 46353a1
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 93 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# siyuan_rmv_btn
A SiYuan Plugin that able to remove the buttons in menu that you don't really use.
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.
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.

## changelog 1.1.0 2024.01.12
- Add icons for reference in setting panel.
- Not anymore detect or read old config.
- Delete config data after uninstall, but not when turn off plugin.

# Warning
- If you removed too much items and end up stopped working, please go to your workspace and delete the entire ``siyuan_rmv_btn`` folder.
- 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.
Expand All @@ -11,7 +17,7 @@ It currently support removing top bar icons, side bar icons, and menus with id `
# Links
repo/Source Code:https://github.com/zxkmm/siyuan_rmv_btn

Download:https://github.com/zxkmm/siyuan_rmv_btn/releases
Download:https://github.com/zxkmm/siyuan_rmv_btn/releases or search `siyuan_rmv_btn` in SiYuan market

Reporting Bugs / Submitting Feqture request:https://github.com/zxkmm/siyuan_rmv_btn/issues

Expand Down
10 changes: 8 additions & 2 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# 思源隐藏菜单项
# 思源移除按钮

一个SiYuan插件,可以删除菜单/底栏/顶栏中你不使用的按钮。
现阶段支持移除顶栏指定按钮,侧栏指定按钮,右键菜单项内容。
本插件在MIT协议下开源,没有联网行为,也没有从远端fetch恶意代码的能力。

## changelog 1.1.0 2024.01.12
- Add icons for reference in setting panel.
- Not anymore detect or read old config.
- Delete config data after uninstall, but not when turn off plugin.

# 链接
repo/源码:https://github.com/zxkmm/siyuan_rmv_btn

下载:集市搜索 “隐藏按钮” 或者 访问 https://github.com/zxkmm/siyuan_rmv_btn/releases
下载:集市搜索 “移除按钮” 或者 访问 https://github.com/zxkmm/siyuan_rmv_btn/releases

汇报 bug / 提交功能请求:https://github.com/zxkmm/siyuan_rmv_btn/issues

论坛thread:https://ld246.com/article/1701669406727

# 警告

- 如果你移除了太多东西导致无法正常操作,请到思源工作空间删除整个``siyuan_rmv_btn``文件夹。
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "siyuan_rmv_btn",
"version": "1.0.2",
"version": "1.1.0",
"type": "module",
"description": "A plugin to remove menu items you don't really need.",
"repository": "https://github.com/zxkmm/siyuan_rmv_btn",
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "siyuan_rmv_btn",
"author": "zxkmm",
"url": "https://github.com/zxkmm/siyuan_rmv_btn",
"version": "1.0.2",
"version": "1.1.0",
"minAppVersion": "2.10.14",
"backends": [
"windows",
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"totalSwitch": "Total Switch",
"totalSwitchdesc": "If the items you want to hide are related to the commercial part of Source, please consider donating to @D and @V (not me) as they live by writing open-source code.<br> v1.0.2",
"listenImplementation": "Listen Implementation",
"listenImplementationdesc": "It is recommended to choose the DOMNodeInserted option for the best overall performance, but this option will output a warning in the terminal. If you cannot accept this, please choose one of the other two implementations.",
"listenImplementationdesc": "It is recommended to choose the DOMNodeInserted option for the best overall performance, but this option will output a warning in the console. If you cannot accept this, please choose one of the other two implementations.",
"reload_hint": "Reload the interface to apply the latest changes.",
"old_config_exist": "Remove Button Plugin:<br> Due to a <b><u>performance improvement</u></b> refactoring of the configuration storage system in the latest version, please <b><u>uninstall and reinstall</u></b> the Remove Button Plugin after seeing this prompt. Enter the configuration in the settings interface again to ensure performance and stability. Thank you for your understanding. <br> This prompt will appear <b><u>only once per device</u></b> after <b><u>correct reinstallation</u></b>. If you still see this prompt after reinstalling, please uninstall the Remove Button Plugin first and report the bug to the developer.",
"rm_menu_title": "Menu Items to Hide",
Expand All @@ -13,6 +13,6 @@
"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>",
"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",
"uninstall_hint": "Succesfully uninstalled Remove Button Plugin.",
"hintTitle": "About",
"hintTitle": "About v1.1.0",
"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>"
}
4 changes: 2 additions & 2 deletions src/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"totalSwitch": "总开关",
"totalSwitchdesc": "如果您要隐藏的项目与思源的商业部分有关,请考虑向@D和@V捐赠(不是我),因为他们以编写开源代码生活。<br> v1.0.2",
"listenImplementation": "监听实现",
"listenImplementationdesc": "建议首选综合性能最佳的DOMNodeInserted, 但是这个选项会在终端输出一个warning,如果您无法接受,请选择另外两个实现",
"listenImplementationdesc": "建议首选综合性能最佳的DOMNodeInserted, 但是这个选项会在控制台输出一个warning,如果您无法接受,请选择另外两个实现",
"reload_hint": "重载界面以应用最新更改",
"old_config_exist": "移除按钮插件:<br> 由于最新版本对配置存储系统进行了<b><u>提高性能</u></b>的重构,请在看到这个提示后,<b><u>卸载并重新安装</u></b>移除按钮插件,并重新在设置界面键入配置, 以保证性能和稳定性,谢谢您的理解. <br>此提示在您正确<b><u>重新安装后</u></b>,每个设备<b><u>仅会弹出一次</u></b> <br>如果重新安装后依然不断看到此提示, 请先卸载移除按钮插件, 并向开发者汇报bug",
"rm_menu_title": "要隐藏的菜单项",
Expand All @@ -13,6 +13,6 @@
"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>",
"ignore_warning": "移除按钮插件: 上方的warning是因为您选择了高性能的监听方式,若不喜欢,请在设置页面选择另外两种方式,谢谢",
"uninstall_hint": "移除按钮插件: 成功卸载",
"hintTitle": "关于",
"hintTitle": "关于 v1.1.0",
"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>"
}
106 changes: 23 additions & 83 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ const STORAGE_NAME = "menu-config";

const frontEnd = getFrontend();

//old trash
const unwantedItem = "unwantedItem";
const unwantedTopBarIcon = "unwantedTopBarIcon";
const unwantedSideBarIcon = "unwatedSideBarIcon";
//old trash end

const targetNode = document.getElementById('commonMenu'); //it's the menu's id

export default class siyuan_rmv_btn extends Plugin {
Expand All @@ -36,11 +30,11 @@ export default class siyuan_rmv_btn extends Plugin {
}
}

rmvMenuItems(_toRemoveListArray_,_monitorImplementation_){
if(_monitorImplementation_ == 1){ //DOMNodeInserted
rmvMenuItems(_toRemoveListArray_, _monitorImplementation_) {
if (_monitorImplementation_ == 1) { //DOMNodeInserted
targetNode.addEventListener('DOMNodeInserted', function (e) {
const buttons = Array.from(targetNode.getElementsByTagName('button'));

buttons.forEach((button) => {
let labelElement = button.getElementsByClassName('b3-menu__label')[0];
if (labelElement) {
Expand All @@ -50,17 +44,17 @@ export default class siyuan_rmv_btn extends Plugin {
}
}
});

}, false);
console.log(this.i18n.ignore_warning);
}else if(_monitorImplementation_ == 2){ //MutationObserver
var observer = new MutationObserver(function(mutationsList, observer) {
for(let mutation of mutationsList) {

} else if (_monitorImplementation_ == 2) { //MutationObserver
var observer = new MutationObserver(function (mutationsList, observer) {
for (let mutation of mutationsList) {
// if((mutation.type === 'childList') || (mutation.type === 'subtree')) {
if(mutation.type) {
if (mutation.type) {
const buttons = Array.from(document.getElementById('commonMenu').getElementsByTagName('button'));

buttons.forEach((button) => {
let labelElement = button.getElementsByClassName('b3-menu__label')[0];
if (labelElement) {
Expand All @@ -73,14 +67,14 @@ export default class siyuan_rmv_btn extends Plugin {
}
}
});

observer.observe(targetNode, { childList: true, subtree: true });
}else {
var observer = new MutationObserver(function(mutationsList, observer) {
for(let mutation of mutationsList) {
if((mutation.type === 'childList') || (mutation.type === 'subtree')) {
} else {
var observer = new MutationObserver(function (mutationsList, observer) {
for (let mutation of mutationsList) {
if ((mutation.type === 'childList') || (mutation.type === 'subtree')) {
const buttons = Array.from(document.getElementById('commonMenu').getElementsByTagName('button'));

buttons.forEach((button) => {
let labelElement = button.getElementsByClassName('b3-menu__label')[0];
if (labelElement) {
Expand All @@ -93,13 +87,12 @@ export default class siyuan_rmv_btn extends Plugin {
}
}
});

observer.observe(targetNode, { childList: true, subtree: true });
}
}


rmvTopButtonBarIcons(_toRemoveListArray_){
rmvTopButtonBarIcons(_toRemoveListArray_) {
_toRemoveListArray_.forEach(elementType => {
const styleElement = document.createElement('style');
styleElement.textContent = `
Expand All @@ -114,7 +107,7 @@ export default class siyuan_rmv_btn extends Plugin {

rmvSideBarIcons(_toRemoveListArray_) {

if (frontEnd == "desktop" || frontEnd =="browser-desktop") {
if (frontEnd == "desktop" || frontEnd == "browser-desktop") {
//pc view
_toRemoveListArray_.forEach(elementType => {
const styleElement = document.createElement('style');
Expand All @@ -127,7 +120,7 @@ export default class siyuan_rmv_btn extends Plugin {
});
//mobile view
}
if (frontEnd == "mobile" || frontEnd =="browser-mobile") {
if (frontEnd == "mobile" || frontEnd == "browser-mobile") {
//mobile
_toRemoveListArray_.forEach(elementType => {
const styleElement = document.createElement('style');
Expand All @@ -142,49 +135,13 @@ export default class siyuan_rmv_btn extends Plugin {
}
}

checkOldComfigExist(){ //old trash detect
if (
this.data[unwantedTopBarIcon].unwantedTopBarIcons ||
this.data[unwantedSideBarIcon].unwantedTopBarIcons ||
this.data[unwantedSideBarIcon].unwantedTopBarIcons
){
console.log(this.i18n.old_config_exist);
showMessage(this.i18n.old_config_exist);
}

}

reloadInterface(){
reloadInterface() {
window.location.reload();
showMessage(this.i18n.reload_hint);
}

async onload() {


//old trash
try {
const _item_ = await this.loadData(unwantedItem);
this.data[unwantedItem].unwantedItems = _item_.unwantedItems;
} catch (error) {
this.data[unwantedItem] = { unwantedItems: "" };
}

try {
const _item_ = await this.loadData(unwantedTopBarIcon);
this.data[unwantedTopBarIcon].unwantedTopBarIcons = _item_.unwantedTopBarIcons;
} catch (error) {
this.data[unwantedTopBarIcon] = { unwantedTopBarIcons: "" }
}

try {
const _item_ = await this.loadData(unwantedSideBarIcon);
this.data[unwantedSideBarIcon].unwantedSideBarIcons = _item_.unwantedSideBarIcons;
} catch (error) {
this.data[unwantedSideBarIcon] = { unwantedSideBarIcons: "" }
}
//old trash end

this.settingUtils = new SettingUtils(this, STORAGE_NAME);
this.settingUtils.load();
this.settingUtils.addItem({
Expand Down Expand Up @@ -234,26 +191,13 @@ export default class siyuan_rmv_btn extends Plugin {
title: this.i18n.hintTitle,
description: this.i18n.hintDesc,
});


}

onLayoutReady() {

this.checkOldComfigExist();
this.loadData(STORAGE_NAME);
this.settingUtils.load();

// console.log(frontEnd); //DBG

// //dbg
// console.log("menuItems2Rmv" + this.settingUtils.get("unwantedMenuItem"));
// console.log("topbtn2rmv" + this.settingUtils.get("unwantedTopButtonBarIcon"));
// console.log("sideBtn2mv" + this.settingUtils.get("unwantedSideBarIcon"));
// console.log("obsImp"+ this.settingUtils.get("listenImplementation"));
// //dbg


if (this.settingUtils.get("totalSwitch")) {
this.rmvTopButtonBarIcons(
this.convertStringToArray(
Expand Down Expand Up @@ -281,12 +225,8 @@ export default class siyuan_rmv_btn extends Plugin {
this.reloadInterface();
}

uninstall(){
//remove old trash
this.removeData(unwantedTopBarIcon);
this.removeData(unwantedSideBarIcon);
this.removeData(unwantedItem);
//remove old trash end
uninstall() {
this.removeData(STORAGE_NAME);
showMessage(this.i18n.uninstall_hint);
}

Expand Down
Loading

0 comments on commit 46353a1

Please sign in to comment.