Skip to content

Commit

Permalink
easyscholar:密钥支持
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Mar 19, 2023
1 parent c82b233 commit ebd890f
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 58 deletions.
3 changes: 1 addition & 2 deletions addon/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ pref("extensions.zotero.__addonRef__.GPT.secretKey", "");
pref("extensions.zotero.__addonRef__.storage.in", "note");
pref("extensions.zotero.__addonRef__.storage.filename", "");

// pref("extensions.zotero.__addonRef__.easyscholar.username", "");
// pref("extensions.zotero.__addonRef__.easyscholar.password", "");
pref("extensions.zotero.__addonRef__.easyscholar.secretKey", "");



Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zotero-style",
"version": "2.5.0",
"version": "2.5.1",
"description": "让你的Zotero看起来更有趣",
"config": {
"addonName": "Zotero Style",
Expand Down
13 changes: 7 additions & 6 deletions src/modules/graphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export default class GraphView {
private async getGraphByItemArrLink(items: Zotero.Item[], getArr: Function) {
const nodes: { [key: string]: any } = {}
const graph: { [key: string]: any } = { nodes }
const sharedValues: { [key: string]: { count: number, items: Set<Zotero.Item> } } = {}
const sharedValues: { [key: string]: { items: Set<Zotero.Item> } } = {}

// 找出所有共享值
items.forEach((item) => {
Expand All @@ -313,23 +313,24 @@ export default class GraphView {
}
values.forEach((value: string) => {
if (!sharedValues.hasOwnProperty(value)) {
sharedValues[value] = { count: 0, items: new Set() }
sharedValues[value] = { items: new Set() }
}
sharedValues[value].count += 1
sharedValues[value].items.add(item)
})
})
// 根据分位点,计算临界值
const pct = 0.95
const countArr = Object.values(sharedValues).map(i => i.count).filter(i=>i>1).sort()
const pct = 0.9
console.log(sharedValues)
const countArr = Object.values(sharedValues).map(i => i.items.size).filter(i=>i>1).sort()
const limit = countArr[parseInt((countArr.length * pct).toFixed(0))]
console.log(limit)
// 创建节点对象
Object.keys(sharedValues).forEach((value: string) => {
const items = [...sharedValues[value].items]
items.forEach(item => {
nodes[item.id] ??= { links: {}, type: "item" }
if (items.length > limit) {
console.log(items.length)
if (items.length >= limit) {
nodes[item.id].links[value] = true;
(nodes[value] ??= {links: {}, type: "tag"}).links[item.id] = true
}
Expand Down
25 changes: 16 additions & 9 deletions src/modules/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export class Tags {
}, this.nestedTagsContainer) as HTMLDivElement;
// 搜索框
const searchBoxHeight = 15
let timer: number;
const searchBox = ztoolkit.UI.appendElement({
tag: "div",
classList: ["nested-search-box"],
Expand Down Expand Up @@ -364,15 +365,21 @@ export class Tags {
const searchText = inputNode.value as string
if (searchText.length) {
clearNode.style.display = ""
} else {
clearNode.style.display = "none"

}
// 搜索
console.log("search...", searchText)
this.searchText = searchText
// 复制一份
this.plainTags = await this.getPlainTags()
this.nestedTags = await this.getNestedTags()
box.innerHTML = ""
await this.render(box, this.nestedTags)
window.clearTimeout(timer)
timer = window.setTimeout(async () => {
// 搜索
console.log("search...", searchText)
this.searchText = searchText
// 复制一份
this.plainTags = await this.getPlainTags()
this.nestedTags = await this.getNestedTags()
box.innerHTML = ""
await this.render(box, this.nestedTags)
}, 500)
}
}
]
Expand All @@ -383,7 +390,7 @@ export class Tags {
styles: {
width: `${searchBoxHeight}px`,
height: `${searchBoxHeight}px`,
display: "none"
display: this.searchText?.length ? "" : "none"
},
properties: {
innerHTML: `<svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http:https://www.w3.org/2000/svg" width="${searchBoxHeight}" height="${searchBoxHeight}"><path d="M512.288 1009.984c-274.912 0-497.76-222.848-497.76-497.76s222.848-497.76 497.76-497.76c274.912 0 497.76 222.848 497.76 497.76s-222.848 497.76-497.76 497.76zM700.288 368.768c12.16-12.16 12.16-31.872 0-44s-31.872-12.16-44.032 0l-154.08 154.08-154.08-154.08c-12.16-12.16-31.872-12.16-44.032 0s-12.16 31.84 0 44l154.08 154.08-154.08 154.08c-12.16 12.16-12.16 31.84 0 44s31.872 12.16 44.032 0l154.08-154.08 154.08 154.08c12.16 12.16 31.872 12.16 44.032 0s12.16-31.872 0-44l-154.08-154.08 154.08-154.08z" fill="#5a5a5a" p-id="5698"></path></svg>`
Expand Down
84 changes: 47 additions & 37 deletions src/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,54 @@ const utils = {
}
if (data) { return data }
// 开启一个异步更新影响因子
// 下面代码对es官方影响较大
// window.setTimeout(async () => {
// const username = Zotero.Prefs.get(`${config.addonRef}.easyscholar.username`) as string
// const password = Zotero.Prefs.get(`${config.addonRef}.easyscholar.password`) as string
// if (username.length && password.length) {
// await this.requests.get(
// `https://easyscholar.cc/login?userName=${username}&password=${password}`
// )
// }
// const response = await this.requests.post(
// "https://easyscholar.cc/extension/listPublicationRank4",
// {
// publicationName: { "0": publicationTitle }
// }
// )
// ztoolkit.log(response)
// if (response && response.data) {
// let data = response.data.publicationRankList[0]
// if (data) {
// delete data.tempID
// await this.localStorage.set(item, key, data)
// }
// }
// })
let secretKey = Zotero.Prefs.get(`${config.addonRef}.easyscholar.secretKey`) as string
window.setTimeout(async () => {
this.requests.cache = {}
let response = await this.requests.get(
`https://easyscholar.cc/homeController/getQueryTable.ajax?sourceName=${escape(publicationTitle)}`,
)
response = response || await this.requests.get(
`https://easyscholar.cc/homeController/getQueryTable.ajax?sourceName=${publicationTitle}`,
)
console.log(
response)
if (response && response.data) {
let data = response.data[0]
if (data) {
await this.localStorage.set(item, key, data)
if (secretKey) {
let response = await this.requests.get(
`https://easyscholar.cc/open/getPublicationRank?secretKey=${secretKey}&publicationName=${escape(publicationTitle) }`,
) || await this.requests.get(
`https://easyscholar.cc/open/getPublicationRank?secretKey=${secretKey}&publicationName=${publicationTitle}`,
)
ztoolkit.log(response)
if (response && response.data) {
// 自定义数据集+官方数据集合并
let officialAllData = response.data.officialRank.all
let customRankInfo = response.data.customRank.rankInfo
response.data.customRank.rank.forEach((rankString: string) => {
try {
// 1613160542602600448&&&2
let uuid: string, rank: string;
[uuid, rank] = rankString.split("&&&")
rank = {
"1": "oneRankText",
"2": "twoRankText",
"3": "threeRankText",
"4": "fourRankText",
"5": "fiveRankText"
}[rank] as string
let info = customRankInfo.find((i:any) => i.uuid == uuid)
officialAllData[info.abbName] = info[rank]
} catch {}
})
console.log(officialAllData)
if (officialAllData) {
await this.localStorage.set(item, key, officialAllData)
}
}
} else {
this.requests.cache = {}
let response = await this.requests.get(
`https://easyscholar.cc/homeController/getQueryTable.ajax?sourceName=${escape(publicationTitle)}`,
) || await this.requests.get(
`https://easyscholar.cc/homeController/getQueryTable.ajax?sourceName=${publicationTitle}`,
)
console.log(
response)
if (response && response.data) {
let data = response.data[0]
if (data) {
await this.localStorage.set(item, key, data)
}
}
}
})
Expand Down
4 changes: 4 additions & 0 deletions src/modules/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3516,6 +3516,10 @@ export default class Views {
(original) =>
(index: number, selection: object, oldDiv: HTMLDivElement, columns: any[]) => {
const div = original.call(ZoteroPane.collectionsView, index, selection, oldDiv, columns)

// div.querySelector("span").style.backgroundColor = "#ffffff"
// div.querySelector("span").style.color = "#ffffff"

const ref = ZoteroPane.collectionsView.getRow(index).ref!
if (index > 0) {
let key: string;
Expand Down
4 changes: 2 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"[email protected]": {
"updates": [
{
"version": "2.5.0",
"version": "2.5.1",
"update_link": "https://github.com/muisedestiny/zotero-style/releases/latest/download/zotero-style.xpi",
"applications": {
"gecko": {
Expand All @@ -12,7 +12,7 @@
}
},
{
"version": "2.5.0",
"version": "2.5.1",
"update_link": "https://github.com/muisedestiny/zotero-style/releases/latest/download/zotero-style.xpi",
"applications": {
"zotero": {
Expand Down
2 changes: 1 addition & 1 deletion update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<em:version>2.5.0</em:version>
<em:version>2.5.1</em:version>
<em:targetApplication>
<rdf:Description>
<em:id>[email protected]</em:id>
Expand Down

0 comments on commit ebd890f

Please sign in to comment.