Skip to content

Commit

Permalink
#标签自定义前缀条件
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Feb 9, 2023
1 parent fbc6e65 commit 317d2f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions addon/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pref("extensions.zotero.__addonRef__.tagsColumn.align", "left");
pref("extensions.zotero.__addonRef__.textTagsColumn.opacity", "0.5");
pref("extensions.zotero.__addonRef__.textTagsColumn.backgroundColor", "#fadec9");
pref("extensions.zotero.__addonRef__.textTagsColumn.textColor", "black");
pref("extensions.zotero.__addonRef__.textTagsColumn.prefix", "#");




Expand Down
17 changes: 15 additions & 2 deletions src/modules/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,18 @@ export default class Views {
}) as HTMLSpanElement
if (!data) { return tagSpans }
let tags: { tag: string, color: string }[] = JSON.parse(data)
const prefix = Zotero.Prefs.get(`${config.addonRef}.text${key}Column.prefix`) as string
tags.forEach(tagObj => {
let startIndex: number
let tag = tagObj.tag, color = tagObj.color
if (!tag.startsWith("#")) { return }
let tagSpan = getTagSpan(tag.slice(1), color)
if (prefix.startsWith("~~")) {
if (tag.startsWith(prefix.slice(2))) { return }
startIndex = 0
} else {
if (prefix != "" && !tag.startsWith(prefix)) { return }
startIndex = prefix.length
}
let tagSpan = getTagSpan(tag.slice(startIndex), color)
tagSpans.appendChild(tagSpan)
})
return tagSpans;
Expand All @@ -306,6 +314,11 @@ export default class Views {
this.patchSetting(
"Text" + key,
[
{
prefKey: `textTagsColumn.prefix`,
name: "Prefix",
type: "input"
},
{
prefKey: "textTagsColumn.textColor",
name: "Text",
Expand Down

0 comments on commit 317d2f3

Please sign in to comment.