function detectWeb(doc, url) {
// TODO: adjust the logic here
if (url.includes('document')) {
return 'statute';
}
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('tr.clickable td a[href]');
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;
}
async function doWeb(doc, url) {
if (detectWeb(doc, url) == 'multiple') {
let items = await Zotero.selectItems(getSearchResults(doc, false));
Zotero.debug('items:' + JSON.stringify(items));
if (!items) return;
for (let url of Object.keys(items)) {
Zotero.debug('url:' + url);
await scrape(await requestDocument(url));
}
}
else {
await scrape(doc, url);
}
}
async function scrape(doc, url = doc.location.href) {
var newItem = new Zotero.Item("statute");
var statuteTitle = text(doc, 'title');
Zotero.debug('statuteTitle' + statuteTitle);
newItem.title = statuteTitle;
newItem.complete();
// TODO: add other zotero newItems
}