Skip to content

Instantly share code, notes, and snippets.

@laobubu
Last active March 5, 2019 06:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laobubu/d610b5dd6ee3a0a76f8886ac73198df2 to your computer and use it in GitHub Desktop.
Save laobubu/d610b5dd6ee3a0a76f8886ac73198df2 to your computer and use it in GitHub Desktop.
HyperMD for V2EX
/**
HyperMD breaks the wall between Preview and Writing for Markdown.
@see https://github.com/laobubu/HyperMD/
此脚本可以帮助你在 V2EX 发帖界面体验 HyperMD 的强大功能。
使用方法:
1. 打开发帖界面 https://www.v2ex.com/new
2. 在地址栏输入以下地址并回车 [^1]
javascript:void($.getScript('https://rawgit.com/laobubu/d610b5dd6ee3a0a76f8886ac73198df2/raw/hypermd-v2ex.js'))
3. 倒数5秒钟
[^1]: 有的浏览器出于保护目的,直接复制粘贴,可能会丢失前面的 javascript: 这段字符。
可以考虑将这个地址保存为书签,再通过书签访问这个神奇网址。
*/
+function(){
var p='https://laobubu.net/HyperMD'
function loadCss(url){$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href',url))}
function info(txt,color){ $('#content_remaining').text(txt).css({color:color||''}) }
var jsLoadSeq = [
'/static/js/codemirror/mode/meta.js',
'/static/js/codemirror/mode/xml/xml.js',
p+'/ai1.js',
p+'/powerpack/insert-file-with-smms.js',
]
loadCss(p+'/mode/hypermd.css')
loadCss(p+'/theme/hypermd-light.css')
info('HyperMD Loading...', '#000')
loadNextJs()
function loadNextJs() {
if (jsLoadSeq.length == 0) {
initEditor();
} else {
var url = jsLoadSeq.shift();
$.getScript(url, loadNextJs);
info(jsLoadSeq.length + ' components left ... HyperMD Loading...', 'blue');
}
}
function initEditor(){
info('Welcome to use HyperMD')
$([
'<li><span class="f13">HyperMD 编辑器</span><div class="sep10"></div>',
'当前编辑器为 <a href="https://github.com/laobubu/hypermd/" target="_blank">HyperMD</a>,',
'并且采用 <a href="https://sm.ms/" target="_blank">sm.ms</a> 的图床来上传图片。',
'由于 V2EX 内置 CodeMirror 内核版本偏老,使用体验上可能会有出入。',
'有问题和建议,<a href="https://github.com/laobubu/hypermd/issues" target="_blank">请到这里提交 issue</a>。',
'<div class="sep10"></div></li>'
].join('')).insertBefore($('#Rightbar .box ul li')[0])
var cfgs = HyperMD.suggestedEditorConfig;
for (var opt in cfgs) {
if (opt.slice(0,3) === 'hmd') editor.setOption(opt, cfgs[opt])
}
editor.setOption('mode','hypermd')
editor.setOption('keyMap','hypermd')
editor.setOption('theme', 'hypermd-light')
}
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment