Skip to content

Commit

Permalink
fix: #1
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Dec 30, 2023
1 parent 58ad295 commit dd4b858
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 78 deletions.
104 changes: 28 additions & 76 deletions addon/chrome/content/preferences.xhtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<linkset>
<html:link rel="localization" href="__addonRef__-preferences.ftl" />
</linkset>
<vbox
id="zotero-prefpane-__addonRef__"
onload="Zotero.__addonInstance__.hooks.onPrefsEvent('load', {window})"
>
<vbox id="zotero-prefpane-__addonRef__" onload="Zotero.__addonInstance__.hooks.onPrefsEvent('load', {window})">
<groupbox>
<label>
<html:h2 data-l10n-id="source-title"></html:h2>
Expand All @@ -14,14 +11,8 @@
<separator class="thin" />
<hbox align="center">
<label data-l10n-id="directory"></label>
<html:input
id="source-dir"
type="text"
readonly="true"
flex="1"
preference="extensions.zotero.__addonRef__.sourceDir"
style="background: none; border: none"
>
<html:input id="source-dir" type="text" readonly="true" flex="1"
preference="extensions.zotero.__addonRef__.sourceDir" style="background: none; border: none">
</html:input>
<button id="choose-source-dir" data-l10n-id="choose"></button>
</hbox>
Expand All @@ -36,11 +27,7 @@
<separator class="thin" />
<hbox align="center">
<label data-l10n-id="attach-type-start"></label>
<menulist
native="true"
id="attach-type"
preference="extensions.zotero.__addonRef__.attachType"
>
<menulist native="true" id="attach-type" preference="extensions.zotero.__addonRef__.attachType">
<menupopup>
<menuitem data-l10n-id="importing" value="importing" />
<menuitem data-l10n-id="linking" value="linking" />
Expand All @@ -59,14 +46,8 @@
<separator class="thin" />
<hbox align="center">
<label data-l10n-id="directory"></label>
<html:input
id="dest-dir"
type="text"
readonly="true"
flex="1"
preference="extensions.zotero.__addonRef__.destDir"
style="background: none; border: none"
>
<html:input id="dest-dir" type="text" readonly="true" flex="1"
preference="extensions.zotero.__addonRef__.destDir" style="background: none; border: none">
</html:input>
<button id="choose-dest-dir" data-l10n-id="choose"></button>
</hbox>
Expand All @@ -75,35 +56,25 @@

<hbox align="center">
<label data-l10n-id="subfolder"></label>
<html:input
id="subfolder-format"
type="text"
flex="1"
preference="extensions.zotero.__addonRef__.subfolderFormat"
>
<html:input id="subfolder-format" type="text" flex="1"
preference="extensions.zotero.__addonRef__.subfolderFormat">
</html:input>
</hbox>

<separator class="thin" />

<hbox align="center">
<label data-l10n-id="filename"></label>
<button
id="file-renaming-button"
data-l10n-id="preferences-file-renaming-customize-button"
<button id="file-renaming-button" data-l10n-id="preferences-file-renaming-customize-button"
data-search-strings="preferences-file-renaming-format-title, preferences-file-renaming-format-template"
oncommand="Zotero_Preferences.navigateToPane('zotero-subpane-file-renaming')"
></button>
oncommand="Zotero_Preferences.navigateToPane('zotero-subpane-file-renaming')"></button>
</hbox>

<separator class="thin" />

<label data-l10n-id="preferences-file-renaming-format-instructions-more">
<label
is="zotero-text-link"
href="https://www.zotero.org/support/file_renaming"
data-l10n-name="file-renaming-format-help-link"
></label>
<label is="zotero-text-link" href="https://www.zotero.org/support/file_renaming"
data-l10n-name="file-renaming-format-help-link"></label>
</label>
</vbox>
</groupbox>
Expand All @@ -112,16 +83,13 @@
<html:h2 data-l10n-id="other-title"></html:h2>
</label>
<vbox align="start">
<checkbox
native="true"
data-l10n-id="auto-rename"
preference="extensions.zotero.autoRenameFiles"
/>
<checkbox
native="true"
data-l10n-id="auto-move"
preference="extensions.zotero.__addonRef__.autoMove"
/>
<checkbox native="true" data-l10n-id="auto-rename" preference="extensions.zotero.autoRenameFiles" />
<checkbox native="true" data-l10n-id="auto-move" preference="extensions.zotero.__addonRef__.autoMove" />
<hbox align="center">
<label data-l10n-id="file-types"></label>
<html:input type="text" flex="1" preference="extensions.zotero.__addonRef__.fileTypes">
</html:input>
</hbox>
</vbox>
</groupbox>
<groupbox>
Expand All @@ -131,38 +99,22 @@
<vbox align="start">
<label data-l10n-id="about-intro"></label>
<separator class="thin" />
<label
style="margin-inline: 6px 5px; text-decoration: none"
is="zotero-text-link"
href="https://github.com/MuiseDestiny/zotero-attanger"
class="zotero-text-link"
>
<label style="margin-inline: 6px 5px; text-decoration: none" is="zotero-text-link"
href="https://github.com/MuiseDestiny/zotero-attanger" class="zotero-text-link">
⭐ Star it
</label>
<label
style="margin-inline: 6px 5px; text-decoration: none"
is="zotero-text-link"
href="https://github.com/MuiseDestiny"
class="zotero-text-link"
>
<label style="margin-inline: 6px 5px; text-decoration: none" is="zotero-text-link"
href="https://github.com/MuiseDestiny" class="zotero-text-link">
🔍 See author's Github
</label>
<label
style="margin-inline: 6px 5px; text-decoration: none"
is="zotero-text-link"
href="https://space.bilibili.com/13557814"
class="zotero-text-link"
>
<label style="margin-inline: 6px 5px; text-decoration: none" is="zotero-text-link"
href="https://space.bilibili.com/13557814" class="zotero-text-link">
📺 See author's Bilibli
</label>
<label
style="margin-inline: 6px 5px; text-decoration: none"
is="zotero-text-link"
href="https://gitee.com/MuiseDestiny/plugins"
class="zotero-text-link"
>
<label style="margin-inline: 6px 5px; text-decoration: none" is="zotero-text-link"
href="https://gitee.com/MuiseDestiny/plugins" class="zotero-text-link">
🎊 See Pro plugins
</label>
</vbox>
</groupbox>
</vbox>
</vbox>
1 change: 1 addition & 0 deletions addon/locale/en-US/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ auto-rename =
.label = Automatically Rename Added Attachments
auto-move =
.label = Automatically Move Added Attachments
file-types = Types of Attachments for Automatic Renaming/Moving (separated by ',')
about-title = About
about-intro = 🌠 Happy New Year! Attanger is an abbreviation for Attachment Manager, and this project heavily references the ZotFile plugin of Zotero version 6.
1 change: 1 addition & 0 deletions addon/locale/zh-CN/preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ auto-rename =
.label = 自动重命名添加的附件
auto-move =
.label = 自动移动添加的附件
file-types = 自动重命名/移动的附件类型(用','隔开)
about-title = 关于
about-intro = 🌠 新年快乐!Attanger 是 Attachment Manager 的缩写,本项目大量参考了 Zotero 6 版本的 ZotFile 插件。
3 changes: 3 additions & 0 deletions addon/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ pref("__prefsPrefix__.subfolderFormat", `{{collection}}/{{year}}`);
pref("__prefsPrefix__.sourceDir", "");
pref("__prefsPrefix__.destDir", "");
pref("__prefsPrefix__.autoMove", true);
pref("__prefsPrefix__.move", "linking");
pref("__prefsPrefix__.fileTypes", "pdf,doc,docx,txt,rtf,djvu,epub");

19 changes: 17 additions & 2 deletions src/modules/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class Menu {
window.setTimeout(async () => {
await Promise.all(
atts.map((att: Zotero.Item) => {
if (!checkFileType(att)) { return }
if (Zotero.Prefs.get("autoRenameFiles")) {
renameFile(att);
}
Expand Down Expand Up @@ -470,8 +471,8 @@ function getCollectionPathsOfItem(item: Zotero.Item) {
}
return OS.Path.normalize(
getCollectionPath(collection.parentID) +
addon.data.folderSep +
collection.name,
addon.data.folderSep +
collection.name,
) as string;
};
try {
Expand All @@ -480,3 +481,17 @@ function getCollectionPathsOfItem(item: Zotero.Item) {
return item.getCollections().map(getCollectionPath).slice(0, 1)[0];
}
}


function checkFileType(attItem: Zotero.Item) {
const fileTypes = getPref("fileTypes") as string
if (!fileTypes) return true;
var pos = attItem.attachmentFilename.lastIndexOf("."),
fileType =
pos == -1 ? "" : attItem.attachmentFilename.substr(pos + 1).toLowerCase(),
regex = fileTypes
.toLowerCase()
.replace(/,/gi, "|");
// return value
return fileType.search(new RegExp(regex)) >= 0 ? true : false;
}

0 comments on commit dd4b858

Please sign in to comment.