Skip to content

Commit

Permalink
0504
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed May 4, 2023
1 parent 00bee9a commit ba878c1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 115 deletions.
2 changes: 1 addition & 1 deletion addon/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pref("extensions.zotero.__addonRef__.PublicationTagsColumn.margin", "0.2");
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.padding", "0.5");
pref("extensions.zotero.__addonRef__.PublicationTagsColumn.opacity", "0.13");

pref("extensions.zotero.__addonRef__.function.progressColumn.enable", true);
pref("extensions.zotero.__addonRef__.function.progressColumn.enable", false);
pref("extensions.zotero.__addonRef__.progressColumn.style", "bar");
pref("extensions.zotero.__addonRef__.progressColumn.color", "#86C8BC");
pref("extensions.zotero.__addonRef__.progressColumn.opacity", "0.7");
Expand Down
2 changes: 0 additions & 2 deletions src/modules/d3.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/modules/record.ts

This file was deleted.

56 changes: 56 additions & 0 deletions src/modules/requests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

export default class Requests {
/**
* Record api response
*/
public cache: { [key: string]: any } = {}

async get(url: string, responseType: string = "json", headers: object = {}) {
const k = JSON.stringify(arguments)
if (this.cache[k]) {
return this.cache[k]
}
let res = await Zotero.HTTP.request(
"GET",
url,
{
responseType: responseType,
headers,
credentials: "include"
}
)
if (res.status == 200) {
this.cache[k] = res.response
return res.response
} else {
console.log(`get ${url} error`, res)
}
}

async post(url: string, body: object = {}, responseType: string = "json") {
const k = JSON.stringify(arguments)
if (this.cache[k]) {
return this.cache[k]
}
let res = await Zotero.HTTP.request(
"POST",
url,
Object.assign({
responseType: responseType,
}, (Object.keys(body).length > 0 ? {
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body),
// credentials: "include"
} : {}))
)
if (res.status == 200) {
this.cache[k] = res.response
return res.response
} else {
// window.alert("error" + res.status)
console.log(`post ${url} error`, res)
}
}
}
96 changes: 3 additions & 93 deletions src/modules/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Requests from "zotero-reference/src/modules/requests";
import Requests from "./requests";

import { config } from "../../package.json";
import LocalStorage from "./localStorage";
Expand Down Expand Up @@ -27,7 +27,7 @@ export async function updatePublicationTags(localStorage: LocalStorage, item: Zo
} catch { console.log(response) }
if (response && response.data) {
// 自定义数据集 + 官方数据集合并
let officialAllData={...response.data.officialRank.all}
let officialAllData = {...response.data.officialRank.all}
if (Object.keys(officialAllData).length === 0) {
if (tip) {
new ztoolkit.ProgressWindow("Publication Tags", { closeTime: 3000, closeOtherProgressWindows: true })
Expand Down Expand Up @@ -69,94 +69,4 @@ export async function updatePublicationTags(localStorage: LocalStorage, item: Zo
return 1
}
}
}

// let lock: undefined | _ZoteroPromiseObject = undefined
// const utils = {
// requests: new Requests(),
// localStorage: new localStorage(config.addonRef),
// wait(item: Zotero.Item, key: string, local: boolean=true) {
// switch (key) {
// case "publication":
// const publicationTitle = this.getPublicationTitle(item)
// if (publicationTitle == "") { return }
// let data
// if (local) {
// try {
// data = this.localStorage.get(item, key)
// } catch {}
// }
// if (data !== undefined) { return data }
// // 开启一个异步更新影响因子
// let secretKey = Zotero.Prefs.get(`${config.addonRef}.easyscholar.secretKey`) as string
// window.setTimeout(async () => {
// this.requests.cache = {}
// if (secretKey) {
// await lock;
// lock = Zotero.Promise.defer()
// let response
// try {
// response = await this.requests.get(
// `https://easyscholar.cc/open/getPublicationRank?secretKey=${secretKey}&publicationName=${encodeURIComponent(publicationTitle)}`,
// )
// } catch { console.log(response) }
// // 延迟
// await Zotero.Promise.delay(1000)
// lock!.resolve()
// if (response && response.data) {
// // 自定义数据集+官方数据集合并
// let officialAllData = response.data.officialRank.all
// if (!officialAllData) {
// if (!local) {
// new ztoolkit.ProgressWindow("Publication Tags", { closeTime: 3000, closeOtherProgressWindows: true })
// .createLine({ text: "Not Found", type: "default" }).show()
// }
// return await this.localStorage.set(item, key, "")
// }
// 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 {}
// })
// if (officialAllData) {
// await this.localStorage.set(item, key, officialAllData)
// console.log(item.key, officialAllData)
// // 显示它支持的所有字段
// let popupWin = new ztoolkit.ProgressWindow("Publication Tags", { closeTime: 3000, closeOtherProgressWindows: true }).show()
// popupWin.createLine({text: publicationTitle, type: "default"})
// Object.keys(officialAllData).forEach(k => {
// popupWin.createLine({ text: `${k}: ${officialAllData[k]}`, type: "success" })
// })
// // ztoolkit.ItemTree.refresh()
// }
// }
// } else {
// if (!local) {
// new ztoolkit.ProgressWindow("Publication Tags", { closeTime: 3000, closeOtherProgressWindows: true })
// .createLine({ text: "No easyScholar secret key configured", type: "fail" }).show()
// }
// }
// })
// return
// default:
// break
// }
// },
// getPublicationTitle(item: Zotero.Item) {
// return [item.getField("publicationTitle"), item.getField("proceedingsTitle")].find(i=>i.trim().length > 0)
// }
// }

// export default utils
}
2 changes: 1 addition & 1 deletion typing/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare const _globalThis: {
addon: typeof addon;
};

declare const ztoolkit: import("E:/Github/zotero-plugin-toolkit").ZoteroToolkit;
declare const ztoolkit: import("zotero-plugin-toolkit").ZoteroToolkit;

declare const rootURI: string;

Expand Down

0 comments on commit ba878c1

Please sign in to comment.