Skip to content

Instantly share code, notes, and snippets.

@andersjohansson
Last active December 2, 2019 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersjohansson/1b028b51ca766591923c3d1ace162a56 to your computer and use it in GitHub Desktop.
Save andersjohansson/1b028b51ca766591923c3d1ace162a56 to your computer and use it in GitHub Desktop.
Clean up zotero reports by using javascript in the browser console (or in a bookmarklet).
// USAGE:
// 1. Save the zotero report and open it in your web browser.
// 2. Open the browser’s web console
// (in Firefox: Menu>Web Developer>Web console (or CTRL+SHIFT+K))
// (in Chrome: Menu>More Tools>Developer tools)
// 3. Customize the lists below by commenting out fields you want to keep
// 4. Copy and paste the code into the web console and run it.
// 5. Your report should be cleaned up and ready to print etc.
// ALTERNATIVE USAGE (bookmarklet):
// It is possible to create bookmarklets of these functions, which may
// be suitable if you often need to clean up reports in different
// ways.
// 1. Customize which fields to clean below
// 2. Remove all comment lines (starting with //), they seem to break bookmarklets
// 3. Copy relevant code
// 4. Create a new bookmark in your browser
// 5. Add: javascript:{COPIED CODE} as location for the bookmark
// 6. Invoking the bookmark should clean up a report!
// Remember that the report is only edited as viewed in the browser
// and not saved back to the file. However, you can re-save it from
// your browser now.
// CODE:
// CLEAN OUT METADATA
// Here are the fields to clean away. Everything that is commented out
// (prefixed with //) is kept. Customize this to your liking!
const fieldsToCleanEN = [
// CREATOR TYPES (keep all):
// "Author",
// "Contributor",
// "Editor",
// "Translator",
// "Series Editor",
// "Interview With",
// "Interviewer",
// "Director",
// "Scriptwriter",
// "Producer",
// "Cast Member",
// "Sponsor",
// "Counsel",
// "Inventor",
// "Attorney/Agent",
// "Recipient",
// "Performer",
// "Composer",
// "Words By",
// "Cartographer",
// "Programmer",
// "Artist",
// "Commenter",
// "Presenter",
// "Guest",
// "Podcaster",
// "Reviewed Author",
// "Cosponsor",
// "Book Author",
// ITEM FIELDS:
// "Type",
// "Title",
"Date Added",
"Modified",
"Source",
"Notes",
"Tags",
"Attachments",
"Related",
"URL",
"Rights",
"Series",
"Volume",
"Issue",
"Edition",
"Place",
"Publisher",
"Pages",
"ISBN",
// "Publication",
"ISSN",
"Date",
"Section",
"Call Number",
"Loc. in Archive",
"Distributor",
"Extra",
"Journal Abbr",
"DOI",
"Accessed",
"Series Title",
"Series Text",
"Series Number",
"Institution",
"Report Type",
"Code",
"Session",
"Legislative Body",
"History",
"Reporter",
"Court",
"# of Volumes",
"Committee",
"Assignee",
"Patent Number",
"Priority Numbers",
"Issue Date",
"References",
"Legal Status",
"Code Number",
"Medium",
"Number",
"Artwork Size",
"Library Catalog",
"Format",
"Medium",
"Scale",
"Website Type",
"Format",
"Label",
"Meeting Name",
"Studio",
"Running Time",
"Network",
"Post Type",
"File Type",
"Version",
"System",
"Company",
"Conference Name",
"Encyclopedia Title",
"Dictionary Title",
"Language",
"Prog. Language",
"University",
"Abstract",
"Website Title",
"Report Number",
"Bill Number",
"Code Volume",
"Code Pages",
"Date Decided",
"Reporter Volume",
"First Page",
"Document Number",
"Date Enacted",
"Public Law Number",
"Country",
"Application Number",
"Forum/Listserv Title",
"Episode Number",
"Blog Title",
"Medium",
"Case Name",
"Name of Act",
"Subject",
"Proceedings Title",
"Book Title",
"Short Title",
"Docket Number",
"# of Pages",
"Program Title",
"Issuing Authority",
"Filing Date",
"Genre",
"Archive",
];
[...document.getElementsByTagName("th")].forEach(th => {
if (fieldsToCleanEN.indexOf(th.innerText) > -1) {
th.parentElement.remove();
}
});
// CLEAN OUT EXTRA INFO
// This is the info below each item’s metadata. Comment out anything
// you want to keep with //
const extraToClean = [
".tags",
".attachments",
".related",
".notes"
];
[...document.querySelectorAll(extraToClean.join(", "))].forEach(x => x.remove());
// LOCALIZATION
// My zotero is localized to Swedish, and uses the field names below in reports
// You may need to customize it the same way.
// Names to use can be found in:
// https://github.com/zotero/zotero/blob/master/chrome/locale/LOCALE/zotero/zotero.properties
// e.g. https://github.com/zotero/zotero/blob/master/chrome/locale/sv-SE/zotero/zotero.properties#L435
// it starts around line 435, at itemFields.itemType=...
const fieldsToCleanSV = [
// CREATOR TYPES:
// "Författare",
// "Medarbetare",
// "Redaktör",
// "Översättare",
// "Redaktör för bokserie",
// "Intervju med",
// "Intervjuare",
// "Regissör",
// "Manusförfattare",
// "Producent",
// "Skådespelare",
// "Förslagsläggare",
// "Handledare",
// "Uppfinnare",
// "Ombud/Agent",
// "Mottagare",
// "Artist",
// "Kompositör",
// "Text av",
// "Kartograf",
// "Programmerare",
// "Konstnär",
// "Kommentator",
// "Presentatör",
// "Gäst",
// "Poddsändare",
// "Recenserad författare",
// "Medsponsor",
// "Bokförfattare",
// ITEM FIELDS:
// "Typ",
// "Titel",
"Tillagd den",
"Ändrad den",
"Källa",
"Anteckningar",
"Etiketter",
"Bifogade dokument",
"Liknande",
"Webbadress",
"Rättigheter",
"Bokserie",
"Band/Årgång",
"Nummer",
"Upplaga",
"Ort",
"Utgivare",
"Sidor",
"ISBN",
// "Publikation",
"ISSN",
"Datum",
"Avsnitt",
"Hyllkod",
"Plats i arkiv",
"Distributör",
"Extra",
"Tidskriftsförkortning",
"DOI",
"Hämtad den",
"Titel på bokserie",
"Bokseries text",
"Nummer i bokserie",
"Institution",
"Rapporttyp",
"Författningssamling",
"Session",
"Lagstiftande organ",
"Historia",
"Referatsamling",
"Domstol",
"# volymer",
"Kommitté",
"Representant",
"Patentnummer",
"Prioritetsnummer",
"Utgivningsdatum",
"Källhänvisningar",
"Rättslig status",
"Författningsnummer",
"Medium för konstverk",
"Nummer",
"Storlek på konstverk",
"Bibliotekskatalog",
"Format",
"Media",
"Brevtyp",
"Manustyp",
"Karttyp",
"Skala",
"Uppsatstyp",
"Webbplatstyp",
"Format",
"Stämpel",
"Presentationstyp",
"Namn på möte",
"Studio",
"Inspelningslängd",
"Nätverk",
"Källtyp",
"Filtyp",
"Version",
"System",
"Företag",
"Namn på konferens",
"Uppslagsverkstitel",
"Ordbokstitel",
"Språk",
"Prog. Language",
"Lärosäte",
"Sammanfattning",
"Titel på webbplats",
"Rapportnummer",
"Förarbetets ref. nr.",
"Lagband",
"Sidkod",
"Avgörandedatum",
"Referattyp",
"Första sida",
"Dokumentnummer",
"Datum för ikraftträdande",
"Public Law Number",
"Land",
"Anmälningsnummer",
"Titel på forum/listserver",
"Avsnittsnummer",
"Bloggnamn",
"Media",
"Rättsfallsnamn",
"Författningens namn",
"Ämne",
"Protokolltitel",
"Boktitel",
"Kort titel",
"Målnummer",
"# sidor",
"Programtitel",
"Utgivare",
"Ansökningsdatum",
"Genre",
"Arkiv"
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment