Skip to content

Commit

Permalink
add reset theme
Browse files Browse the repository at this point in the history
  • Loading branch information
iShareStuff committed Oct 16, 2022
0 parents commit 25416ab
Show file tree
Hide file tree
Showing 26 changed files with 2,597 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/builds
node_modules
.vscode
package-lock.json
13 changes: 13 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"npm": {
"publish": false
},
"github": {
"release": true,
"assets": ["builds/*.xpi"]
},
"hooks": {
"after:bump": "npm run build",
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
}
}
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
* @Descripttion: your project
* @version: 1.0
* @Author: ingopro
* @Date: 2022-04-24 22:08:23
* @LastEditors: isharestuff
* @LastEditTime: 2022-10-16 17:37:10
-->
# ZoteroTheme

Zotero 主题

# Quick Start Guide

## Install

- Download the latest release (.xpi file) from the [Releases Page](https://github.com/iShareStuff/ZoteroTheme/releases)
_Note_ If you're using Firefox as your browser, right-click the `.xpi` and select "Save As.."
- In Zotero click `Tools` in the top menu bar and then click `Addons`
- Go to the Extensions page and then click the gear icon in the top right.
- Select `Install Add-on from file`.
- Browse to where you downloaded the `.xpi` file and select it.
- Restart Zotero, by clicking `restart now` in the extensions list where the
ZoteroTheme plugin is now listed.

## Usage

## Development & Contributing

This add-on is built on the Zotero Addon Template of [zotero-pdf-translate](https://github.com/windingwind/zotero-pdf-translate).

Moreover, this add-on add utility with the help of [Zotero PDF Background Plugin](https://github.com/q77190858/zotero-pdf-background).

## 恢复默认主题(Reset Defalut Theme)

* 首选项>>主题编辑器>>选择默认主题default
- Reset>>Apply

![image](https://user-images.githubusercontent.com/61663626/195975450-57b3e067-ab81-4451-9548-881b3e62cc79.png)


## Disclaimer

Use this code under AGPL(open source required). No warranties are provided. Keep the laws of your locality in mind!

Part of the code of this repo refers to other open-source projects within the allowed scope.

- [zotero-pdf-translate](https://github.com/windingwind/zotero-pdf-translate)
7 changes: 7 additions & 0 deletions addon/chrome.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
content __addonRef__ chrome/content/
skin __addonRef__ default chrome/skin/default/__addonRef__/
locale __addonRef__ en-US chrome/locale/en-US/
locale __addonRef__ zh-CN chrome/locale/zh-CN/

overlay chrome://zotero/content/zoteroPane.xul chrome://__addonRef__/content/overlay.xul
overlay chrome://zotero/content/preferences/preferences.xul chrome://__addonRef__/content/preferences.xul
7 changes: 7 additions & 0 deletions addon/chrome/content/overlay.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://__addonRef__/skin/overlay.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://__addonRef__/locale/overlay.dtd">

<overlay id="__addonRef__" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://__addonRef__/content/scripts/index.js" />
</overlay>
69 changes: 69 additions & 0 deletions addon/chrome/content/preferences.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0"?>
<!DOCTYPE window SYSTEM "chrome://__addonRef__/locale/overlay.dtd">

<overlay id="__addonRef__-preferences" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<prefwindow id="zotero-prefs">
<prefpane id="zotero-prefpane-__addonRef__" insertafter="zotero-prefpane-advanced" label="Theme" image="chrome://__addonRef__/skin/favicon.png" onpaneload="Zotero.ZoteroTheme.prefs.initPreferences(window)">
<preferences id="zotero-preferences-__addonRef__">
<preference id="pref-__addonRef__-currentTheme" name="extensions.zotero.ZoteroTheme.currentTheme" type="string" />
<preference id="pref-__addonRef__-themes" name="extensions.zotero.ZoteroTheme.themes" type="string" />
</preferences>
<tabbox>
<tabs>
<tab label="&zotero.__addonRef__.pref.themeeditor.label;" />
<tab label="&zotero.__addonRef__.pref.advanced.label;" />
</tabs>
<tabpanels id="zotero-prefpane-__addonRef__" orient="vertical">
<tabpanel id="zotero-prefpane-__addonRef__-themeeditor" orient="vertical">
<rows>
<row>
<label value="&zotero.__addonRef__.pref.themeeditor.theme.label;" />
<menulist id="zotero-prefpane-__addonRef__-themeeditor-themesmenulist">
<!-- Insert Here -->
</menulist>
<button id="zotero-prefpane-__addonRef__-themeeditor-create" label="+" tooltiptext="Create Theme" style="width: 30px; maxWidth: 30px; minWidth: 30px" onclick="Zotero.ZoteroTheme.prefs.createTheme();"></button>
<button id="zotero-prefpane-__addonRef__-themeeditor-delete" label="-" tooltiptext="Delete Theme" style="width: 30px; maxWidth: 30px; minWidth: 30px" onclick="Zotero.ZoteroTheme.prefs.deleteTheme();"></button>
<button id="zotero-prefpane-__addonRef__-themeeditor-reset" label="" tooltiptext="Reset Theme" style="width: 30px; maxWidth: 30px; minWidth: 30px" onclick="Zotero.ZoteroTheme.prefs.resetTheme();"></button>
<button id="zotero-prefpane-__addonRef__-themeeditor-apply" label="Apply" tooltiptext="Apply Theme" style="width: 30px; maxWidth: 30px; minWidth: 30px" onclick="Zotero.ZoteroTheme.prefs.applyTheme();"></button>
</row>
<row>
<columns>
<column flex="1">
<groupbox flex="1">
<caption label="&zotero.__addonRef__.pref.themeeditor.styles.label;" />
<rows id="zotero-prefpane-__addonRef__-themeeditor-rows">
<!-- Insert Here -->
</rows>
<html:input id="zotero-prefpane-__addonRef__-themeeditor-colorpicker" type="color" hidden="true" />
</groupbox>
</column>
<column>
<groupbox flex="1">
<caption label="&zotero.__addonRef__.pref.themeeditor.preview.label;" />
<rows>
<row>
<textbox id="zotero-prefpane-__addonRef__-themeeditor-preview" value="The quick brown fox jumps over a lazy dog" width="200" height="100" multiline="true" />
</row>
</rows>
</groupbox>
</column>
</columns>
</row>
</rows>

</tabpanel>
<tabpanel id="zotero-prefpane-__addonRef__-advanced" orient="vertical">
<groupbox>
<caption label="&zotero.__addonRef__.help.feedback.caption.label;" />
<hbox style="display: block">
<label value="&zotero.__addonRef__.help.feedback.label;" class="zotero-text-link" href="__homepage__" />
</hbox>
</groupbox>
<label value="&zotero.__addonRef__.help.version.label;" />
<label value="&zotero.__addonRef__.help.releasetime.label;" />
</tabpanel>
</tabpanels>
</tabbox>
</prefpane>
</prefwindow>
</overlay>
10 changes: 10 additions & 0 deletions addon/chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!ENTITY zotero.__addonRef__.pref.themeeditor.label "Theme Editor">
<!ENTITY zotero.__addonRef__.pref.themeeditor.theme.label "Theme">
<!ENTITY zotero.__addonRef__.pref.themeeditor.styles.label "Styles">
<!ENTITY zotero.__addonRef__.pref.themeeditor.preview.label "Preview">
<!ENTITY zotero.__addonRef__.pref.advanced.label "Advanced">

<!ENTITY zotero.__addonRef__.help.feedback.caption.label "User Guide and Feedback">
<!ENTITY zotero.__addonRef__.help.feedback.label "GitHub">
<!ENTITY zotero.__addonRef__.help.version.label "__addonName__ VERSION __buildVersion__">
<!ENTITY zotero.__addonRef__.help.releasetime.label "Build __buildTime__">
10 changes: 10 additions & 0 deletions addon/chrome/locale/zh-CN/overlay.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!ENTITY zotero.__addonRef__.pref.themeeditor.label "主题编辑器">
<!ENTITY zotero.__addonRef__.pref.themeeditor.theme.label "主题">
<!ENTITY zotero.__addonRef__.pref.themeeditor.styles.label "样式">
<!ENTITY zotero.__addonRef__.pref.themeeditor.preview.label "预览">
<!ENTITY zotero.__addonRef__.pref.advanced.label "高级">

<!ENTITY zotero.__addonRef__.help.feedback.caption.label "User Guide and Feedback">
<!ENTITY zotero.__addonRef__.help.feedback.label "GitHub">
<!ENTITY zotero.__addonRef__.help.version.label "__addonName__ VERSION __buildVersion__">
<!ENTITY zotero.__addonRef__.help.releasetime.label "Build __buildTime__">
Binary file added addon/chrome/skin/default/ZoteroTheme/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions addon/install.rdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<RDF:RDF
xmlns:em="http://www.mozilla.org/2004/em-rdf#"
xmlns:NC="http://home.netscape.com/NC-rdf#"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<RDF:Description
RDF:about="urn:mozilla:install-manifest"
em:id="__addonID__"
em:name="__addonName__"
em:version="__buildVersion__"
em:type="2"
em:creator="__author__"
em:description="__description__"
em:homepageURL="__homepage__"
em:iconURL="chrome://__addonRef__/skin/favicon.png"
em:updateURL="https://raw.githubusercontent.com/iShareStuff/ZoteroTheme/master/update.rdf">>
<em:type>2</em:type>
<em:targetApplication RDF:resource="rdf:#$x61SL3"/>
<em:targetApplication>
<Description>
<em:id>[email protected]</em:id>
<em:minVersion>5.0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
<em:targetApplication>
<Description>
<em:id>[email protected]</em:id>
<em:minVersion>5.0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
</RDF:Description>
</RDF:RDF>
164 changes: 164 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
const esbuild = require("esbuild");
const compressing = require("compressing");
const path = require("path");
const fs = require("fs");
const process = require("process");
const replace = require("replace-in-file");
const {
name,
author,
description,
homepage,
addonName,
addonID,
addonRef,
version,
} = require("./package.json");

function copyFileSync(source, target) {
var targetFile = target;

// If target is a directory, a new file with the same name will be created
if (fs.existsSync(target)) {
if (fs.lstatSync(target).isDirectory()) {
targetFile = path.join(target, path.basename(source));
}
}

fs.writeFileSync(targetFile, fs.readFileSync(source));
}

function copyFolderRecursiveSync(source, target) {
var files = [];

// Check if folder needs to be created or integrated
var targetFolder = path.join(target, path.basename(source));
if (!fs.existsSync(targetFolder)) {
fs.mkdirSync(targetFolder);
}

// Copy
if (fs.lstatSync(source).isDirectory()) {
files = fs.readdirSync(source);
files.forEach(function (file) {
var curSource = path.join(source, file);
if (fs.lstatSync(curSource).isDirectory()) {
copyFolderRecursiveSync(curSource, targetFolder);
} else {
copyFileSync(curSource, targetFolder);
}
});
}
}

function clearFolder(target) {
if (fs.existsSync(target)) {
fs.rmSync(target, { recursive: true, force: true });
}

fs.mkdirSync(target, { recursive: true });
}

function dateFormat(fmt, date) {
let ret;
const opt = {
"Y+": date.getFullYear().toString(),
"m+": (date.getMonth() + 1).toString(),
"d+": date.getDate().toString(),
"H+": date.getHours().toString(),
"M+": date.getMinutes().toString(),
"S+": date.getSeconds().toString(),
};
for (let k in opt) {
ret = new RegExp("(" + k + ")").exec(fmt);
if (ret) {
fmt = fmt.replace(
ret[1],
ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0")
);
}
}
return fmt;
}

const t = new Date();
const buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
const buildDir = "builds";

console.log(
`[Build] BUILD_DIR=${buildDir}, VERSION=${version}, BUILD_TIME=${buildTime}`
);

clearFolder(buildDir);

copyFolderRecursiveSync("addon", buildDir);

esbuild
.build({
entryPoints: ["src/index.ts"],
bundle: true,
// Entry should be the same as addon/chrome/content/overlay.xul
outfile: path.join(buildDir, "addon/chrome/content/scripts/index.js"),
// minify: true,
})
.catch(() => process.exit(1));

console.log("[Build] Run esbuild OK");

const optionsAddon = {
files: [
path.join(buildDir, "**/*.rdf"),
path.join(buildDir, "**/*.dtd"),
path.join(buildDir, "**/*.xul"),
path.join(buildDir, "**/*.manifest"),
"update.rdf",
],
from: [
/__author__/g,
/__description__/g,
/__homepage__/g,
/__addonName__/g,
/__addonID__/g,
/__addonRef__/g,
/__buildVersion__/g,
/__buildTime__/g,
/<em:version>\S*<\/em:version>/g,
],
to: [
author,
description,
homepage,
addonName,
addonID,
addonRef,
version,
buildTime,
`<em:version>${version}</em:version>`,
],
countMatches: true,
};

_ = replace.sync(optionsAddon);
console.log(
"[Build] Run replace in ",
_.filter((f) => f.hasChanged).map(
(f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`
)
);

console.log("[Build] Replace OK");

console.log("[Build] Addon prepare OK");

compressing.zip.compressDir(
path.join(buildDir, "addon"),
path.join(buildDir, `${name}.xpi`),
{
ignoreBase: true,
}
);

console.log("[Build] Addon pack OK");
console.log(
`[Build] Finished in ${(new Date().getTime() - t.getTime()) / 1000} s.`
);
7 changes: 7 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
},
"exclude": ["node_modules", "builds"]
}
Loading

0 comments on commit 25416ab

Please sign in to comment.