Skip to content

Commit

Permalink
支持Zotero6
Browse files Browse the repository at this point in the history
1、支持Zotero6
(1)去掉图片压缩
(2)去掉笔记行间距
(3)去掉笔记段间距
(4)去掉更换笔记背景
2、默认卡模版的标题改为标题1
3、添加调整浮动窗口设置高度
4、添加批量建卡
5、添加笔记源代码
  • Loading branch information
018 committed Feb 22, 2022
1 parent 8042af8 commit 50017b3
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 47 deletions.
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ zotcard是Zotero的一个插件,它可以帮助你快速写卡片、或笔记

![默认卡片样式-默认](https://raw.githubusercontent.com/018/zotcard/main/image/default-style.png)

- 社交样式:[下载](https://raw.githubusercontent.com/018/zotcard/main/zotcardstyle/social.zotcardstyle) (「右键」-「链接存储为...」)
- 社交样式(仅支持Zotero5)[下载](https://raw.githubusercontent.com/018/zotcard/main/zotcardstyle/social.zotcardstyle) (「右键」-「链接存储为...」)

![默认卡片样式-社交样式](https://raw.githubusercontent.com/018/zotcard/main/image/social-style.png)

- 卡片样式:[下载](https://raw.githubusercontent.com/018/zotcard/main/zotcardstyle/card.zotcardstyle) (「右键」-「链接存储为...」)
- 卡片样式(仅支持Zotero5)[下载](https://raw.githubusercontent.com/018/zotcard/main/zotcardstyle/card.zotcardstyle) (「右键」-「链接存储为...」)

![默认卡片样式-卡片样式](https://raw.githubusercontent.com/018/zotcard/main/image/card-style.png)

- 便签样式:[下载](https://raw.githubusercontent.com/018/zotcard/main/zotcardstyle/memo.zotcardstyle) (「右键」-「链接存储为...」)
- 便签样式(仅支持Zotero5)[下载](https://raw.githubusercontent.com/018/zotcard/main/zotcardstyle/memo.zotcardstyle) (「右键」-「链接存储为...」)

![默认卡片样式-便签样式](https://raw.githubusercontent.com/018/zotcard/main/image/memo-style.png)

Expand Down Expand Up @@ -76,6 +76,8 @@ zotcard是Zotero的一个插件,它可以帮助你快速写卡片、或笔记

- `extensions.zotero.zotcard.general.visible`:短文卡显示

还可以支持批量建卡。
![批量建卡](https://raw.githubusercontent.com/018/zotcard/main/image/batchnewcard.png)


## 自定义卡
Expand Down Expand Up @@ -175,7 +177,7 @@ zotcard是Zotero的一个插件,它可以帮助你快速写卡片、或笔记

**调整浮动编辑窗口**

在通过**打开浮动编辑窗口**打开的浮动编辑窗口,默认会堆一块。通过此功能可以设置显示在屏幕上一行多少个,平铺在屏幕上。
在通过**打开浮动编辑窗口**打开的浮动编辑窗口,默认会堆一块。通过此功能可以设置显示在屏幕上一行多少个和高度,平铺在屏幕上。

**关闭所选浮动编辑窗口**

Expand All @@ -185,10 +187,20 @@ zotcard是Zotero的一个插件,它可以帮助你快速写卡片、或笔记

此功能关闭所有浮动编辑窗口。

**压缩图片**
**压缩图片(仅支持Zotero5)**

此功能调用tinypng接口,设置api key即可图片压缩,还可多次压缩。为笔记压缩,尽可能可同步。可以设置`zotcard.config.compress_with_width_and_height`为true,跟随宽高进行压缩,属于高度压缩会影响图片质量。

**打印**

此功能可调整格式然后直接打印。

**笔记源代码**

由于Zotero6去掉了查看源代码,此功能可以编辑笔记的源代码。




## 分类操作

Expand All @@ -206,12 +218,16 @@ zotcard是Zotero的一个插件,它可以帮助你快速写卡片、或笔记

<img src="https://raw.githubusercontent.com/018/zotcard/main/image/card-operation.png" alt="卡片操作" width="300"/>

## 笔记行间距
## 笔记行间距(仅支持Zotero5)

<img src="https://raw.githubusercontent.com/018/zotcard/main/image/line-spacing.png" alt="笔记行间距" width="300"/>

支持设置笔记行间距。

## 笔记段间距(仅支持Zotero5)

支持设置笔记段间距。


## 选项

Expand All @@ -237,7 +253,7 @@ zotcard是Zotero的一个插件,它可以帮助你快速写卡片、或笔记

作者为你提供了三种默认卡片样式:默认、社交和卡片。请参考上文图片,根据喜好进行下载,然后通过此功能进行替换。

**笔记背景**
**笔记背景(仅支持Zotero5)**

你可以修改笔记的背景,这里设置之后会对所有笔记(卡片)的背景生效,目前预设了:

Expand Down
5 changes: 5 additions & 0 deletions chrome/content/adjust.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ Components.utils.import('resource://gre/modules/Services.jsm');
function onload () {
let column = Zotero.Prefs.get('zotcard.config.column_edt')
document.getElementById('column_edt').value = column || '4'
let height = Zotero.Prefs.get('zotcard.config.height_edt')
document.getElementById('height_edt').value = height || '300'
}

function ok () {
var column = document.getElementById('column_edt').value
Zotero.Prefs.set('zotcard.config.column_edt', column)
var height = document.getElementById('height_edt').value
Zotero.Prefs.set('zotcard.config.height_edt', height)

var width = window.screen.availWidth / column
var wm = Services.wm;
Expand All @@ -25,6 +29,7 @@ function ok () {
while (e.hasMoreElements()) {
var win = e.getNext()
win.outerWidth = width
win.outerHeight = height
if (w < window.screen.availWidth && h < window.screen.availHeight) {
win.moveTo(w, h)
}
Expand Down
3 changes: 3 additions & 0 deletions chrome/content/adjust.xul
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
<groupbox orient="vertical">
<label value="&zotero.zotcard.adjust.column.label;"/>
<textbox id="column_edt" flex="1"/>

<label value="&zotero.zotcard.adjust.height.label;"/>
<textbox id="height_edt" flex="1"/>
</groupbox>
</dialog>
48 changes: 48 additions & 0 deletions chrome/content/batchnewcard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Copyright 2021 018.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';
/* global window, document, Components */
/* global Zotero, ZoteroPane, ZOTERO_CONFIG */
Components.utils.import('resource://gre/modules/Services.jsm');

var io = window.arguments && window.arguments.length > 0 ? window.arguments[0] : { dataIn: [] }

io = Object.assign(io, { dataOut: false })

function onload () {
io.dataIn.items.forEach((element, index) => {
let label = document.createElement('label')
label.setAttribute('value', `${element.label}数量:`)
document.getElementById('groupbox').appendChild(label)
let textbox = document.createElement('textbox')
textbox.setAttribute('id', element.id)
textbox.setAttribute('item-index', index)
textbox.setAttribute('value', element.value || '')
textbox.setAttribute('flex', '1')
document.getElementById('groupbox').appendChild(textbox)
})
window.sizeToContent()
}

function ok () {
var dataOut = []
document.querySelectorAll('#groupbox textbox').forEach(textbox => {
if (textbox.value.length > 0) {
if (textbox.value.match(/\D/g)) {
Zotero.ZotCard.Utils.warning('请正确输入数量。')
textbox.focus()
} else {
let index = parseInt(textbox.getAttribute('item-index'))
io.dataIn.items[index].value = parseInt(textbox.value)
dataOut.push(io.dataIn.items[index])
}
}
})
if (dataOut) {
io.dataOut = dataOut
window.close()
}
}
31 changes: 31 additions & 0 deletions chrome/content/batchnewcard.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>

<!--
/* Copyright 2021 018.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-->

<?xml-stylesheet href="chrome://zoterozotcard/skin/dialog.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://zoterozotcard/locale/overlay.dtd">

<dialog
id="zotcard-batchnewcard"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
orient="vertical"
buttons="accept,cancel"
ondialogaccept="ok();return false;"
ondialogcancel="window.close();return true;"
onload="onload()"
flex="1"
title="&zotero.zotcard.batchnewcard.title;"
width="200"
height="100">

<script src="chrome://zotero/content/include.js"/>
<script src="chrome://zoterozotcard/content/batchnewcard.js"/>

<groupbox id="groupbox" orient="vertical">
</groupbox>
</dialog>
33 changes: 33 additions & 0 deletions chrome/content/notesourcecode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright 2021 018.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';
/* global window, document, Components */
/* global Zotero, ZoteroPane, ZOTERO_CONFIG */
Components.utils.import('resource://gre/modules/Services.jsm');

var io = window.arguments && window.arguments.length > 0 ? window.arguments[0] : { dataIn: [] }

io = Object.assign(io, { dataOut: false })
var id = io.dataIn
let note = Zotero.Items.get(id)

function onload () {
if (note) {
document.getElementById('textbox').value = note.getNote()
window.sizeToContent()
} else {
Zotero.ZotCard.Utils.warning('错误的笔记id。')
window.close()
}
}

async function ok () {
note.setNote(document.getElementById('textbox').value)
await note.saveTx()

io.dataOut = true
window.close()
}
32 changes: 32 additions & 0 deletions chrome/content/notesourcecode.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>

<!--
/* Copyright 2021 018.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-->

<?xml-stylesheet href="chrome://zoterozotcard/skin/dialog.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://zoterozotcard/locale/overlay.dtd">

<dialog
id="zotcard-batchnewcard"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
orient="vertical"
buttons="accept,cancel"
ondialogaccept="ok();return false;"
ondialogcancel="window.close();return true;"
onload="onload()"
flex="1"
title="&zotero.zotcard.batchnewcard.title;"
width="800"
height="600">

<script src="chrome://zotero/content/include.js"/>
<script src="chrome://zoterozotcard/content/notesourcecode.js"/>

<groupbox id="groupbox" orient="vertical">
<textbox id="textbox" multiline="true" flex="1" height="680" />
</groupbox>
</dialog>
8 changes: 8 additions & 0 deletions chrome/content/overlay.xul
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
label="&zotero.zotcard.closeall.label;"
oncommand="Zotero.ZotCard.closeall()"/>
<menuseparator
id="zotero-itemmenu-zotcard-compressimg-separator"
class="dynamic-menu only-note" />
<menuitem
id="zotero-itemmenu-zotcard-compressimg"
Expand All @@ -120,6 +121,13 @@
class="dynamic-menu only-note only-simple"
label="&zotero.zotcard.print.label;"
oncommand="Zotero.ZotCard.print()"/>
<menuseparator
class="dynamic-menu only-note only-simple" />
<menuitem
id="zotero-itemmenu-zotcard-notesourcecode"
class="dynamic-menu only-note only-simple"
label="&zotero.zotcard.notesourcecode.label;"
oncommand="Zotero.ZotCard.notesourcecode()"/>
</menupopup>
</menu>
</popup>
Expand Down
4 changes: 2 additions & 2 deletions chrome/content/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function refreshCard (id) {
let cardContentAll = cardDiv.querySelector(`.card-all`)
cardContentAll.innerHTML = matchNote(item.getNote())
let cardTitle = cardDiv.querySelector(`.card-title`)
cardTitle.innerHTML = `<h3 class="linenowrap" style="text-align: center;">${item.getNoteTitle()}</h3>`
cardTitle.innerHTML = `<h1 class="linenowrap" style="text-align: center;">${item.getNoteTitle()}</h1>`

let index = indexOfCards(id)
cards[index] = Zotero.ZotCard.Utils.toCardItem(item)
Expand Down Expand Up @@ -669,7 +669,7 @@ function createCard (card, index) {

let cardTitle = document.createElement('div')
cardTitle.setAttribute('class', 'card-title')
cardTitle.innerHTML = `<h3 class="linenowrap" style="text-align: center;">${card.title}</h3>`
cardTitle.innerHTML = `<h1 class="linenowrap" style="text-align: center;">${card.title}</h1>`
cardTitle.hidden = extra[card.id].expand
cardContent.appendChild(cardTitle)
cardDiv.appendChild(cardContent)
Expand Down
8 changes: 7 additions & 1 deletion chrome/content/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Zotero.getMainWindow().Zotero.ZotCard.Utils.confirm = function (message) {
return ps.confirm(null, Zotero.getString('general.warning'), message)
}

Zotero.getMainWindow().Zotero.ZotCard.Utils.version = function () {
return parseInt(Zotero.version.substr(0, 1))
}



Zotero.getMainWindow().Zotero.ZotCard.Utils.getParam = function (url, name) {
if (!url) return ''

Expand Down Expand Up @@ -250,7 +256,7 @@ Zotero.getMainWindow().Zotero.ZotCard.Utils.formatDate = function (date, format)

Zotero.getMainWindow().Zotero.ZotCard.Utils.hangzi = function (html) {
var content = Zotero.ZotCard.Utils.htmlToText(html)
Zotero.debug(`content: ${content}`)
Zotero.debug(`zotcard@content: ${content}`)
let m1 = content.match(/[\u4E00-\u9FA5]/g)
let m2 = content.match(/[\u9FA6-\u9FEF]/g)
let m3 = content.match(/\w+/g)
Expand Down
Loading

0 comments on commit 50017b3

Please sign in to comment.