油猴脚本(3)——智能文档粘贴markdown

wils
wils

创作者俱乐部成员

网页里的智能文档不能粘贴markdown,有点不便

前面说过油猴脚本可以把网页改造成你喜欢的样子

今天试着加个粘贴markdown的方法

油猴脚本如下:

🔔

// ==UserScript==

// @name kdocs

// @namespace http://tampermonkey.net/

// @version 2024-07-01

// @description try to take over the world!

// @author You

// @match https://www.kdocs.cn/*

// @icon https://www.google.com/s2/favicons?sz=64&domain=kdocs.cn

// @require https://cdnjs.cloudflare.com/ajax/libs/marked/13.0.2/marked.min.js

// @grant none

// ==/UserScript==

(function() {

'use strict';

function debounce(func, delay) {

let timerId;

return function () {

const context = this;

const args = arguments;

clearTimeout(timerId);

timerId = setTimeout(() => {

func.apply(context, args);

}, delay);

};

}

const textarea = document.createElement('textarea');

document.body.prepend(textarea);

const iframe = document.createElement('iframe');

document.body.prepend(iframe);

textarea.oninput = debounce(function(e){

iframe.srcdoc = marked.parse(e.target.value);

}, 600)

})();

上面是个防抖函数debounce

然后用油猴脚本,在body前面插入一个textarea和一个iframe

最后设置textarea的input事件触发个防抖的渲染markdown到iframe内容的方法

广东省
浏览 306
1
6
分享
6 +1
3
1 +1
全部评论 3
 
『峰格』
凡是过往皆为序章,所有将来皆为可盼
· 山东省
1
回复
 
畅心
automa也可以调用openai接口操作整个application
· 广东省
1
回复
 
sainu
打卡打卡
· 河北省
1
回复