希望有开发经验的大佬搞一个适配WPS的Zotero插件
lon91ong opened this issue · comments
不清楚为什么WPS官方论坛关闭了, 找到不反馈问题的渠道
目前WPS和MS Office的功能基本上完全看齐了, 甚至VBA脚本都很少需要改动就能完美运行.
只有插件这块儿适配的不太好, Zotero的Word插件可以加载到WPS中,如下图
在插入引用时可以成功调用Zotero, 但是最后一步总是报错
目前能在WPS中使用的文献管理工具只有NoteExpress, 使用体验实在是一言难尽
希望开发大佬出手适配一下, 可能有用的参考在WPS下开发JS插件说明
这个目前超纲了,我也是刚学JS没多久的新人。
造一个 Zotero WPS Integration,确实超纲。
Zotero Word for Windows Integration 是一个跟 JavaScript 几乎没有关系的古董。
Zotero.dotm
是用 VBA 写的 Word Template,仅实现 Ribbon 菜单以及从 Word 发消息到 Zotero。
而主体是一个用 Visual C++/MFC 写的库,调用 Word Interop API 来实现引文管理功能。
这导致它不能在 WPS 上正常工作。
如果要支持 WPS,则需调用 WPS 文字 API。文档在 WPS 开放平台 > 开发文档 > WPS 客户端开发 > WPS 基础接口 > 文字 API 参考。
简单翻了一下 Zotero Connector 以及其他 Zotero integration plugin,感觉 WPS 加载项确实可以实现相关功能。
从 Zotero 拉取数据是大头。
-
Zotero 桌面应用有 Zotero Connector Server。它自带一套 RPC 风格的 HTTP Citing Protocol。
-
Better BibTeX for Zotero (BBT) (GitHub) 示范了如何扩展 Connector Server。不过,不太清楚 Zotero 5.0.71 的更改
Additional protections to prevent visited webpages from triggering actions in Zotero plugins
会产生什么阻碍。
目前就找到这么多。
如果哪位有兴趣,可以试一下。
如果不行,那么只好也走 OLE Automation。搜到几篇古老的文章,或许可参考:
造一个 Zotero WPS Integration,确实超纲。
Zotero Word for Windows Integration 是一个跟 JavaScript 几乎没有关系的古董。
Zotero.dotm
是用 VBA 写的 Word Template,仅实现 Ribbon 菜单以及从 Word 发消息到 Zotero。而主体是一个用 Visual C++/MFC 写的库,调用 Word Interop API 来实现引文管理功能。
从 Zotero 拉取数据是大头。
从 Zotero 拉取数据是大头
, 这个大头
感觉不太准确, 从Zotero取数据毕竟VBA都已经实现了, 直接照着用JS重写即可, 真正的大头
应该是用JS解析数据并实现用 Visual C++/MFC 写的库
的功能
在WPS已经实现了JS宏和JS加载项的前提下, 上述功能的实现不能说是"轻而易举", 起码够得上"水到渠成"
需要的是 或者独立代发经验丰富的大佬动手 或者有项目开发经验的大佬规划和领导...
以上, 最后一段可能有点"想当然"的意味, 请多见谅!
刚刚试着看看Zotero.dotm中的VBA代码, 用Word2016打开提示"功能锁定"-"工程不可查看", 换WPS2019打开, 直接随便看
注明了使用GNU共享协议, 有两个模块, Zotero和ZoteroRibbon, 代码超简单:
' Zotero功能的精华
Sub ZoteroCommand(cmd As String, bringToFront As Boolean)
Dim cds As COPYDATASTRUCT
#If VBA7 Then
Dim ThWnd As LongPtr
#Else
Dim ThWnd As Long
#End If
Dim a$, args$, name$
Dim i As Long
Dim ignore As Long
Dim sBuffer$
Dim lLength As Long
Dim buf() As Byte
' Try various names for Firefox
Dim appNames(5)
appNames(1) = "Zotero"
appNames(2) = "Firefox"
appNames(3) = "Browser"
appNames(4) = "firefox-dev"
For i = 1 To 4
ThWnd = FindWindow(appNames(i) & "MessageWindow", vbNullString)
If ThWnd <> 0 Then
Exit For
End If
Next
If ThWnd = 0 Then
MsgBox ("Word could not communicate with Zotero. Please ensure Zotero is running and try again. If this problem persists, see https://www.zotero.org/support/word_processor_plugin_troubleshooting")
Exit Sub
End If
' Allow Firefox to bring a window to the front
If bringToFront Then Call SetForegroundWindow(ThWnd)
' Get path to active document
If ActiveDocument.Path <> "" Then
name$ = ActiveDocument.Path & Application.PathSeparator & ActiveDocument.name
Else
name$ = ActiveDocument.name
End If
' Set up command line arguments
name$ = Replace(name$, """", """""")
args$ = "-silent -ZoteroIntegrationAgent WinWord -ZoteroIntegrationCommand " & cmd & " -ZoteroIntegrationDocument """ & name$ & """"
a$ = "firefox.exe " & args$ & Chr$(0) & "C:\"
' Do some UTF-8 magic
lLength = WideCharToMultiByte(CP_UTF8, 0, StrPtr(a$), -1, ByVal 0, 0, 0, 0)
ReDim buf(lLength) As Byte
Call WideCharToMultiByte(CP_UTF8, 0, StrPtr(a$), -1, buf(1), lLength, 0, 0)
' Send message to Firefox
cds.dwData = 1
cds.cbData = lLength
cds.lpData = VarPtr(buf(1))
i = SendMessage(ThWnd, WM_COPYDATA, 0, cds)
' Handle error
If Err.LastDllError = 5 Then
If Dir("C:\Program Files\Mozilla Firefox\firefox.exe") <> "" Then
Call Shell("""C:\Program Files\Mozilla Firefox\firefox.exe"" " & args$, vbNormalFocus)
ElseIf Dir("C:\Program Files (x86)\Mozilla Firefox\firefox.exe") <> "" Then
Call Shell("""C:\Program Files (x86)\Mozilla Firefox\firefox.exe"" " & args$, vbNormalFocus)
End If
End If
End Sub
用JS重写的话, 就卡在了FindWindow
这种系统API的操作函数, 需要用另外的工具实现
Zotero Word for Windows Integration 的那个 Zotero.dotm
仅仅是个 Ribbon,点一下就向 Zotero 发个指令,其他什么功能都没有。
所有逻辑都是在 Zotero 中实现的。
我理解的它的架构:
+------------------+ +------------------+
| Microsoft Word | | Zotero |
| | | |
| +-------------+ | | +-------------+ |
| | Zotero.dotm |-------->| Citation | |
| +-------------+ | | | handler | |
| | | +-------------+ |
| | | ↕ |
| +-------------+ | | +-------------+ |
| | Document | | | | Glue JS | |
| +-------------+ | | +-------------+ |
| ↕ | | ↕ |
| +-------------+ | | +-------------+ |
| | Interop API |<------->| Native | |
| +-------------+ | | +-------------+ |
| | | |
+------------------+ +------------------+
"Zotero" pulls from and pushes to "Microsoft Word".
而做 WPS Integration,我认为应当采取这种方案:
+------------------+ +------------------+
| WPS | | Zotero |
| | | |
| +-------------+ | | +-------------+ |
| | Ribbon | | | | Citation | |
| | / | | | | handler | |
| | TaskPane | | | +-------------+ |
| +-------------+ | | ↕ |
| ↑ | | +-------------+ |
| | | | | Custom | |
| ↓ | | | endpoint | |
| +-------------+ | | | handler | |
| | Plugin host |<---+ | +-------------+ |
| +-------------+ | | | ↕ |
| ↕ | | | +-------------+ |
| +-------------+ | +--->| Connector | |
| | Document | | | | server | |
| +-------------+ | | +-------------+ |
| | | |
+------------------+ +------------------+
"WPS" pulls from "Zotero".
@Lemmingh 是我理解的肤浅了, 刚刚用WPS打开Zotero.dotm查看源代码, 确实如你所言
但是用这种方案的话, 许多Zotero已经实现的工作必须都用JS加载项重做了, 比如: 丰富的引文格式, 工作量不是一般的大
丰富的引文格式
关键在 Custom endpoint handler 能做什么。
上面提到了 BBT,它在 Connector Server 上实现了许多 endpoint。按这个思路,利用 Zotero plugin,仍然可以让 Zotero 完成排版,最后 WPS 加载项这边拉取呈现和 metadata,再嵌入文档。(在 Word 上,是 Zotero 走 IA 把这些东西写进文档。)
但我不清楚 Zotero 5.0.71 增加的安全限制是怎么回事。如果是测 UA,可以想办法绕过。
-
Electron 似乎不受影响。因为一个基于 BBT 开发的产品 (https://github.com/mblode/vscode-zotero/blob/0a0298cf1b6c0f3685d74a67263d3dcbe69735b8/extension.js#L8) 仍能工作。
-
根据文档,WPS plugin host 是个 Chromium,那么,网络通信能用 XHR 或者 Fetch,我不知道它会被 Zotero 当成什么东西。Chrome 好像有个什么毛病,我想不起来。
目前有同学向wps发邮件,希望开发插件。wps也回应了,希望能早点出来。如果着急可以一起发邮件催一催
有同学收到WPS的消息是他们已经提供文档了,不负责开发🙃
建了一个zotero-wps插件开发项目,感兴趣的同学一起去那边交流吧,争取早日搞定zotero的wps插件。zotero-wps插件开发的交流QQ群:1029775161,https://github.com/l0o0/Zotero-WPS