Skip to content

Commit

Permalink
Merge pull request #33 from obgnail/dev
Browse files Browse the repository at this point in the history
update index.js
  • Loading branch information
obgnail authored Jul 27, 2023
2 parents 3876838 + 35d31a2 commit 992925d
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 48 deletions.
2 changes: 2 additions & 0 deletions plugin/auto_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,7 @@
style.innerHTML = css;
document.getElementsByTagName("head")[0].appendChild(style);

module.exports = {config};

console.log("auto_number.js had been injected");
})()
2 changes: 2 additions & 0 deletions plugin/collapse_paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@
}
})

module.exports = {config};

console.log("collapse_paragraph.js had been injected");
})()
2 changes: 1 addition & 1 deletion plugin/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
modal.input.select();
}

module.exports = {Call};
module.exports = {Call, config};

window.addEventListener("keydown", ev => {
if (config.HOTKEY(ev)) {
Expand Down
2 changes: 2 additions & 0 deletions plugin/fence_enhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,7 @@
}
}

module.exports = {config};

console.log("fence_enhance.js had been injected");
})()
2 changes: 2 additions & 0 deletions plugin/file_counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,7 @@
}
}, config.LOOP_DETECT_INTERVAL);

module.exports = {config};

console.log("file_counter.js had been injected");
})()
2 changes: 1 addition & 1 deletion plugin/go_top.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
goTopDiv.style.display = (content.scrollTop > config.THRESHOLD) ? "block" : "none";
})

module.exports = {Call};
module.exports = {Call, config};
console.log("go_top.js had been injected");
})()
47 changes: 7 additions & 40 deletions plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,141 +1,107 @@
window.onload = () => {
global._plugin_had_injected = false;
global._plugins_had_injected = false;
global._plugins = [
{
name: "标签页管理",
src: "./plugin/window_tab.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "全局多关键字搜索",
src: "./plugin/search_multi.js",
enable: true,
clickable: true,
call: null,
call_args: null,
},
{
name: "多关键字高亮",
src: "./plugin/multi_highlighter/index.js",
enable: true,
clickable: true,
call: null,
call_args: null,
},
{
name: "表格大小调整",
src: "./plugin/resize_table.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "只读模式",
src: "./plugin/read_only.js",
enable: true,
clickable: true,
call: null,
call_args: null,
},
{
name: "文段截断",
src: "./plugin/truncate_text.js",
enable: true,
clickable: true,
call: null,
call_args: null,
},
{
name: "图片大小调整",
src: "./plugin/resize_image.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "命令行环境",
src: "./plugin/commander.js",
enable: true,
clickable: true,
call: null,
call_args: null,
},
{
name: "代码块增强",
src: "./plugin/fence_enhance.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "一键到顶",
src: "./plugin/go_top.js",
enable: true,
clickable: true,
call: null,
call_args: null,
},
{
name: "文件计数",
src: "./plugin/file_counter.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "章节折叠",
src: "./plugin/collapse_paragraph.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "中英文混排优化",
src: "./plugin/md_padding/index.js",
enable: true,
clickable: true,
call: null,
call_args: null,
},
{
name: "mermaid替换",
src: "./plugin/mermaid_replace/index.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "自动编号",
src: "./plugin/auto_number.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "右键菜单",
src: "./plugin/right_click_menu.js",
enable: true,
clickable: false,
call: null,
call_args: null,
},
{
name: "测试专用",
src: "./plugin/test.js",
enable: false,
clickable: false,
call: null,
call_args: null,
},
]

Expand All @@ -151,9 +117,10 @@ window.onload = () => {
const promise = new Promise((resolve, reject) => {
_fs.access(filepath, err => {
if (!err) {
const {Call, CallArgs} = reqnode(filepath);
plugin.call = Call;
plugin.call_args = CallArgs;
const {config, Call, CallArgs} = reqnode(filepath);
plugin.config = config || null;
plugin.call = Call || null;
plugin.call_args = CallArgs || null;
resolve(plugin);
} else {
plugin.enable = false;
Expand All @@ -166,8 +133,8 @@ window.onload = () => {
})

Promise.all(promises)
.then(() => global._plugin_had_injected = true)
.catch(() => global._plugin_had_injected = true)
.then(() => global._plugins_had_injected = true)
.catch(() => global._plugins_had_injected = true)
}

loadPlugin();
Expand Down
2 changes: 1 addition & 1 deletion plugin/md_padding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
reload(formattedContent);
})
}
module.exports = {Call};
module.exports = {config, Call};

window.addEventListener("keydown", ev => {
if (config.HOTKEY(ev)) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/multi_highlighter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
ev.stopPropagation();
}
});
module.exports = {Call};
module.exports = {config, Call};

const getKeyArr = () => {
const value = modal.input.value;
Expand Down
2 changes: 1 addition & 1 deletion plugin/read_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
}, config.LOOP_DETECT_INTERVAL);
}

module.exports = {Call};
module.exports = {Call, config};

console.log("read_only.js had been injected");
})()
2 changes: 2 additions & 0 deletions plugin/resize_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
requestAnimationFrame(() => target.style.width = width + "px");
}, true);

module.exports = {config};

console.log("resize_image.js had been injected");
})()
2 changes: 2 additions & 0 deletions plugin/resize_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,7 @@
document.addEventListener('mousemove', onMouseMove);
})

module.exports = {config};

console.log("resize_table.js had been injected");
})()
4 changes: 3 additions & 1 deletion plugin/right_click_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@
}

const _timer = setInterval(() => {
if (global._plugin_had_injected) {
if (global._plugins_had_injected) {
clearInterval(_timer);
appendMenu();
}
}, config.LOOP_DETECT_INTERVAL);

module.exports = {config};

console.log("right_click_menu.js had been injected");
})()
2 changes: 1 addition & 1 deletion plugin/search_multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@
ev.stopPropagation();
})

module.exports = {Call};
module.exports = {Call, config};

console.log("search_multi.js had been injected");
})();
2 changes: 1 addition & 1 deletion plugin/truncate_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,6 @@
}
}, true)

module.exports = {Call, CallArgs};
module.exports = {Call, CallArgs, config};
console.log("truncate_text.js had been injected");
})()
2 changes: 2 additions & 0 deletions plugin/window_tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,7 @@
})
}

module.exports = {config};

console.log("window_tab.js had been injected");
})()

0 comments on commit 992925d

Please sign in to comment.