-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt at a version for Zotero 7. Seems to work!
- Loading branch information
Showing
10 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Zotero Abstract Cleaner | ||
======================= | ||
|
||
This open source project is for fixing line endings in abstracts in Zotero, for example, after copying and pasting from Adobe Acrobat. It adds a menu item in the right-click contextual menu for items. This means that you can select multiple items and apply this function to all of them. | ||
|
||
# Installing | ||
|
||
To install Zotero Abstract Cleaner, download the latest version of Zotero Abstract Cleaner from the Releases section of this GitHub repo. In **Zotero** , open Tools -> Add-ons. Then drag the Zotero Abstract Cleaner .xpi file onto the Zotero Add-ons window. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Zotero.ZoteroAbstractCleaner = { | ||
|
||
id: null, | ||
version: null, | ||
rootURI: null, | ||
initialized: false, | ||
|
||
init({ id, version, rootURI }) | ||
{ | ||
if(this.initialized) return; | ||
|
||
this.id = id; | ||
this.version = version; | ||
this.rootURI = rootURI; | ||
this.initialized = true; | ||
}, | ||
|
||
// when you copy from some formats e.g. pdf, the line endings are crap | ||
// added as an overlay.xul menu item | ||
fixAbstract: async function(){ | ||
var items = Zotero.getActiveZoteroPane().getSelectedItems(); | ||
for (var x=0; x<items.length; x++){ | ||
var itemID = items[x].id; | ||
var item = Zotero.Items.get(itemID); | ||
var abstract = item.getField('abstractNote'); | ||
//Zotero.debug(abstract); | ||
// bit more tedious but preserves paragraphs | ||
abstract = abstract.replace(/\r/gm," "); | ||
abstract = abstract.replace(/\n\n/gm,"<br>"); | ||
abstract = abstract.replace(/\n/gm," "); | ||
abstract = abstract.replace(/<br>/gm,"\n\n"); | ||
abstract = abstract.replace(/ +/g," "); | ||
//Zotero.debug(abstract); | ||
item.setField('abstractNote',abstract); | ||
await item.saveTx(); | ||
} | ||
}, | ||
|
||
}; | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
ZoteroAbstractCleaner7/ZoteroAbstractCleaner7-updates.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"addons": { | ||
"[email protected]": { | ||
"updates": [ | ||
{ | ||
"version": "0.1", | ||
"update_link": "https://raw.githubusercontent.com/dcartertod/zotero-plugins/main/ZoteroAbstractCleaner7.xpi", | ||
"applications": { | ||
"zotero": { | ||
"strict_min_version": "6.999" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
if (typeof Zotero == 'undefined') | ||
{ | ||
var Zotero; | ||
} | ||
|
||
function log(msg) { | ||
Zotero.debug("Zotero Abstract Cleaner 0.1: " + msg); | ||
} | ||
|
||
function install() { | ||
log("Installed "); | ||
} | ||
|
||
async function startup({ id, version, rootURI }) { | ||
log("Starting " + version); | ||
Zotero.debug("Starting " + version); | ||
|
||
Zotero.debug("load sub script " + version); | ||
Services.scriptloader.loadSubScript(rootURI + 'ZoteroAbstractCleaner.js'); | ||
Services.scriptloader.loadSubScript(rootURI + 'zoteroabstractcleaner_menu.js'); | ||
|
||
Zotero.ZoteroAbstractCleaner.init({ id, version, rootURI }); | ||
Zotero.ZoteroAbstractCleaner.Menus.init(); | ||
|
||
} | ||
|
||
function shutdown() | ||
{ | ||
log('ZotMoov: Shutting down'); | ||
// Zotero.ZoteroAbstractCleaner.destroy(); | ||
Zotero.ZoteroAbstractCleaner.Menus.destroy(); | ||
|
||
Zotero.ZoteroAbstractCleaner = null; | ||
} | ||
|
||
function uninstall() | ||
{ | ||
log('ZotMoov: Uninstalled'); | ||
// Zotero.ZoteroAbstractCleaner.destroy(); | ||
Zotero.ZoteroAbstractCleaner.Menus.destroy(); | ||
|
||
Zotero.ZoteroAbstractCleaner = null; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ZoteroAbstractCleaner-abstract = Fix Line Endings in Abstract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ZoteroAbstractCleaner-abstract = Fix Line Endings in Abstract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "ZoteroAbstractCleaner", | ||
"version": "0.1", | ||
"description": "Clean up line endings for Zotero 7.", | ||
"homepage_url": "https://github.com/dcartertod/zotero-plugins", | ||
"applications": { | ||
"zotero": { | ||
"id": "[email protected]", | ||
"update_url": "https://raw.githubusercontent.com/dcartertod/zotero-plugins/main/ZoteroAbstractCleaner7/ZoteroAbstractCleaner7-updates.json", | ||
"strict_min_version": "6.999", | ||
"strict_max_version": "7.0.*" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// ZoteroAbstractCleaner | ||
// Indebted to Zotmoov code written by Wiley Yu | ||
|
||
Components.utils.import('resource://gre/modules/Services.jsm'); | ||
|
||
Zotero.ZoteroAbstractCleaner.Menus = { | ||
_store_added_elements: [], | ||
_zac_menu_item: null, | ||
|
||
_window_listener: | ||
{ | ||
onOpenWindow: function(a_window) | ||
{ | ||
let dom_window = a_window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow); | ||
dom_window.addEventListener('load', function() | ||
{ | ||
dom_window.removeEventListener('load', arguments.callee, false); | ||
if (dom_window.document.documentElement.getAttribute('windowtype') != 'navigator:browser') return; | ||
Zotero.ZoteroAbstractCleaner.Menus._store_added_elements = []; // Clear tracked elements since destroyed by closed window | ||
Zotero.ZoteroAbstractCleaner.Menus._zac_menu_item = null; | ||
Zotero.ZoteroAbstractCleaner.Menus._init(); | ||
}, false); | ||
} | ||
}, | ||
|
||
_getWindow() | ||
{ | ||
let enumerator = Services.wm.getEnumerator('navigator:browser'); | ||
while (enumerator.hasMoreElements()) | ||
{ | ||
let win = enumerator.getNext(); | ||
if (!win.ZoteroPane) continue; | ||
return win; | ||
} | ||
}, | ||
|
||
init() | ||
{ | ||
this._init(); | ||
Services.wm.addListener(this._window_listener); | ||
}, | ||
|
||
_init() | ||
{ | ||
let win = this._getWindow(); | ||
let doc = win.document; | ||
|
||
// Menu separator | ||
let menuseparator = doc.createXULElement('menuseparator'); | ||
|
||
// ZAC Menu item | ||
this._zac_menu_item = doc.createXULElement('menuitem'); | ||
this._zac_menu_item.id = 'zoteroabstractcleaner-menuitem'; | ||
this._zac_menu_item.setAttribute('data-l10n-id', 'ZoteroAbstractCleaner-abstract'); | ||
this._zac_menu_item.addEventListener('command', function() | ||
{ | ||
Zotero.ZoteroAbstractCleaner.fixAbstract(); | ||
}); | ||
|
||
let zotero_itemmenu = doc.getElementById('zotero-itemmenu'); | ||
|
||
zotero_itemmenu.appendChild(menuseparator); | ||
zotero_itemmenu.appendChild(this._zac_menu_item); | ||
|
||
this._store_added_elements.push(menuseparator, this._zac_menu_item); | ||
|
||
// Enable localization | ||
win.MozXULElement.insertFTLIfNeeded('ZoteroAbstractCleaner.ftl'); | ||
}, | ||
|
||
destroy() | ||
{ | ||
this._destroy(); | ||
Services.wm.removeListener(this._window_listener); | ||
}, | ||
|
||
_destroy() | ||
{ | ||
let doc = this._getWindow().document; | ||
for (let element of this._store_added_elements) | ||
{ | ||
if (element) element.remove(); | ||
} | ||
doc.querySelector('[href="ZoteroAbstractCleaner.ftl"]').remove(); | ||
|
||
this._store_added_elements = []; | ||
this._zac_menu_item = null; | ||
} | ||
} |