This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleMDEditor.js
48 lines (41 loc) · 1.74 KB
/
SimpleMDEditor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ==UserScript==
// @name 巴哈論壇文章簡易 MD 編輯器
// @namespace https://home.gamer.com.tw/moontai0724
// @version 0.1
// @description 在巴哈姆特論壇發文區加上 Markdown 編輯器,十分簡易,且有轉換問題,請小心使用。
// @author moontai0724
// @match https://forum.gamer.com.tw/post*
// @supportURL https://home.gamer.com.tw/creationDetail.php?sn=4587238
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @require https://unpkg.com/[email protected]/docs/lib/stackedit.min.js
// @require https://unpkg.com/turndown/dist/turndown.js
// @license MIT
// ==/UserScript==
(function (jQuery) {
'use strict';
(function initializeScript() {
jQuery(".editor-toolbar").append(`<div class="top-editor__icongroup"><button id="MDE_initialize" class="editor-button" type="button">MD</button></div>`);
jQuery("#MDE_initialize").on("click", event => {
if (jQuery(".fe_source").hasClass("is-active"))
bahaRte.toolbar.alternateView(!0);
jQuery(event.target).addClass("is-active");
openMDEditor();
});
})();
function openMDEditor() {
const stackedit = new Stackedit();
stackedit.openFile({
content: {
text: new TurndownService().turndown(bahaRte.convertor.toHtml(bahaRte.getContent()))
}
});
console.log(stackedit);
stackedit.on("fileChange", file => {
bahaRte.doc.body.innerHTML = file.content.html;
bahaRte.utility.save();
});
stackedit.on("close", file => {
jQuery("#MDE_initialize").removeClass("is-active");
});
}
})(jQuery);