Skip to content

Commit

Permalink
add: 进度opacity style
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Jan 20, 2023
1 parent f90d95b commit 1feba76
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 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.0.2",
"version": "2.0.3",
"description": "Zotero Style",
"config": {
"addonName": "Zotero Style",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AddonItem from "./item";

export default class Events {
public recordInterval = 8; // s
public recordInterval = 10; // s
public updateInterval = 60; // s
public maxHangTime = 60; // s
public state = {
Expand Down
5 changes: 4 additions & 1 deletion src/modules/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class Progress {
* 用透明度量化各个部分完成情况
* 适用于 - 阅读高能进度条
*/
public opacity(values: number[], color: string = "#62b6b7", opacity: string = "1"): HTMLSpanElement {
public opacity(values: number[], color: string = "#62b6b7", opacity: string = "1", limit: number = -1): HTMLSpanElement {
const span = ztoolkit.UI.createElement(
document,
"span",
Expand All @@ -39,6 +39,9 @@ export default class Progress {
let sortedValues = [...values].sort((a, b) => b - a);
let meanValue = [...values].reduce((a, b) => a + b) / values.length;
let maxValue = meanValue + (sortedValues[0] - meanValue) * .5
if (limit > 0) {
maxValue = maxValue > limit ? maxValue : limit
}
let [r, g, b] = this.getRGB(color)
for (let value of values) {
span.appendChild(
Expand Down
24 changes: 13 additions & 11 deletions src/modules/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export default class Views {
span.style.marginLeft = "0.3em"
});
}
// @ts-ignore
titleSpan.firstChild.style.marginLeft = ".3em"

const item = ZoteroPane.getSortedItems()[index]
let record: Record = this.addonItem.get(item, "readingTime") as Record
if(!record) { return cellSpan }
Expand All @@ -88,6 +91,7 @@ export default class Views {
Zotero.Prefs.get(
`${config.addonRef}.titleColumn.opacity`
) as string,
60
)
progressNode.style.top = "0"
progressNode.style.zIndex = "-1"
Expand Down Expand Up @@ -268,15 +272,6 @@ export default class Views {
`
if (!data) { return tagSpans }
let tags: { tag: string, color: string }[] = JSON.parse(data)
// const align = Zotero.Prefs.get(
// `${config.addonRef}.tagsColumn.align`
// ) as any || "left"
// let offset = 0
// const margin = parseFloat(
// Zotero.Prefs.get(
// `${config.addonRef}.tagsColumn.margin`
// ) as string
// )
tags.forEach(tagObj => {
let tag = tagObj.tag, color = tagObj.color
if (!tag.startsWith("#")) { return }
Expand Down Expand Up @@ -311,7 +306,14 @@ export default class Views {
},
{
renderCellHook: (index: any, data: any, column: any) => {
const span = ztoolkit.UI.createElement(document, "span", "html") as HTMLSpanElement
const span = ztoolkit.UI.createElement(document, "span", {
styles: {
display: "inline-block",
width: "100%",
height: "20px"
}
}) as HTMLSpanElement

let item = ZoteroPane.getSortedItems()[index]
let page: number
try {
Expand Down Expand Up @@ -367,7 +369,7 @@ export default class Views {
prefKey: "progressColumn.style",
name: "Style",
type: "select",
values: ["bar", "line"]
values: ["bar", "line", "opacity"]
},
{
prefKey: "progressColumn.color",
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.0.2",
"version": "2.0.3",
"update_link": "https://github.com/muisedestiny/zotero-style/releases/latest/download/zotero-style.xpi",
"applications": {
"gecko": {
Expand All @@ -12,7 +12,7 @@
}
},
{
"version": "2.0.2",
"version": "2.0.3",
"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.0.2</em:version>
<em:version>2.0.3</em:version>
<em:targetApplication>
<rdf:Description>
<em:id>[email protected]</em:id>
Expand Down

0 comments on commit 1feba76

Please sign in to comment.