Add Scaffold as a built-in developer tool
This commit is contained in:
parent
00c159a1b4
commit
2b6fb73b57
38 changed files with 42578 additions and 0 deletions
63
chrome/content/scaffold/templates/newWeb.js
Normal file
63
chrome/content/scaffold/templates/newWeb.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright © 2019 YOUR_NAME <- TODO
|
||||
|
||||
This file is part of Zotero.
|
||||
|
||||
Zotero is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Zotero is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
|
||||
function detectWeb(doc, url) {
|
||||
// TODO: adjust the logic here
|
||||
if (url.includes('/article/')) {
|
||||
return "newspaperArticle";
|
||||
}
|
||||
else if (getSearchResults(doc, true)) {
|
||||
return "multiple";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getSearchResults(doc, checkOnly) {
|
||||
var items = {};
|
||||
var found = false;
|
||||
// TODO: adjust the CSS selector
|
||||
var rows = doc.querySelectorAll('h2>a.title[href*="/article/"]');
|
||||
for (let row of rows) {
|
||||
// TODO: check and maybe adjust
|
||||
let href = row.href;
|
||||
// TODO: check and maybe adjust
|
||||
let title = ZU.trimInternal(row.textContent);
|
||||
if (!href || !title) continue;
|
||||
if (checkOnly) return true;
|
||||
found = true;
|
||||
items[href] = title;
|
||||
}
|
||||
return found ? items : false;
|
||||
}
|
||||
|
||||
function doWeb(doc, url) {
|
||||
if (detectWeb(doc, url) == "multiple") {
|
||||
Zotero.selectItems(getSearchResults(doc, false), function (items) {
|
||||
if (items) ZU.processDocuments(Object.keys(items), scrape);
|
||||
});
|
||||
}
|
||||
else {
|
||||
scrape(doc, url);
|
||||
}
|
||||
}
|
21
chrome/content/scaffold/templates/scrapeBibTeX.js
Normal file
21
chrome/content/scaffold/templates/scrapeBibTeX.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
function scrape(doc, url) {
|
||||
// TODO adjust the url building
|
||||
var m = url.match(/FId=([\w\d]+)&/);
|
||||
if (m) {
|
||||
// e.g. http://www.fachportal-paedagogik.de/fis_bildung/suche/fis_ausg.html?FId=A18196&lart=BibTeX&Speichern=Speichern&senden_an=+E-Mail-Adresse
|
||||
var bibUrl = "/fis_bildung/suche/fis_ausg.html?FId=" + m[1] + "&lart=BibTeX";
|
||||
ZU.doGet(bibUrl, function (text) {
|
||||
var translator = Zotero.loadTranslator("import");
|
||||
translator.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4");
|
||||
translator.setString(text);
|
||||
translator.setHandler("itemDone", function (obj, item) {
|
||||
item.attachments.push({
|
||||
title: "Snapshot",
|
||||
document: doc
|
||||
});
|
||||
item.complete();
|
||||
});
|
||||
translator.translate();
|
||||
});
|
||||
}
|
||||
}
|
21
chrome/content/scaffold/templates/scrapeEM.js
Normal file
21
chrome/content/scaffold/templates/scrapeEM.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
function scrape(doc, url) {
|
||||
var translator = Zotero.loadTranslator('web');
|
||||
// Embedded Metadata
|
||||
translator.setTranslator('951c027d-74ac-47d4-a107-9c3069ab7b48');
|
||||
// translator.setDocument(doc);
|
||||
|
||||
translator.setHandler('itemDone', function (obj, item) {
|
||||
// TODO adjust if needed:
|
||||
item.section = "News";
|
||||
item.complete();
|
||||
});
|
||||
|
||||
translator.getTranslatorObject(function (trans) {
|
||||
trans.itemType = "newspaperArticle";
|
||||
// TODO map additional meta tags here, or delete completely
|
||||
trans.addCustomFields({
|
||||
'twitter:description': 'abstractNote'
|
||||
});
|
||||
trans.doWeb(doc, url);
|
||||
});
|
||||
}
|
36
chrome/content/scaffold/templates/scrapeMARC.js
Normal file
36
chrome/content/scaffold/templates/scrapeMARC.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
function scrape(doc, url) {
|
||||
// TODO adjust the selector for the lines here
|
||||
var lines = doc.querySelectorAll('#cntPlcPortal_grdMrc tr');
|
||||
|
||||
// call MARC translator
|
||||
var translator = Zotero.loadTranslator("import");
|
||||
translator.setTranslator("a6ee60df-1ddc-4aae-bb25-45e0537be973");
|
||||
translator.getTranslatorObject(function (marc) {
|
||||
var record = new marc.record();
|
||||
var newItem = new Zotero.Item();
|
||||
// ignore the table headings in lines[0]
|
||||
record.leader = text(lines[1], 'td', 4);
|
||||
var fieldTag, indicators, fieldContent;
|
||||
for (let line of Array.from(lines).slice(2)) {
|
||||
// multiple lines with same fieldTag do not repeat the tag
|
||||
// i.e. in these cases we will just take same value as before
|
||||
if (text(line, 'td', 0).trim().length > 0) {
|
||||
fieldTag = text(line, 'td', 0);
|
||||
}
|
||||
indicators = text(line, 'td', 1) + text(line, 'td', 2);
|
||||
fieldContent = '';
|
||||
if (text(line, 'td', 3).trim().length > 0) {
|
||||
fieldContent = marc.subfieldDelimiter + text(line, 'td', 3);
|
||||
}
|
||||
fieldContent += text(line, 'td', 4);
|
||||
|
||||
record.addField(fieldTag, indicators, fieldContent);
|
||||
}
|
||||
|
||||
record.translate(newItem);
|
||||
|
||||
// possibly clean newItem further here
|
||||
|
||||
newItem.complete();
|
||||
});
|
||||
}
|
31
chrome/content/scaffold/templates/scrapeRIS.js
Normal file
31
chrome/content/scaffold/templates/scrapeRIS.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
function scrape(doc, url) {
|
||||
var DOI = url.match(/\/(10\.[^#?]+)/)[1];
|
||||
// TODO adjust the url here
|
||||
var risURL = "http://citation-needed.services.springer.com/v2/references/" + DOI + "?format=refman&flavour=citation";
|
||||
// Z.debug(risURL)
|
||||
|
||||
// TODO adjust the url here
|
||||
var pdfURL = doc.getElementById("articlePdf");
|
||||
// Z.debug("pdfURL: " + pdfURL);
|
||||
ZU.doGet(risURL, function (text) {
|
||||
var translator = Zotero.loadTranslator("import");
|
||||
translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
|
||||
translator.setString(text);
|
||||
translator.setHandler("itemDone", function (obj, item) {
|
||||
// TODO tweak some of the output here
|
||||
if (pdfURL) {
|
||||
item.attachments.push({
|
||||
url: pdfURL.href,
|
||||
title: "Full Text PDF",
|
||||
mimeType: "application/pdf"
|
||||
});
|
||||
}
|
||||
item.attachments.push({
|
||||
title: "Snapshot",
|
||||
document: doc
|
||||
});
|
||||
item.complete();
|
||||
});
|
||||
translator.translate();
|
||||
});
|
||||
}
|
11
chrome/content/scaffold/templates/shortcuts.txt
Normal file
11
chrome/content/scaffold/templates/shortcuts.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
Keyboard Shortcuts
|
||||
=============
|
||||
|
||||
Ctrl/Cmd S : Save
|
||||
|
||||
Ctrl/Cmd R : Run doWeb/doImport
|
||||
Ctrl/Cmd T : DetectWeb/detectImport
|
||||
|
||||
Ctrl/Cmd + : Increase Font Size
|
||||
Ctrl/Cmd - : Decrease Font Size
|
||||
Ctrl/Cmd 0 : Restore Font Size
|
Loading…
Add table
Add a link
Reference in a new issue