obgnail / typora_plugin

Typora plugin. Feature enhancement tool | Typora 插件,功能增强工具
MIT License
1.82k stars 86 forks source link

在macos下有办法使用吗? #42

Closed JasonVei closed 2 months ago

JasonVei commented 1 year ago

Windows上是会用了,mac谷歌也没搜到有用的插件怎么安装的教程。主力还是用mac的,可以的话求指点一二

obgnail commented 1 year ago

@JasonVei

  1. Typora 本身就不支持插件功能,这个项目是我通过各种黑魔法实现的,您使用搜索引擎去搜肯定没结果。
  2. 我没有 mac,故没有测试 mac。不过理论上也是能用于 mac。我个人也希望您能帮我测试一下 mac 的使用方式

具体步骤和 windows 大同小异:

  1. 定位到 /Applications/Typora.app/Contents/Resources/TypeMark
  2. 在此目录粘贴 plugin 目录
  3. 修改此目录下的 index.html

Snipaste_2023-07-30_22-27-29

注: 这里的标注写错了: index.js -> index.html

修改 index.html Snipaste_2023-07-30_22-20-25

重启 Typora。 点击鼠标右键,弹出右键菜单栏,如果能看到【启动插件】栏目,说明一切顺利。


如果上面的操作不行,麻烦【第三步】换个位置粘贴(还是在 index.html。当然,之前添加的内容需要删除): Snipaste_2023-07-30_22-21-43

如果可以,请帮忙反馈一下。

JasonVei commented 1 year ago

@obgnail 感谢回复!测试了一下,还是不行,估计mac版本的是不支持做这样的修改以使用插件的,目前打算在win下继续用了,很喜欢这个插件! image image

willbchang commented 1 year ago

Typora 菜单栏可以开 Debug 模式

image

然后在编辑界面右键审查元素

image

可以看到 reqnodeglobal 没有被定义

image

而 Windows 下的 Typora 则有这两个对象

image

继续右键查找 function 定义可以发现 reqnode 的 file path 是 node:internal/modules/cjs/helpers, 是 NodeJS 相关的

image

Windows Typora 里的 global 的 keys 并和 Mac Typora 里的 window 的 keys 做对比

image

首先把两个数组分别通过 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 里的 globalwindow 好像是没有区别的。通过 Object.keys(window).some(x => !Object.keys(global).includes(x)) 检验后得到 false 表明这两个对象里的 keys 都一样

image

因此针对 Mac 上 global 缺失的问题,应该可以直接用 window 来替代

willbchang commented 1 year ago

尝试了在 index.html 里插入代码改变样式,是生效的,所以是可以改的

<script type="text/javascript" defer>
    setTimeout(() => {
        const plains = [...document.getElementsByClassName('md-plain')]
        plains.map(x => x.style.color = 'red')
    }, 1000)
</script>

image

只是现有的插件代码与 Mac Typora 所用的 WebKit 不兼容,特别是用到了 NodeJS 的库的相关代码,部分插件在小修的情况下应该是可以用的。

const Package = {
    Path: reqnode("path"),
    Fs: reqnode("fs"),
    ChildProcess: reqnode('child_process'),
};

目前我对 collapse_paragraph 比较感兴趣,周末看看能不能写出来一版 Mac 上可以用的。

obgnail commented 1 year ago

@willbchang 感谢反馈。 我这边没有环境。如果可以修复,麻烦看能不能提个 PR?

rainyInSeptember commented 1 year ago

目前是支持Mac端了么? @obgnail

xiaotu9639 commented 1 year ago

@obgnail 主力机器是mac,目前能支持了吗

Snowflyt commented 11 months ago

@obgnail 我试了下,Typora for Mac 似乎没有办法直接访问 Node API,它甚至有可能不基于 Node. Typora 官方仅提到了 Linux / Windows 版本基于 Electron,而未明确提及 Typora for Mac 使用的技术。在 Typora for Mac 的 Developer Tool 终端里,File.isNode 的值是 falseprocess 也不存在,即使通过 window.process 也无法访问。Typora for Mac 可能采用了某种 macOS 原生开发的手段,然后嵌入了一个 WebView,并重新实现了一些系统级别的 API,而并没有采用 Node 提供的 API.

如果事情确实符合我的猜测的话,要兼容 macOS,reqnode 应该是直接没法用了。对于常见的 API 如 fs、path,有可能专门为其中的一些特定常用函数写个为 macOS 准备的兼容实现,但对于使用其他更复杂 Node API 的代码,估计就比较复杂了。用 require 组织模块可能也没法用了,可能需要使用一些 Bundle 工具把代码全部编译到一个 .js 文件里来绕过这个问题,或者重新为 macOS 实现一遍 CommonJS 标准😂

magiceses commented 9 months ago

期待mac +1

Snowflyt commented 9 months ago

提供一个思路,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

obgnail commented 9 months ago

我木有环境呀,咋整 😂

neighborse commented 9 months ago

喜欢这个插件,没有windows,同求 mac + 1

immadolf commented 8 months ago

我木有环境呀,咋整 😂

可以试试 https://github.com/sickcodes/Docker-OSX

jackywu commented 8 months ago

为此插件+1,希望尽早能够解决。

chlorine3545 commented 8 months ago

+1,真心希望在 macOS 上也能用上这么强大的插件。

LeavesLei commented 7 months ago

+1,官方repo的增加vim mode的issue 16年就提出来了(https://github.com/typora/typora-issues/issues/187) ,不知道为什么一直没解决...

hurui3550 commented 4 months ago

这里有个插件,可以在mac上使用,说不定可以借鉴。https://github.com/typora-community-plugin/typora-community-plugin。 本仓库这个,我安装失败了,无法使用 :)

chlorine3545 commented 4 months ago

这里有个插件,可以在mac上使用,说不定可以借鉴。https://github.com/typora-community-plugin/typora-community-plugin。 本仓库这个,我安装失败了,无法使用 :)

好像 404 了?

immadolf commented 3 months ago

这里有个插件,可以在mac上使用,说不定可以借鉴。https://github.com/typora-community-plugin/typora-community-plugin。 本仓库这个,我安装失败了,无法使用 :)

好像 404 了?

上面的链接多了一个句号 @yoghurtlee-thu https://github.com/typora-community-plugin/typora-community-plugin/blob/main/README.zh-CN.md

obgnail commented 2 months ago

没有 Mac 环境,暂时关闭此 issue,后续如有解决方案再开启。

spongehah commented 1 month ago

期待MacOS + 1

liang104631 commented 1 month ago

+1

lllllmaster-lulllll commented 4 weeks ago

+1

coutureone commented 2 weeks ago

+1