Skip to content

Commit

Permalink
#295 修复同步
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Mar 24, 2023
1 parent cb83ae6 commit a951465
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
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.3",
"version": "2.5.4",
"description": "让你的Zotero看起来更有趣",
"config": {
"addonName": "Zotero Style",
Expand Down
8 changes: 4 additions & 4 deletions src/modules/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { config } from "../../package.json";

class LocalStorage {
private filename!: string;
private cache: any;
public filename!: string;
public cache: any;
public lock: _ZoteroPromiseObject;
constructor(filename: string) {
this.lock = Zotero.Promise.defer()
Expand Down Expand Up @@ -31,12 +31,12 @@ class LocalStorage {

get(item: Zotero.Item, key: string) {
if (this.cache == undefined) { return }
return (this.cache[item.id] ??= {})[key]
return (this.cache[item.key] ??= {})[key]
}

async set(item: Zotero.Item, key: string, value: any) {
await this.lock.promise;
(this.cache[item.id] ??= {})[key] = value
(this.cache[item.key] ??= {})[key] = value
window.setTimeout(async () => {
await Zotero.File.putContentsAsync(this.filename, JSON.stringify(this.cache));
})
Expand Down
12 changes: 12 additions & 0 deletions src/modules/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ export function registerPrefsScripts(_window: Window) {
}
} catch(e) {console.log(e)}
})
Object.keys(storage.cache).forEach((_id: string) => {
let id = Number(_id)
let key = Zotero.Items.get(id).key
let data = storage.cache[key]
if (!data.readingTime?.data) {
storage.cache[key] = storage.cache[id]
}
})
window.setTimeout(async () => {
await Zotero.File.putContentsAsync(storage.filename, JSON.stringify(storage.cache));
ztoolkit.getGlobal("alert")("Please restart Zotero.")
})
}
})
}
4 changes: 3 additions & 1 deletion src/modules/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,21 @@ export class Tags {
margin: "0 5px"
},
properties: {
value: this.searchText
value: this.searchText,
},
listeners: [
{
type: "focus",
listener: () => {
searchBox.style.opacity = "1"
searchBox.style.boxShadow = `0 0 0 1px rgba(0,0,0,0.5)`
}
},
{
type: "blur",
listener: () => {
searchBox.style.opacity = "0.6"
searchBox.style.boxShadow = ``
}
},
{
Expand Down
17 changes: 14 additions & 3 deletions src/modules/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ export default class Views {
let update = async (item: Zotero.Item) => {
const cacheKey = `${item.key}-annoRecord`
if (item.isRegularItem()) {
let pdfItem
let pdfItem: Zotero.Item
try {
pdfItem = await item.getBestAttachment()
} catch {
Expand All @@ -958,8 +958,18 @@ export default class Views {
}
let page: number = 0;
try {
page = Number(this.storage.get(item, "readingTime").page)
} catch { }
const key = `${pdfItem.id} total-pages`
// this.cache[key] ??= (await Zotero.Fulltext.getPages(pdfItem.id)).total
// if (!this.cache[key]) {
// window.setTimeout(async () => {
// await Zotero.FullText.indexItems([pdfItem.id], { complete: true });
// })
// }
page = Number(this.storage.get(item, "readingTime").page) ||
(this.cache[key] ??= (await Zotero.Fulltext.getPages(pdfItem.id)).total) ||
page
} catch (e) { console.log(e) }
console.log(page)
let annoRecord: any = { page, data: {} }
const annoArray = pdfItem.getAnnotations()
annoArray.forEach((anno: any) => {
Expand Down Expand Up @@ -3546,6 +3556,7 @@ export default class Views {

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

const row = ZoteroPane.collectionsView.getRow(index)
const ref = row.ref!
if (index > 0) {
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.3",
"version": "2.5.4",
"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.3",
"version": "2.5.4",
"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.3</em:version>
<em:version>2.5.4</em:version>
<em:targetApplication>
<rdf:Description>
<em:id>[email protected]</em:id>
Expand Down

0 comments on commit a951465

Please sign in to comment.