A New ACS Translator

I found many friends reported their troubles with ACS Translator after ACS web page modified, I also met some errors when I tried with it. So, I tried my best to resolve this problem and got a good result. Here is my new code for ACS publisher. It can scribe the search results page and an issue page, also PDF will be downloaded when you save an item.

Old codes was deleted. Try the updated ones.
  • Thanks for your work on this issue! I added a link to the trac ticket. https://www.zotero.org/trac/ticket/1242
  • edited January 15, 2009
    I updated the ACS tranlator after discussed with Dan Stillman about Wiley one. I think this one will be more efficient thank the old one.
    http://forums.zotero.org/discussion/5226/a-new-wiley-translator/#Item_11

    function detectWeb(doc, url) {
    var namespace = doc.documentElement.namespaceURI;
    var nsResolver = namespace ? function(prefix) {
    if (prefix == 'x') return namespace; else return null;
    } : null;

    if(doc.evaluate('//input[@id="articleListHeader_selectAllToc"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
    return "multiple";
    } else if (doc.evaluate('//div[@id="articleHead"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
    return "journalArticle";
    }
    return false;
    }

    function doWeb(doc, url){
    var namespace = doc.documentElement.namespaceURI;
    var nsResolver = namespace ? function(prefix) {
    if (prefix == 'x') return namespace; else return null;
    } : null;
    var host = 'http://' + doc.location.host + "/";
    //Zotero.debug(host);
    var m = url.match(/https?:\/\/[^\/]*\/doi\/(abs|full)\/(.+)/);
    var dois = new Array();
    if(detectWeb(doc, url) == "multiple") { //search
    var doi;
    var title;
    var availableItems = new Array();
    var xpath = '//div[@class="articleBox"]';
    if (doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
    elmts = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
    var elmt = elmts.iterateNext();
    do {
    title = doc.evaluate('./div[@class="articleBoxMeta"]/h2', elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
    doi = doc.evaluate('./div[@class="articleBoxMeta"]/h2/a/@href', elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent.replace("/doi/abs/","");
    if (doi.indexOf("prevSearch") != -1){
    doi = doi.substring(0,doi.indexOf("?"))
    }
    availableItems[doi] = title;
    } while (elmt = elmts.iterateNext())
    }
    var items = Zotero.selectItems(availableItems);
    if(!items) {
    return true;
    }
    for(var i in items) {
    dois.push(i);
    }
    } else if (m){ //single article
    dois.push(m[2]);
    //extrating journal abbreviation
    var ja = doc.evaluate('//div[@id="articleMeta"]/div[@id="citation"]/cite', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
    }

    var setupSets = [];
    for each (doi in dois) {
    var citUrl = host + 'action/showCitFormats?doi=' + doi;
    setupSets.push({ doi: doi, citUrl: citUrl });
    }

    var setupCallback = function () {
    //get citation export page's source code;
    if (setupSets.length) {
    var set = setupSets.shift();
    Zotero.Utilities.HTTP.doGet(set.citUrl, function(text){
    //get the exported RIS file name;
    var downloadFileName = text.match(/<input type="hidden" name="downloadFileName" value="([^>]+)" \/>/)[1];
    //Zotero.debug(downloadFileName);
    processCallback(set.doi,downloadFileName);
    });
    }
    else {
    Zotero.done();
    }
    }
    var processCallback = function (doi,downloadFileName) {
    var baseurl = "http://pubs.acs.org/action/downloadCitation";
    var post = "doi=" + doi + "&downloadFileName=" + downloadFileName + "&include=abs&format=refman&direct=on&submit=Download+article+citation+data";
    Zotero.Utilities.HTTP.doPost(baseurl, post,function(text){
    text = text.replace("N1 - doi:","M3 - doi:")
    var translator = Zotero.loadTranslator("import");
    translator.setTranslator("32d59d2d-b65a-4da4-b0a3-bdd3cfb979e7");
    translator.setString(text);
    translator.setHandler("itemDone", function(obj, item) {
    item.journalAbbreviation = ja;
    var pdfUrl = host + 'doi/pdf/' + doi;
    var fullTextUrl = host + 'doi/full/' + doi;
    item.attachments.push(
    {title:"ACS Full Text PDF",url:pdfUrl, mimeType:"application/pdf"},
    {url:fullTextUrl, title:"ACS Snapshot", mimeType:"text/html"}
    );
    item.complete();
    });
    translator.translate();
    setupCallback();
    });
    }
    setupCallback();
    Zotero.wait();
    }
  • santawort

    When I run this translator, it does not give a journal abbreviation for the ACS journals, Any theories?
  • smk

    ACS does not provide the journal abbreviation in the exported RIS file, so Z can't get it from the RIS file.
    I updated the codes above and it could get journal abbreviation. Enjoy it!
Sign In or Register to comment.