Skip to content

Commit

Permalink
#118 默认添加zotero8种颜色,期刊标签支持自定义缩写简称
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Feb 12, 2023
1 parent 57934da commit 2d59c80
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 45 deletions.
8 changes: 5 additions & 3 deletions addon/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ pref("extensions.zotero.__addonRef__.IFColumn.info", false);


pref("extensions.zotero.__addonRef__.PublicationTagsColumn.fields", "sci, sciif5, eii");
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.opacity", "0.5");
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.rankColors", '#ff9999, #86dad1, #ffe78f, #ffd4a9, #cce5ff');
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.defaultColor", "#86dad1");
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.textColor", 'black');
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.sortBy", 'sci, -sciif');
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.map", "北大中文核心=北核, SCIIF=IF, SCIIF(5)=IF(5)");

pref("extensions.zotero.__addonRef__.PublicationTagsColumn.margin", "0.2");
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.padding", "0.5");
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.opacity", "0.5");



Expand All @@ -46,8 +48,8 @@ pref("extensions.zotero.__addonRef__.progressColumn.circle", true);

pref("extensions.zotero.__addonRef__.columnsViews", "[]");

pref("extensions.zotero.__addonRef__.annotationColors", '[["general.yellow","#ffd400"],["general.red","#ff6666"],["general.green","#5fb236"],["general.blue","#2ea8e5"],["general.purple","#a28ae5"]]');
pref("extensions.zotero.__addonRef__.annotationColorsGroups", '[["Untitled",[["general.yellow","#ffd400"],["general.red","#ff6666"],["general.green","#5fb236"],["general.blue","#2ea8e5"],["general.purple","#a28ae5"]]]]');
pref("extensions.zotero.__addonRef__.annotationColors", '[["general.yellow","#ffd400"],["general.red","#ff6666"],["general.green","#5fb236"],["general.blue","#2ea8e5"],["general.purple","#a28ae5"],["general.magenta","#e56eee"],["general.orange","#f19837"],["general.gray","#aaaaaa"]]');
pref("extensions.zotero.__addonRef__.annotationColorsGroups", '[["Untitled",[["general.yellow","#ffd400"],["general.red","#ff6666"],["general.green","#5fb236"],["general.blue","#2ea8e5"],["general.purple","#a28ae5"],["general.magenta","#e56eee"],["general.orange","#f19837"],["general.gray","#aaaaaa"]]]]');



Expand Down
56 changes: 27 additions & 29 deletions src/modules/easyscholar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const field2Info: any = {
sci(s: string) {
let rank;
let text = `SCI ${s}`
let key = "SCI", value = s;
if (s == "Q1") {
rank = 1
} else if (s == "Q2") {
Expand All @@ -11,11 +11,10 @@ const field2Info: any = {
} else if (s == "Q4") {
rank = 4
}
return {rank, text}

return { rank, key, value}
},
sciif(s: string) {
let text = `SCIIF ${s}`
let key = "SCIIF", value = s;
let number = Number(s);
let rank
if (number >= 10) {
Expand All @@ -29,11 +28,11 @@ const field2Info: any = {
} else if (number >= 0 && number < 1) {
rank = 5
}
return {rank, text}
return {rank, key, value}
},
sciif5(s: string) {
let number = parseFloat(s);
let text = `SCIIF(5) ${s}`
let key = "SCIIF(5)", value = s;
let rank
if (number >= 10) {
rank = 1
Expand All @@ -46,10 +45,10 @@ const field2Info: any = {
} else if (number >= 0 && number < 1) {
rank = 5
}
return {rank, text}
return { rank, key, value }
},
sciBase(s: string) {
let text = `SCI基础版 ${s}`
let key = "SCI基础版", value = s;
s = s.substring(s.length - 2);
let rank
if (s == "1区") {
Expand All @@ -61,10 +60,10 @@ const field2Info: any = {
} else if (s == "4区") {
rank = 4
}
return {rank, text}
return { rank, key, value }
},
sciUp(s: string) {
let text = `SCI升级版 ${s}`
let key = "SCI升级版", value = s;
s = s.substring(s.length - 2);
let rank
if (s == "1区") {
Expand All @@ -76,10 +75,10 @@ const field2Info: any = {
} else if (s == "4区") {
rank = 4
}
return {rank, text}
return {rank, key, value}
},
ssci(s: string) {
let text = `SSCI ${s}`
let key = "SSCI", value = s
let rank
if (s == "Q1") {
rank = 1
Expand All @@ -91,44 +90,43 @@ const field2Info: any = {
rank = 4
} else if (s == "SSCI") {
rank = 5
text = "SSCI";
}
return {rank, text}
return {rank, key, value}
},
eii(s: string) {
let text = "EI检索"
let key = "EI检索", value = "";
let rank = 2
return {rank, text}
return { rank, key, value: ""}
},
cssci(s: string) {
let text = s
let key = s, value = "";
let rank
if (s == "CSSCI") {
rank = 1
} else if (rank == "CSSCI扩展版") {
} else if (s == "CSSCI扩展版") {
rank = 2
}
return {rank, text}
return {rank, key, value}
},
nju(s: string) {
let text = `NJU ${s}`
let key = "NJU", value = s;
let rank
if (s == "超一流期刊" || s == "学科群一流期刊") {
rank = 1
} else if (rank == "A") {
} else if (s == "A") {
rank = 2
} else if (rank == "B") {
} else if (s == "B") {
rank = 3
}
return {rank, text}
return {rank, key, value}
},
pku(s: string) {
let text = "北大中文核心"
let key = "北大中文核心", value = ""
let rank = 1
return { rank, text }
return { rank, key, value }
},
xju(s: string) {
let text = `XJU ${s}`
let key = "XJU", value = s;
let rank
if (s == "一区") {
rank = 1
Expand All @@ -141,10 +139,10 @@ const field2Info: any = {
} else if (s == "五区") {
rank = 5
}
return {rank, text}
return {rank, key, value}
},
ccf(s: string) {
let text = `CCF ${s}`
let key = "CCF", value=s
let rank
if (s == "A") {
rank = 1;
Expand All @@ -159,7 +157,7 @@ const field2Info: any = {
} else if (s == "T3") {
rank = 3;
}
return {rank, text}
return {rank, key, value}
}
}

Expand Down
47 changes: 34 additions & 13 deletions src/modules/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,11 @@ export default class Views {
}).join(".")
return s + " \n" + JSON.stringify(data)
} catch (e) {
console.log(e)
return ""
}
},
{
renderCellHook: (index: any, data: any, column: any) => {
console.log(data)
const span = ztoolkit.UI.createElement(document, "span", {
styles: {
display: "flex",
Expand All @@ -640,21 +638,30 @@ export default class Views {
const margin = Zotero.Prefs.get(`${config.addonRef}.${key}Column.margin`) as string
const padding = Zotero.Prefs.get(`${config.addonRef}.${key}Column.padding`) as string
let fields: any = Zotero.Prefs.get(`${config.addonRef}.${key}Column.fields`) as string
fields = fields.split(/,\s*/g).filter((i: string)=>data[i])
fields = fields.split(/,\s*/g).filter((i: string) => data[i])
let mapString: any = Zotero.Prefs.get(`${config.addonRef}.${key}Column.map`) as string
const textMap = new Map()
mapString.split(/,\s*/g).filter((s: string) => s.indexOf("=") != -1).forEach((s: string) => {
let [k, v] = s.split("=").map((s: string) => s.trim())
k && v && textMap.set(k, v)
})
let getMapString = (k: string) => {
return textMap.get(k) || k
}
for (let i = 0; i < fields.length; i++) {
let field = fields[i]
let fieldValue = data[field]
let text, color
if (field in field2Info) {
let info = field2Info[field](fieldValue)
let rankIndex = info.rank - 1
text = info.text
color = rankIndex >= rankColors.length ? rankColors.slice(-1)[0] : rankColors[rankIndex]
text = [getMapString(info.key), getMapString(info.value) ].filter(i=>i.length>0).join(" ")
} else {
if (field.toUpperCase() == fieldValue.toUpperCase()) {
text = fieldValue.toUpperCase()
text = getMapString(fieldValue.toUpperCase())
} else {
text = `${field.toUpperCase()} ${fieldValue}`
text = `${getMapString(field.toUpperCase())} ${getMapString(fieldValue)}`
}
color = defaultColor
}
Expand Down Expand Up @@ -706,6 +713,11 @@ export default class Views {
name: "Fields",
type: "input",
},
{
prefKey: `${key}Column.map`,
name: "Map",
type: "input",
},
{
prefKey: `${key}Column.rankColors`,
name: "Rank Colors",
Expand Down Expand Up @@ -744,7 +756,8 @@ export default class Views {
type: "range",
range: [0, 1, 0.001]
},
]
],
500
)
}

Expand Down Expand Up @@ -1132,7 +1145,8 @@ export default class Views {
*/
public patchSetting(
colKey: string,
args: { prefKey: string, name: string, type: string, range?: number[], values?: string[] }[]
args: { prefKey: string, name: string, type: string, range?: number[], values?: string[]}[],
width: number = 233
) {
const sign = `zoterostyle-setting-${colKey}`
if (ZoteroPane.itemsView[sign]) { return }
Expand Down Expand Up @@ -1384,7 +1398,7 @@ export default class Views {
},
element: element,
hooks: { accept }
}, 233, (args.length + 2.5) * eachHeight
}, width, (args.length + 2.5) * eachHeight
)
}
}
Expand Down Expand Up @@ -2294,7 +2308,6 @@ export default class Views {
name: "标注",
label: "Style",
callback: (prompt: Prompt) => {
prompt.inputNode.placeholder = "左击使用,右击删除,左长按进入编辑"
const container = prompt.createCommandsContainer()
type Name = string;
type Color = string;
Expand All @@ -2306,7 +2319,16 @@ export default class Views {
let groups: Group[]= JSON.parse(Zotero.Prefs.get(`${config.addonRef}.annotationColorsGroups`) as string)
// [[颜色名称, 颜色], [颜色名称, 颜色]]
// let defaultAnno: Annotation[] = JSON.parse(Zotero.Prefs.get(`${config.addonRef}.annotationColors`) as string)
let defaultAnno: Annotation[] = [["general.yellow", "#ffd400"], ["general.red", "#ff6666"], ["general.green", "#5fb236"], ["general.blue", "#2ea8e5"], ["general.purple", "#a28ae5"]]
let defaultAnno: Annotation[] = [
['general.yellow', '#ffd400'],
['general.red', '#ff6666'],
['general.green', '#5fb236'],
['general.blue', '#2ea8e5'],
['general.purple', '#a28ae5'],
['general.magenta', '#e56eee'],
['general.orange', '#f19837'],
['general.gray', '#aaaaaa']
];

const svg = `<svg t="1675648090111" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http:https://www.w3.org/2000/svg" p-id="2675" width="20" height="20" style="height: 100%;"><path d="M863.328262 481.340895l-317.344013 0.099772L545.984249 162.816826c0-17.664722-14.336138-32.00086-32.00086-32.00086s-31.99914 14.336138-31.99914 32.00086l0 318.400215-322.368714-0.17718c-0.032684 0-0.063647 0-0.096331 0-17.632039 0-31.935493 14.239806-32.00086 31.904529-0.096331 17.664722 14.208843 32.031824 31.871845 32.095471l322.59234 0.17718 0 319.167424c0 17.695686 14.336138 32.00086 31.99914 32.00086s32.00086-14.303454 32.00086-32.00086L545.982529 545.440667l317.087703-0.099772c0.063647 0 0.096331 0 0.127295 0 17.632039 0 31.935493-14.239806 32.00086-31.904529S880.960301 481.404542 863.328262 481.340895z" fill="#575B66" p-id="2676"></path></svg>`
console.log(groups, defaultAnno)
Expand Down Expand Up @@ -2537,7 +2559,6 @@ export default class Views {
* @param annotationColors
*/
let editAnnotations = (group: Group) => {
prompt.inputNode.placeholder = "右击删除"
let annotations: Annotation[] = group[1]
const container = prompt.createCommandsContainer()
const isUsed = JSON.stringify(annotations) == Zotero.Prefs.get(`${config.addonRef}.annotationColors`)
Expand Down Expand Up @@ -3078,7 +3099,7 @@ function dialog(io: {
window.openDialog(
`chrome:https://${config.addonRef}/content/dialog.xul`,
"zotero-style",
`chrome,centerscreen,width=${width},height=${height},alwaysRaised=yes`,
`chrome,centerscreen,width=${width},height=${height},alwaysRaised=yes,resizable=yes`,
io
);
}
Expand Down

0 comments on commit 2d59c80

Please sign in to comment.