Comments (18)
继续右键查找 function 定义可以发现 reqnode
的 file path 是 node:internal/modules/cjs/helpers
, 是 NodeJS 相关的
取 Windows Typora 里的 global
的 keys 并和 Mac Typora 里的 window
的 keys 做对比
首先把两个数组分别通过 temp1.sort((a, b) => a.localeCompare(b))
按字母顺序排序后,复制保存成本地文件,然后通过 git diff
命令对比,发现有一些差异,但大体上是一样的作用。
diff --git a/global.txt b/window.txt
index feee737..86dbf7e 100644
--- a/global.txt
+++ b/window.txt
@@ -1,9 +1,10 @@
[
"_",
- "__dirname",
- "__filename",
+ "_dispatchMessageFromObjC",
+ "_documentState",
+ "_doSend",
+ "_handleMessageFromObjC",
"_lastFocusTimeMark",
- "_onBackup",
"_options",
"_releaseNo",
"_xamzrequire",
@@ -12,48 +13,46 @@
"addDateQuery",
"alert",
"Analytics",
- "argv",
"atob",
"autoNumberingForMath",
"AWS",
"blur",
+ "bridge",
"btoa",
"caches",
+ "callHandler",
"cancelAnimationFrame",
"cancelIdleCallback",
"cancelSmartSchedule",
"captureEvents",
- "chrome",
- "clearImmediate",
"clearInterval",
"clearTimeout",
- "ClientCommand",
"clientHandlerOnPresentationMoved",
"clientInformation",
"close",
"closed",
"CodeMirror",
"confirm",
- "cookieStore",
"cppHook",
"createImageBitmap",
- "credentialless",
"crossOriginIsolated",
"crypto",
"customElements",
"debugMode",
+ "defaultstatus",
+ "defaultStatus",
"defferSelectionUpdateTimer",
"define",
"devicePixelRatio",
"Diagram",
- "dirname",
- "doApplyRename",
+ "dispatchMessagesWithTimeoutSafety",
"document",
"DOMPurify",
"editor",
"EmojiSearchMap",
+ "event",
+ "export",
"exports",
- "external",
"failImgCache",
"fastdom",
"fastdomPromised",
@@ -68,9 +67,7 @@
"getComputedStyle",
"getMarkdown",
"getPage",
- "getScreenDetails",
"getSelection",
- "global",
"globalExp",
"globalMod",
"globalReq",
@@ -86,11 +83,10 @@
"innerHeight",
"innerWidth",
"isInputComponent",
- "isOnWindowHtml",
"isSecureContext",
+ "isWk",
"jQuery",
"JSBridge",
- "launchQueue",
"length",
"loadedImgCache",
"loadedWebview",
@@ -102,33 +98,30 @@
"MathJax",
"mathJaxTags",
"mathPackages",
+ "maxSearchPanel",
"menubar",
"mermaid",
"mermaid-mindmap",
"mermaidAPI",
+ "messageHandlers",
"mode",
"module",
"moveBy",
"moveImageQueue",
"moveTo",
"name",
- "navigation",
"navigator",
"NFile",
"NodeDef",
+ "offscreenBuffering",
"onabort",
"onafterprint",
+ "onanimationcancel",
"onanimationend",
"onanimationiteration",
"onanimationstart",
- "onappinstalled",
- "onauxclick",
- "onbeforeinput",
- "onbeforeinstallprompt",
- "onbeforematch",
"onbeforeprint",
"onbeforeunload",
- "onbeforexrselect",
"onblur",
"oncancel",
"oncanplay",
@@ -136,15 +129,11 @@
"onchange",
"onclick",
"onclose",
- "oncontentvisibilityautostatechange",
- "oncontextlost",
"oncontextmenu",
- "oncontextrestored",
+ "oncopy",
"oncuechange",
+ "oncut",
"ondblclick",
- "ondevicemotion",
- "ondeviceorientation",
- "ondeviceorientationabsolute",
"ondrag",
"ondragend",
"ondragenter",
@@ -158,6 +147,8 @@
"onerror",
"onfocus",
"onformdata",
+ "ongamepadconnected",
+ "ongamepaddisconnected",
"ongotpointercapture",
"onhashchange",
"onImageErrorFunc",
@@ -188,6 +179,7 @@
"ononline",
"onpagehide",
"onpageshow",
+ "onpaste",
"onpause",
"onplay",
"onplaying",
@@ -198,7 +190,6 @@
"onpointermove",
"onpointerout",
"onpointerover",
- "onpointerrawupdate",
"onpointerup",
"onpopstate",
"onPowerChange",
@@ -208,7 +199,6 @@
"onreset",
"onresize",
"onscroll",
- "onsearch",
"onsecuritypolicyviolation",
"onseeked",
"onseeking",
@@ -238,60 +228,37 @@
"onWindowBlur",
"onWindowFocusForMac",
"onWindowFocusForNode",
- "onWindowResignForNode",
"open",
- "openDatabase",
"opener",
"origin",
- "originAgentCluster",
"outerHeight",
"outerWidth",
"pageXOffset",
"pageYOffset",
"parent",
"parse",
- "PDF_ArraySkip",
- "PDF_CommnetSkip",
- "PDF_ConvertObjectPos",
- "PDF_DictionarySkip",
- "PDF_GetDateTime_Now",
- "PDF_GetMediaBoxRect",
- "PDF_GetString",
- "PDF_mmToPts",
- "PDF_NameSkip",
- "PDF_OverlappingCut",
- "PDF_PtsTomm",
- "PDF_RectToHeight",
- "PDF_RectToWidth",
- "PDF_RGB",
- "PDF_SeekPos",
- "PDF_StrToFloatDef",
- "PDF_StrToIntDef",
- "PDF_TextSkip",
- "PDF_TopLineSkip",
- "PDFLib",
"performance",
"personalbar",
"postMessage",
"print",
"prompt",
- "queryLocalFonts",
"queueMicrotask",
"Raphael",
+ "registerHandler",
"releaseCaptureWin_",
"releaseEvents",
"remoteOnLoad",
"removeLastModifyQuery",
"Reporter",
"reportError",
- "reqnode",
"requestAnimationFrame",
"requestIdleCallback",
"requestSmartSchedule",
"require",
+ "res",
"resizeBy",
"resizeTo",
- "scheduler",
+ "responseCallbacks",
"screen",
"screenLeft",
"screenTop",
@@ -304,63 +271,38 @@
"scrollX",
"scrollY",
"self",
+ "sendMessageQueue",
"sessionStorage",
"setAttributeOnlyNeeded",
- "setImmediate",
"setInterval",
"setTimeout",
"setWritingContent",
"showDialog",
- "showDirectoryPicker",
+ "showModalDialog",
"showNotification",
- "showOpenFilePicker",
- "showSaveFilePicker",
"speechSynthesis",
"State",
"status",
"statusbar",
"stop",
"structuredClone",
- "styleMedia",
"svgCache",
- "TColor",
- "TFileStream",
- "TMemoryStream",
"toolbar",
"top",
- "TPDFAnalyst",
- "TPDFCode",
- "TPDFCombine",
- "TPDFDeletePage",
- "TPDFDocInfo",
- "TPDFDocView",
- "TPDFInfoMaker",
- "TPDFKnife",
- "TPDFNode",
- "TPDFNodeList",
- "TPDFObjMemManager",
- "TPDFOpenAction",
- "TPDFOpenActionType",
- "TPDFOutLineMaker",
- "TPDFOutLineManager",
- "TPDFPageLayout",
- "TPDFPageMode",
- "TPDFParser",
- "TPDFRotatePage",
- "TPDFViewerPreferences",
- "TReadStream",
- "TRect",
- "trustedTypes",
"turnOnIframeRefreshTimer",
"typoraOptionPrefix",
+ "uniqueId",
"uploadImageQueue",
"videoOnError",
"visualViewport",
"webkitCancelAnimationFrame",
+ "webkitCancelRequestAnimationFrame",
+ "webkitConvertPointFromNodeToPage",
+ "webkitConvertPointFromPageToNode",
+ "webkitIndexedDB",
"webkitRequestAnimationFrame",
- "webkitRequestFileSystem",
- "webkitResolveLocalFileSystemURL",
- "WebView",
+ "WebViewJavascriptBridge",
"window",
+ "winSearchPanel",
"words"
]
再看看 Windows Typora 里的 global
和 window
好像是没有区别的。通过 Object.keys(window).some(x => !Object.keys(global).includes(x))
检验后得到 false
表明这两个对象里的 keys 都一样
![image](https://private-user-images.githubusercontent.com/14329786/259942111-94f2082e-5097-4a4f-bb83-5b1991bc2d6b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjExOTgyMjMsIm5iZiI6MTcyMTE5NzkyMywicGF0aCI6Ii8xNDMyOTc4Ni8yNTk5NDIxMTEtOTRmMjA4MmUtNTA5Ny00YTRmLWJiODMtNWIxOTkxYmMyZDZiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE3VDA2MzIwM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFlMTBhN2U3ZDA1YzU2ZGM3MTE3MzY5YjUxZTc5YWM4ZThmMjBlMjYxZmQ4MjFlZmQxM2Y1MDc2MTdkNWY5OTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.i7xw05uZFpEKcWWFkGWrroZCwzG_eYWKovDGJTKUVWQ)
因此针对 Mac 上 global
缺失的问题,应该可以直接用 window
来替代
from typora_plugin.
提供一个思路,macOS 下暴露了一个全局函数 bridge.callHandler
,在 macOS 下 Typora 的大部分操作都是通过它进行的。其中 "controller.runCommand"
可以用于调用 Shell.
/**
* 运行 Shell 命令(仅在 macOS 下有效)
*/
const runShellCommand = (command, options) => {
const { cwd } = options ?? {};
return new Promise((resolve, reject) => {
window.bridge.callHandler(
"controller.runCommand",
{ args: command, ...(cwd ? { cwd } : {}) },
([success, stdout, stderr, command]) => {
if (success) resolve(stdout);
else reject(stderr);
},
);
});
};
const nodeVersion = await runShellCommand("node -v");
如果有一些 Node 库实在没法 Polyfill,可以要求用户安装 Node,然后通过命令行调用 Node,或者后台通过命令行调用 Node 起个服务器,用 WebSocket 去通信😂.
目测兼容 macOS 的工作量很大。如果有人感兴趣可以照这个思路做下去。
另外在 macOS 下模块问题肯定没办法解决,Typora for mac 是不支持 CommonJS 的 require 的,预计要打包成 iife 才能正常使用。我有个项目采用了这种思路以兼容 Typora for macOS,用 Rollup 把项目打包成 iife 单文件,可以参考一下里边的思路:https://github.com/Snowfly-T/typora-copilot
from typora_plugin.
- Typora 本身就不支持插件功能,这个项目是我通过各种黑魔法实现的,您使用搜索引擎去搜肯定没结果。
- 我没有 mac,故没有测试 mac。不过理论上也是能用于 mac。我个人也希望您能帮我测试一下 mac 的使用方式。
具体步骤和 windows 大同小异:
- 定位到 /Applications/Typora.app/Contents/Resources/TypeMark
- 在此目录粘贴 plugin 目录
- 修改此目录下的 index.html
注: 这里的标注写错了: index.js -> index.html
重启 Typora。
点击鼠标右键,弹出右键菜单栏,如果能看到【启动插件】栏目,说明一切顺利。
如果上面的操作不行,麻烦【第三步】换个位置粘贴(还是在 index.html。当然,之前添加的内容需要删除):
如果可以,请帮忙反馈一下。
from typora_plugin.
@obgnail
感谢回复!测试了一下,还是不行,估计mac版本的是不支持做这样的修改以使用插件的,目前打算在win下继续用了,很喜欢这个插件!
from typora_plugin.
尝试了在 index.html 里插入代码改变样式,是生效的,所以是可以改的
<script type="text/javascript" defer>
setTimeout(() => {
const plains = [...document.getElementsByClassName('md-plain')]
plains.map(x => x.style.color = 'red')
}, 1000)
</script>
只是现有的插件代码与 Mac Typora 所用的 WebKit 不兼容,特别是用到了 NodeJS 的库的相关代码,部分插件在小修的情况下应该是可以用的。
const Package = {
Path: reqnode("path"),
Fs: reqnode("fs"),
ChildProcess: reqnode('child_process'),
};
目前我对 collapse_paragraph
比较感兴趣,周末看看能不能写出来一版 Mac 上可以用的。
from typora_plugin.
@willbchang
感谢反馈。
我这边没有环境。如果可以修复,麻烦看能不能提个 PR?
from typora_plugin.
目前是支持Mac端了么? @obgnail
from typora_plugin.
@obgnail 主力机器是mac,目前能支持了吗
from typora_plugin.
@obgnail 我试了下,Typora for Mac 似乎没有办法直接访问 Node API,它甚至有可能不基于 Node. Typora 官方仅提到了 Linux / Windows 版本基于 Electron,而未明确提及 Typora for Mac 使用的技术。在 Typora for Mac 的 Developer Tool 终端里,File.isNode
的值是 false
, process
也不存在,即使通过 window.process
也无法访问。Typora for Mac 可能采用了某种 macOS 原生开发的手段,然后嵌入了一个 WebView,并重新实现了一些系统级别的 API,而并没有采用 Node 提供的 API.
如果事情确实符合我的猜测的话,要兼容 macOS,reqnode
应该是直接没法用了。对于常见的 API 如 fs、path,有可能专门为其中的一些特定常用函数写个为 macOS 准备的兼容实现,但对于使用其他更复杂 Node API 的代码,估计就比较复杂了。用 require
组织模块可能也没法用了,可能需要使用一些 Bundle 工具把代码全部编译到一个 .js 文件里来绕过这个问题,或者重新为 macOS 实现一遍 CommonJS 标准😂
from typora_plugin.
期待mac +1
from typora_plugin.
我木有环境呀,咋整 😂
from typora_plugin.
喜欢这个插件,没有windows,同求 mac + 1
from typora_plugin.
我木有环境呀,咋整 😂
可以试试 https://github.com/sickcodes/Docker-OSX
from typora_plugin.
为此插件+1,希望尽早能够解决。
from typora_plugin.
+1,真心希望在 macOS 上也能用上这么强大的插件。
from typora_plugin.
+1,官方repo的增加vim mode的issue 16年就提出来了(typora/typora-issues#187) ,不知道为什么一直没解决...
from typora_plugin.
这里有个插件,可以在mac上使用,说不定可以借鉴。https://github.com/typora-community-plugin/typora-community-plugin。
本仓库这个,我安装失败了,无法使用 :)
from typora_plugin.
这里有个插件,可以在mac上使用,说不定可以借鉴。https://github.com/typora-community-plugin/typora-community-plugin。 本仓库这个,我安装失败了,无法使用 :)
好像 404 了?
from typora_plugin.
Related Issues (20)
- 只读模式的bug HOT 2
- 启停插件问题 HOT 5
- 正文区域点击鼠标右键,不显示右键菜单栏;但是插件的功能却能使用 HOT 9
- 建议:【升级插件】功能 HOT 4
- 【文件模版】:模板变量优化建议 HOT 4
- 【文件模版】:模板预览固定,不发生变化。 HOT 4
- callouts渲染异常 HOT 5
- 如何默认开启调试模式 HOT 1
- 能否在markmap中添加自定义字体的设置? HOT 2
- 代码块右上角工具优化 HOT 2
- 如何点标题即可修改标题等级 HOT 2
- 文件规范性检查的小方块不见了 HOT 8
- 自动编号功能问题 HOT 3
- timeline 问题反馈 HOT 8
- 按要求修改了快捷键配置文件,快捷键无效 HOT 5
- 请问,能否让命令行环境功能打开后就是位于typora当前工作文件夹 HOT 2
- 上传文章到CSDN,提示开始上传后就没动静了,实际上未上传成功 HOT 6
- 希望添加一款大纲目录插件 HOT 5
- 按钮和更新功能异常 HOT 1
- callouts问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typora_plugin.