diff --git a/src/shared/js/utils/parsers.js b/src/shared/js/utils/parsers.js index e1ad5f07..7d568d15 100644 --- a/src/shared/js/utils/parsers.js +++ b/src/shared/js/utils/parsers.js @@ -1613,7 +1613,8 @@ const trySemanticScholar = async (paper) => { miniHash(match.title) === miniHash(paper.title) && Math.abs(match.year - paper.year) < 3 && match.venue && - !match.venue.toLowerCase().includes("arxiv") + !match.venue.toLowerCase().includes("arxiv") && + !match.venue.toLowerCase().includes("biorxiv") ) { info("Found a Semantic Scholar match"); let venue = match.venue diff --git a/src/shared/min/utils.min.js b/src/shared/min/utils.min.js index 70e93344..24b5c17f 100644 --- a/src/shared/min/utils.min.js +++ b/src/shared/min/utils.min.js @@ -29,4 +29,4 @@ Fix the json file and try again. `+`author={${i}}, `+`year={${a}}, `+`url={${t}}, -`+"}"},extractAPIv2ContentValue=e=>{const t={};let r=!1;for(var[i,a]of Object.entries(e.content))a&&a.value?(t[i]=a.value,r=!0):t[i]=a;return e.content=t,{isV2:r,paper:e}},makeOpenReviewPaper=async e=>{var t=await getOpenReviewNoteJSON(e),r=await getOpenReviewForumJSON(e);if(403===t.status&&"ForbiddenError"===t.name)throw logError(dedent(`Error parsing OpenReview url ${e}. Most likely because this entry is protected and you do not have the rights to access it. 1/ Make sure you are logged in. 2/ Alternatively, this may be due to OpenReview changing the visibility of this paper. Try accessing this URL manually to make sure.`)),Error(t.message);if(404===t.status&&"NotFoundError"===t.name)throw logError(dedent(`Error parsing OpenReview url ${e}.`)),Error(t.message);var t=t.notes[0],i=!1,r=r.notes,a=({isV2:i,paper:t}=extractAPIv2ContentValue(t),t.content.title),n=(t.content.authors||t.content.authors.value).join(" and "),o=bibtexToString(t.content._bibtex||makeOpenReviewBibTex(t,e)),s=bibtexToObject(o),l=s.citationKey,s=s.year;let c;c=t.pdf?"https://openreview.net/pdf?id="+t.id:(t.html||e).replace("/forum?id=","/pdf?id=");const p=t.invitation?.split("/")||t.domain.split("/");let u=p[0].split(".")[0],d=p.slice(1).join("/").split("-")[0].replaceAll("/"," ").replace(" Conference",""),h=u,f=!1;global.overrideORConfs.hasOwnProperty(u)&&(h=global.overrideORConfs[u],f=!0),f&&(d=d.replace(h,""),u=h);e=(u+" "+d).replace(/ \d\d\d\d/g,"").replace(/\s\s+/g," "),t=`OR-${u}-${s}_`+t.id;let m,g,y,b="";return(m=i?r.filter(e=>e?.content?.recommendation?.value):r.filter(e=>-1<["Final Decision","Paper Decision","Acceptance Decision"].indexOf(e?.content?.title)))&&00===t?cleanStr(e)+"ed":e).join(" "),y=g+` @ ${e} (${s})`,g.toLowerCase().indexOf("rejected")<0&&(b=e)),{author:n,bibtex:o,id:t,key:l,note:y="Anonymous"===n&&"Rejected"!=g?`Under review @ ${e} (${s}) (${(new Date).toLocaleDateString()})`:y,pdfLink:c,title:a,venue:b,year:s}},makeBioRxivPaper=async e=>{var t=e.replace(".full.pdf",""),r="https://api.biorxiv.org//details/biorxiv/"+e.split("/").slice(-2).join("/").replace(".full.pdf","").split("v")[0];const i=await fetch(r).then(e=>e.json());if("ok"!==i.messages[0].status)throw new Error(r+" returned "+i.messages[0].status);const a=i.collection.last(),n=await fetchText(t),o=(new DOMParser).parseFromString(n.replaceAll("\n",""),"text/html");r=o.querySelector(".bibtext a").getAttribute("href");const s=bibtexToString(await(await fetch(r)).text());var t=extractAuthor(s),r=await parseIdFromUrl(e),l=s.split("\n")[0].split("{")[1].replace(",","").trim(),e=cleanBiorxivURL(e)+".full.pdf",c=a.title,p=a.date.split("-")[0];return{author:t,bibtex:s,id:r,key:l,note:"",pdfLink:e,title:c,venue:"",year:p}},makePMLRPaper=async e=>{var t=e.split("/").last().split(".")[0],r=await parseIdFromUrl(e);const i=e.includes(".html")?e:e.split("/").slice(0,-2).join("/")+`/${t}.html`;e=i.replace(".html","")+`/${t}.pdf`;const a=await fetchDom(i),n=a.getElementById("bibtex").innerText.replaceAll("\t"," ").replaceAll(/\s\s+/g," ");let o=n;for(const d of n.match(/,\ ?\w+ ?= ?{/g))o=o.replace(d,d.replace(", ",",\n ").replace(" = ","="));o.endsWith("}}")&&(o=o.slice(0,-2)+"}\n}"),o=bibtexToString(o);var s=extractAuthor(o),l=a.getElementsByTagName("h1")[0].innerText,c=extractBibtexValue(o,"year");let p=extractBibtexValue(o,"booktitle").replaceAll("Proceedings of the",""),u=p;note=`Accepted @ ${u} (${c})`;for(const h in global.overridePMLRConfs)if(p.includes(h)){u=global.overridePMLRConfs[h],p=u+" "+c,note="Accepted @ "+p;break}return{author:s,bibtex:o,id:r,key:t,note:note,pdfLink:e,title:l,venue:u,year:c}},findACLValue=(e,t)=>{return queryAll("dt",e).filter(e=>e.innerText.includes(t))[0].nextElementSibling.innerText},makeACLPaper=async e=>{e=e.replace(".pdf","");const t=await fetchDom(e);e=t.getElementById("citeBibtexContent");if(e){var r=t.getElementById("title").innerText,e=bibtexToString(e.innerText);const l=bibtexToObject(e);var i=l.year,a=l.author.replace(/\s+/g," ").split(" and ").map(e=>e.split(",").map(e=>e.trim()).reverse().join(" ")).join(" and "),n=l.citationKey,o=findACLValue(t,"Venue"),s=findACLValue(t,"PDF");return{author:a,bibtex:e,id:`ACL-${o}-${i}_`+findACLValue(t,"Anthology ID"),key:n,note:`Accepted @ ${o} (${i})`,pdfLink:s,title:r,venue:o,year:i}}},makePNASPaper=async e=>{e=e.replace(".full.pdf","").replace(/\/doi\/e?pdf\//,"/doi/abs/");const t=await fetchDom(e);var r=t.getElementsByTagName("h1")[0].innerText,i=queryAll(".authors span[property='author'] a:not([property='email']):not(.orcid-id)",t).filter(e=>!e.getAttribute("href").includes("mailto:")).map(e=>e.innerText).join(" and "),a=t.querySelector("span[property='datePublished']").innerText.match(/\d{4}/g)[0],n=`PNAS-${a}_`+(e.endsWith("/")?e.split("/").slice(-2):e.split("/").slice(-1))[0];const o=e.includes("/doi/pdf/")||e.includes("/doi/epdf/")?e.replace("/doi/epdf/","/doi/pdf/"):e.replace("/doi/abs/","/doi/pdf/").replace("/doi/full/","/doi/pdf/");var e=[...t.querySelector(".core-container").getElementsByTagName("a")].map(e=>e.getAttribute("href")).filter(e=>e?.includes("https://doi.org"))[0].split("/").slice(-2).join("/"),s="doi:"+e;return{author:i,bibtex:bibtexToString(`@article{${s}, author={${i}}, title={${r}}, journal = {Proceedings of the National Academy of Sciences}, year={${a}}, doi={${e}}, eprint={${o}}, URL={${o.replace("/doi/pdf/","/doi/abs/")}} }`),id:n,key:s,note:`Published @ PNAS (${a})`,pdfLink:o,title:r,venue:"PNAS",year:a}},makeNaturePaper=async e=>{var t=(e=e.replace(".pdf","").split("#")[0])+".pdf",r=e.split("/").last();const i=await fetchDom(e);e=i.querySelector("h1.c-article-title").innerText;const a=queryAll("ul.c-article-author-list li",i).map(e=>e.innerText.replace(/(\ ?,)|&|…|\d/g,"").split(/orcid/i)[0].trim()).filter(e=>0e.innerText).filter(e=>e.includes("https://doi.org"))[0];var l=""+a.split(" ")[1]+n+firstNonStopLowercase(e);let c={citationKey:l,entryType:"article",author:a,title:e,journal:o,year:n};s&&(c.doi=s,c.url="https://doi.org/"+s);var p=bibtexToString(c);return{author:a,bibtex:p,id:r,key:l,note:`Published @ ${o} (${n})`,pdfLink:t,title:e,venue:o,year:n}},makeACSPaper=async e=>{const t=(e=e.replace("pubs.acs.org/doi/pdf/","pubs.acs.org/doi/").split("?")[0]).replace("/abs/","/").split("/doi/")[1];e=`https://pubs.acs.org/action/downloadCitation?doi=${t}&include=cit&format=bibtex&direct=true`,e=await fetchText(e);const r=bibtexToObject(e);var i=r.author.replaceAll("\n","").trim(),a=r.title.trim(),n=r.year.trim(),o=r.citationKey.trim(),s="https://pubs.acs.org/doi/pdf/"+t,l=`Published @ ${r.journal} (${r.year})`;return{author:i,bibtex:e,id:"ACS_"+t.replaceAll(".","").replaceAll("/",""),key:o,note:l,pdfLink:s,title:a,venue:r.journal,year:n}},makeIOPPaper=async e=>{(e=e.split("#")[0]).endsWith("/pdf")&&(e=e.slice(0,-4));var t=await fetchDom(e),t=queryAll(".btn-multi-block a",t).filter(e=>"BibTeX"===e.innerText).map(e=>e.getAttribute("href"))[0],t="https://"+parseUrl(e).host+t,t=await fetchText(t);const r=bibtexToObject(t);var i=r.author.replaceAll("\n","").trim(),a=r.title.trim(),n=r.year.trim(),o=r.citationKey.trim(),s=e+"/pdf",l=r.journal,c=`Published @ ${l} (${n})`,e=e.split("/article/").last().split("/meta")[0];return{author:i,bibtex:t,id:"IOPscience_"+miniHash(e),key:o,note:c,pdfLink:s,title:a,venue:l,year:n}},makeJMLRPaper=async e=>{var t=(e=(e=(e=e.includes("/papers/volume")?e.replace("/papers/volume","/papers/v"):e).endsWith(".pdf")?e.split("/").slice(0,-1).join("/"):e).replace(".html","")).split("/").last(),r=e+".bib",r=await fetchText(r);const{author:i,year:a,title:n,citationKey:o}=bibtexToObject(r);return{author:i,bibtex:r,id:`JMLR-${a}_`+t,key:o.trim(),note:`Published @ JMLR (${a})`,pdfLink:e.replace("/papers/v","/papers/volume")+`/${t}.pdf`,title:n,venue:"JMLR",year:a}},makePMCPaper=async e=>{var t=e.match(/PMC\d+/)[0].replace("PMC",""),r=e.split("PMC"+t)[0]+"PMC"+t;const i=await(await fetch(`https://api.ncbi.nlm.nih.gov/lit/ctxp/v1/pmc/?format=csl&id=${t}&download=true`)).json();var a=i["epub-date"]?i["epub-date"]["date-parts"][0][0]+"":i.issued["date-parts"][0][0]+"",n=i.author.map(e=>e.given+" "+e.family).join(" and "),o=i["container-title"].split(" ").map(e=>e.capitalize()).join(" "),s=i.title,t=`PMC-${a}_`+t,l=i.author[0].family+a+firstNonStopLowercase(s);let c;return{author:n,bibtex:bibtexToString({entryType:"article",citationKey:l,journal:o,issn:i.ISSN,volume:i.volume,page:i.page,doi:i.DOI,PMID:i.PMID,PMCID:i.PMCID,publisher:i.publisher,author:n,title:s}),id:t,key:l,note:`Published @ ${o} (${a})`,pdfLink:c=isPdfUrl(e)?e:r+"/pdf",title:s,venue:o,year:a}},makePubMedPaper=async e=>{const t=await fetchDom(e.split("?")[0]),r=[...t.getElementsByTagName("meta")].filter(e=>e.getAttribute("name")?.includes("citation_")),i=Object.fromEntries(r.map(e=>[e.getAttribute("name").replace("citation_",""),e.getAttribute("content")])),a=document.querySelector("div.authors-list").innerText.replace(/\d/gi,"").split(",").map(e=>e.trim()).join(" and ");var e=i.title,n=i.journal_title,o=i.date.split("/")[2],s=`PubMed-${o}_`+i.pmid,l=""+a.split(" and ")[0].split(" ").last()+o+firstNonStopLowercase(i.title),c={entryType:"article",citationKey:l,publisher:i.publisher,doi:i.doi,issn:i.issn,journal:n,year:o,author:a},c=bibtexToString(c),p=`Accepted @ ${journal} (${o})`;return{author:a,bibtex:c,id:s,key:l,note:p,pdfLink:"",title:e,venue:n,year:o}},makeIJCAIPaper=async e=>{const t=e.endsWith(".pdf")?e.replace(".pdf","").split("/").last().match(/[1-9]\d*/)[0]:e.split("/").last();e=e.match(/proceedings\/\d+/gi)[0].split("/")[1];const r=(await fetchText(`https://www.ijcai.org/proceedings/${e}/bibtex/`+t)).replace(/}\n/gi,"},\n");var i=bibtexToObject(r.split("\n").filter(e=>!/note\s+=/gi.test(e)).join("\n")),a=i.citationKey,n=i.title,i=flipAndAuthors(i.author),o=`IJCAI-${e}_`+t,s=`Accepted @ IJCAI (${e})`,l=t.padStart(4,0);return{author:i,bibtex:r,id:o,key:a,note:s,pdfLink:`https://www.ijcai.org/proceedings/${e}/${l}.pdf`,title:n,venue:"IJCAI",year:e}},makeACMPaper=async e=>{let t;t=isPdfUrl(e)?e:e.replace(/\/doi\/?(abs|full)?\//,"/doi/pdf/");const r=await fetchDom(e.replace("/doi/pdf/","/doi/"));let i,a,n,o,s,l,c,p;var u=extractDataFromDCMetaTags(r);if(u)({author:i,year:a,title:n,venue:o,key:s,doi:l,bibtex:c,note:p}=u);else{n=r.querySelector(".citation__title").innerText,i=queryAll("ul[ariaa-label='authors'] li.loa__item .loa__author-name",r).map(e=>e.innerText.replace(",","").trim()).join(" and ");const d=r.querySelector(".issue-item__detail a").innerText;o=d.split("'")[0].trim(),a="20"+d.split("'")[1].split(":")[0].trim(),l=t.split("/doi/pdf/")[1],p=`Accepted @ ${o} (${a})`,s=l,c=bibtexToString({entryType:"article",citationKey:l,journal:o,author:i,title:n,year:a,publisher:"Association for Computing Machinery",address:"New York, NY, USA",url:noParamUrl(e).replace("/doi/pdf/","/doi/")})}u=`ACM-${a}_`+miniHash(l);return{author:i,bibtex:c,id:u,key:s,note:p,pdfLink:t,title:n,venue:o,year:a}},makeIEEEPaper=async e=>{isPdfUrl(e)&&(e=`https://ieeexplore.ieee.org/document/${e.split("/stamp/stamp.jsp?tp=&arnumber=")[1].match(/\d+/)[0]}/`);const t=await fetchDom(e),r=JSON.parse([...t.getElementsByTagName("script")].filter(e=>e.innerHTML?.includes("metadata="))[0].innerHTML.split("metadata=")[1].split(/};\s*/)[0]+"}");var i=r.title,a=r.authors.map(e=>e.name).join(" and "),n=r.publicationYear,e=""+parseUrl(e).origin+r.pdfUrl,o=r.publicationTitle,s=r.articleId;return{author:a,bibtex:bibtexToString({entryType:"article",citationKey:s,journal:o,volume:r.volume,pages:r.startPage+"-"+r.endPage,doi:r.doi,title:i,year:n,author:a}),id:`IEEE-${n}_`+s,key:s,note:`Accepted @ ${o} (${n})`,pdfLink:e,title:i,venue:o,year:n}},makeSpringerPaper=async t=>{const e=[...global.sourceExtras.springer.types,"content/pdf"];var r=e.find(e=>t.includes(`/${e}/`));if(!r)throw new Error(`Could not find Springer type for ${t} (known: ${e.join(", ")})`);var i=t.split(`/${r}/`)[1].split("?")[0].replace(".pdf",""),a=(await fetchCrossRefDataForDoi(i))["data"];if(!a)throw new Error("Aborting Springer paper parsing, see error above");var{author:n,bibtex:o,citationKey:s,year:l,title:c,venue:p}=a;return{author:n,bibtex:o,id:`Springer-${l}_`+miniHash(i),key:s,note:`Published @ ${p} (${l})`,pdfLink:a.pdf??("content/pdf"===r?t:t.replace(`/${r}/`,"/content/pdf/")+".pdf"),title:c,venue:p,year:l,extra:{url:"https://doi.org/"+i}}},makeAPSPaper=async e=>{e=e.split("#")[0];var[t,r]=parseUrl(e).pathname.split("/").slice(1,3),i=e.split(`/${t}/${r}/`).last(),a=e.replace(`/${t}/${r}/`,`/${t}/export/`),a=await fetchText(a+"?type=bibtex&download=true"),n=bibtexToObject(a),e=e.replace(`/${t}/${r}/`,`/${t}/pdf/`),r=`APS-${n.year}_`+miniHash(i),t=n.journal??n.publisher,i=(await readJournalAbbreviations(),global.journalAbbreviations[miniHash(t)]??t),t=`Published @ ${i} (${n.year})`;return{author:flipAndAuthors(n.author),bibtex:a,id:r,key:n.citationKey,note:t,pdfLink:e,title:n.title,venue:i,year:n.year}},makeWileyPaper=async e=>{const t=e.replace(/\/doi\/(abs|epdf|full)\//g,"/doi/pdf/");e=t.replace("/doi/pdf/","/doi/abs/");const r=await fetchDom(e);var e=queryAll("meta[name=citation_author]",r).map(e=>e.getAttribute("content")).join(" and "),i=r.querySelector("meta[name=citation_journal_title]").getAttribute("content"),a=r.querySelector("meta[name=citation_title]").getAttribute("content"),n=r.querySelector("meta[name=citation_publisher]").getAttribute("content"),o=r.querySelector("meta[name=citation_publication_date]")?.getAttribute("content")?.split("/")[0]??r.querySelector("meta[name=citation_online_date]")?.getAttribute("content")?.split("/")[0],s=r.querySelector("meta[name=citation_doi]").getAttribute("content"),l=`Published @ ${i} (${o})`,c=`Wiley-${o}_`+miniHash(s);return{author:e,bibtex:bibtexToString({citationKey:s,entryType:"article",title:a,author:e,year:o,doi:s,publisher:n,journal:i}),id:c,key:s,note:l,pdfLink:t,title:a,venue:i,year:o}},makeScienceDirectPaper=async e=>{var e=e.split("/pii/")[1].split("/")[0].split("#")[0].split("?")[0],t=await fetchText(`https://www.sciencedirect.com/sdfe/arp/cite?pii=${e}&format=text%2Fx-bibtex&withabstract=false`),{author:r,journal:i,year:a,title:n,citationKey:o}=bibtexToObject(t),s=`Published @ ${i} (${a})`;return{author:r,bibtex:t,id:`ScienceDirect-${a}_`+miniHash(e),key:o,note:s,pdfLink:"https://reader.elsevier.com/reader/sd/pii/"+e,title:n,venue:i??"Science Direct",year:a}},makeSciencePaper=async e=>{let t,r,i,a,n,o,s,l,c,p,u;o="https://science.org/doi/pdf/"+(p=(p=noParamUrl(e).split("/doi/")[1]).startsWith("10.")?p:p.split("/").slice(1).join("/")),u="https://science.org/doi/full/"+p;var e=(await fetchCrossRefDataForDoi(p))["data"];return e?({author:t,bibtex:r,title:s,venue:l,year:c}=e,a=e.citationKey,n=`Published @ ${l} (${c})`):(e=await fetchDom(u),{author:t,year:c,publisher,title:s,venue:l,key:a,bibtex:r,note:n}=extractDataFromDCMetaTags(e)),i=`Science-${c}_`+miniHash(p),{author:t,bibtex:r,id:i,key:a,note:n,pdfLink:o,title:s,venue:l,year:c}},makeFrontiersPaper=async e=>{e=e.replace(/\/pdf$/,"/full");var t=noParamUrl(e).split("/articles/")[1].split("/full")[0],r=await fetchText(`https://www.frontiersin.org/articles/${t}/bibTex`);const i=Object.fromEntries(Object.entries(bibtexToObject(r)).map(([e,t])=>["citationKey"===e||"entryType"===e?e:e.toLowerCase(),t]));i.author=flipAndAuthors(i.author),delete i.abstract;var{author:r,journal:a,year:n,title:o,citationKey:s}=i,l=`Published @ ${a} (${n})`;return{author:r,bibtex:bibtexToString(i),id:`Frontiers-${n}_`+miniHash(t),key:s,note:l,pdfLink:e.replace(/\/full$/,"/pdf"),title:o,venue:a,year:n}},makeIHEPPaper=async t=>{let r,i;if(t.includes("/files/")){const d=t.split("/files/")[1].split("/")[0];var a="https://inspirehep.net/api/literature?q=documents.key:"+d;const e=(await fetchJSON(a)).data;if(!(r=e.hits.hits.find(e=>!!e.metadata.documents.find(e=>e.key===d))))return void warn("Could not find an Inspire HEP record for the url",t);i=r.metadata.control_number}else i=t.match(/\/literature\/(\d+)/)[1];if(i){var a=await fetchText(`https://inspirehep.net/api/literature/${i}?format=bibtex`),n=(r||({data:r}=await fetchJSON(`https://inspirehep.net/api/literature/${i}?format=json`)),bibtexToObject(a));let e=n.title??r.metadata.titles[0].title;e.startsWith("{")&&e.endsWith("}")&&(e=e.slice(1,-1));var o=r.metadata.documents?.[0]?.url??t,s=flipAndAuthors(n.author),l=n.year??r.created.split("-")[0],c="IHEP-"+i,p=n.journal??"Inspire HEP",u=n.citationKey,n=n.doi??"";return{author:s,bibtex:a,id:c,key:u,note:`Published @ ${p} (${l})`,pdfLink:o,title:e,venue:p,year:l,doi:n}}warn("Could not find an Inspire HEP id for the url",t)},makePLOSPaper=async e=>{var t=e.split("?id=").last().split("&")[0],{bibtex:r,key:i,author:a,venue:n,title:o,note:s,year:l}=await fetchBibtex(e.split("/article")[0]+"/article/citation/bibtex?id="+t),c=e.split("/article")[0]+`/article/file?id=${t}&type=printable`,e=e.split("journals.plos.org/")[1].split("/")[0];return{author:flipAndAuthors(a),bibtex:r,id:`PLOS-${e}_`+miniHash(t),key:i,note:s,pdfLink:c,title:o,venue:n,year:l,doi:t}},makeRSCPaper=async e=>{var t=noParamUrl(e).split("/").last(),r=e.split("/").find(e=>"articlehtml"===e||"articlepdf"===e||"articlelanding"===e).replace("article",""),e="articlepdf"===r?e:e.replace(`/article${r}/`,"/articlepdf/");let{bibtex:i,key:a,author:n,venue:o,title:s,note:l,year:c,doi:p}=await fetchBibtex(`https://pubs.rsc.org/en/content/formatedresult?markedids=${t}&downloadtype=article&managertype=bibtex`);return{author:flipAndAuthors(n),bibtex:i,id:`RSC-${o.replaceAll(" ","")}_`+miniHash(t),key:a,note:l,pdfLink:e,title:s,venue:o,year:c,doi:p}},makeWebsitePaper=async e=>{var t=e.url;const r=await fetchDom(t);var i=Object.fromEntries([...r.querySelectorAll("meta")].filter(e=>e.getAttribute("property")).filter(e=>e.getAttribute("property").startsWith("og:")).map(e=>[e.getAttribute("property").replace("og:",""),e.getAttribute("content")])),a=i.site_name||parseUrl(t).hostname.replace("www.","").capitalize(),n=(new Date).getFullYear()+"",o="Website_"+urlToWebsiteId(t),s=i.description||"",l=t,i=i.title||e.title,e=miniHash(a)+n+firstNonStopLowercase(i),t=`@misc{${e}, author = {${a}}, title = {${i}}, year = {${n}}, url = {${t}}, note = {Accessed ${(new Date).toISOString().split("T")[0]}} }`;return{author:a,bibtex:bibtexToString(bibtexToObject(t)),id:o,key:e,note:s,pdfLink:l,title:i,venue:"",year:n}},makeMDPIPaper=async e=>{(e=(e=(e=noParamUrl(e)).split("/").last().startsWith("pdf")?e.split("/").slice(0,-1).join("/"):e).endsWith("/notes")?e.replace("/notes",""):e).endsWith("/reprints")&&(e=e.replace("/reprints",""));var t=await fetchDom(e),{author:t,year:r,title:i,venue:a,key:n,doi:o,bibtex:s,note:l,pdfLink:c}=extractDataFromDCMetaTags(t);return{author:t,bibtex:s,id:`MDPI-${r}_`+miniHash(e.split("mdpi.com/")[1]),key:n,note:l,pdfLink:c,title:i,venue:a,year:r,doi:o}},tryPWCMatch=async e=>{let t;var r={type:"papersWithCode",pwcPrefs:await getStorage("pwcPrefs")??{},paper:e},{url:r,note:i,venue:a,pubYear:n}=await sendMessageToBackground(r)??{};return r&&!e.codeLink?log("[PapersWithCode] Discovered a code repository:",r):log("[PapersWithCode] No code repository found"),a&&!e.venue?(log("[PapersWithCode] Found a publication venue:",a),e=bibtexToObject(e.bibtex),t=bibtexToString({...e,year:n,journal:a})):log("[PapersWithCode] No publication found"),{codeLink:r,note:i,venue:a,bibtex:t}},tryCrossRef=async e=>{try{var t="https://api.crossref.org/works?rows=1&mailto=schmidtv%40mila.quebec&select=event%2Ctitle&query.title="+encodeURI(e.title);const i=await fetch(t).then(e=>e.json());if("ok"!==i.status)return log(`[Crossref] ${t} returned `+i.message.status),{note:null};if(0===i.message.items.length)return{note:null};if(i.message.items[0].title[0]?.toLowerCase().replaceAll("\n"," ").replaceAll(/\s\s+/g," ")!==e.title.toLowerCase().replaceAll("\n"," ").replaceAll(/\s\s+/g," "))return{note:null};if(!i.message.items[0].event||!i.message.items[0].event.name)return{note:null};info("Found a CrossRef match");var r=i.message.items[0].event.name.trim();return{venue:r,note:`Accepted @ ${r} -- [crossref.org]`}}catch(e){return logError("[Crossref]",e),{note:null}}},tryDBLP=async e=>{try{var t,r,i,a,n=encodeURI(e.title);const o=await fetch(`https://dblp.org/search/publ/api?q=${n}&format=json`);if(429===o.status)return{note:null,status:429};const s=await o.json();if(!(s.result&&s.result.hits&&s.result.hits.hit&&s.result.hits.hit.length))return{note:null};for(const l of s.result.hits.hit.sort((e,t)=>parseInt(e.info.year,10)-parseInt(t.info.year,10)))if(decodeHtml(l.info.title?.toLowerCase().replaceAll("\n"," ").replaceAll(".","").replaceAll(/\s\s+/g," "))===e.title.toLowerCase().replaceAll("\n"," ").replaceAll(".","").replaceAll(/\s\s+/g," ")&&"CoRR"!==l.info.venue)return info("Found a DBLP match"),t=await fetchText(l.info.url+".bib"),r=miniHash(l.info.venue),await readJournalAbbreviations(),i=(global.journalAbbreviations[r]??l.info.venue).trim(),a=l.info.year,l.info.url,{venue:i,note:`Accepted @ ${i} ${a} -- [dblp.org]`,bibtex:t};return{note:null}}catch(e){return logError("[DBLP]",e),{note:null}}},trySemanticScholar=async t=>{try{var{data:e,status:r}=await fetchJSON(`https://api.semanticscholar.org/graph/v1/paper/search?query=${encodeURI(t.title)}&fields=title,venue,year,authors,externalIds,url&limit=50`);if(e&&e.data&&0e.name).join(" and "),o=l.externalIds.DOI,s=bibtexToString({entryType:"article",citationKey:miniHash(l.authors[0].name.split(" ").last())+i+firstNonStopLowercase(t.title),title:t.title,author:n,journal:e,year:i,doi:o,bibSource:"Semantic Scholar "+l.url});return{venue:e,note:a,bibtex:s,status:r}}}catch(e){logError("[SemanticScholar]",e)}},tryGoogleScholar=async e=>{return await sendMessageToBackground({type:"google-scholar",paper:e})},tryPreprintMatch=async(e,t=!1)=>{let r,i,a,n,o={},s=["DBLP","SemanticScholar","CrossRef","GoogleScholar"],l=[silentPromiseTimeout(tryGoogleScholar(e)),silentPromiseTimeout(trySemanticScholar(e)),silentPromiseTimeout(tryCrossRef(e)),silentPromiseTimeout(tryDBLP(e))];t&&(l.push(silentPromiseTimeout(tryPWCMatch(e))),s.push("PapersWithCode"));for(var[c,p]of Object.entries(s)){if(o[p]=await l[c],{note:r,venue:i,bibtex:a}=o[p]??{},r)break;log(`[${p}] No publication found`)}return t&&(t="PapersWithCode",o.hasOwnProperty(t)||(o[t]=await l[t]),o[t].codeLink&&!e.codeLink&&(n=o[t].codeLink)),{note:r,venue:i,bibtex:a,code:n}},initPaper=async e=>{e.note||(e.note=""),e.md=`[${e.title}](${e.pdfLink})`,e.tags=[],e.codeLink=e.codeLink??"",e.favorite=!1,e.favoriteDate="",e.addDate=(new Date).toJSON(),e.lastOpenDate=e.addDate,e.count=1,e.code={};for(const t in e)e.hasOwnProperty(t)&&"string"==typeof e[t]&&(e[t]=e[t].trim());return e=await autoTagPaper(e),validatePaper(e),e},autoTagPaper=async r=>{try{var e,i,a=await getStorage("autoTags");if(!a||!a.length)return r;let t=new Set;for(const n of a)n.tags?.length&&(n.title||n.author)&&(e=!n.title||new RegExp(n.title,"i").test(r.title),i=!n.author||new RegExp(n.author,"i").test(r.author),e&&i&&n.tags.forEach(e=>t.add(e)));return r.tags=[...t].sort(),r.tags.length&&log("Automatically adding tags:",r.tags),r}catch(e){return log("Error auto-tagging:",e),log("Paper:",r),r}},makePaper=async(e,t,r=!1)=>{let i;if(r)(i=await makeWebsitePaper(r))&&(i.source="website");else if(e.arxiv)(i=await makeArxivPaper(t))&&(i.source="arxiv");else if(e.neurips)(i=await makeNeuripsPaper(t))&&(i.source="neurips");else if(e.cvf)(i=await makeCVFPaper(t))&&(i.source="cvf");else if(e.openreview)(i=await makeOpenReviewPaper(t))&&(i.source="openreview");else if(e.biorxiv)(i=await makeBioRxivPaper(t))&&(i.source="biorxiv");else if(e.pmlr)(i=await makePMLRPaper(t))&&(i.source="pmlr");else if(e.acl)(i=await makeACLPaper(t))&&(i.source="acl");else if(e.pnas)(i=await makePNASPaper(t))&&(i.source="pnas");else if(e.nature)(i=await makeNaturePaper(t))&&(i.source="nature");else if(e.acs)(i=await makeACSPaper(t))&&(i.source="acs");else if(e.iop)(i=await makeIOPPaper(t))&&(i.source="iop");else if(e.jmlr)(i=await makeJMLRPaper(t))&&(i.source="jmlr");else if(e.pmc)(i=await makePMCPaper(t))&&(i.source="pmc");else if(e.ijcai)(i=await makeIJCAIPaper(t))&&(i.source="ijcai");else if(e.acm)(i=await makeACMPaper(t))&&(i.source="acm");else if(e.ieee)(i=await makeIEEEPaper(t))&&(i.source="ieee");else if(e.springer)(i=await makeSpringerPaper(t))&&(i.source="springer");else if(e.aps)(i=await makeAPSPaper(t))&&(i.source="aps");else if(e.wiley)(i=await makeWileyPaper(t))&&(i.source="wiley");else if(e.sciencedirect)(i=await makeScienceDirectPaper(t))&&(i.source="sciencedirect");else if(e.science)(i=await makeSciencePaper(t))&&(i.source="science");else if(e.frontiers)(i=await makeFrontiersPaper(t))&&(i.source="frontiers");else if(e.ihep)(i=await makeIHEPPaper(t))&&(i.source="ihep");else if(e.plos)(i=await makePLOSPaper(t))&&(i.source="plos");else if(e.rsc)(i=await makeRSCPaper(t))&&(i.source="rsc");else{if(!e.mdpi)throw new Error("Unknown paper source: "+JSON.stringify({is:e,url:t}));(i=await makeMDPIPaper(t))&&(i.source="mdpi")}if(void 0!==i)return initPaper(i)},findFuzzyPaperMatch=(e,t)=>{t=miniHash(t.title);if(e.hasOwnProperty(t)){const r=e[t];e=r.find(t=>!global.preprintSources.some(e=>t.toLowerCase().startsWith(e)));return e?e:r[0]}return null};"undefined"!=typeof module&&null!=module.exports&&((dummyModule=module).exports={autoTagPaper:autoTagPaper,decodeHtml:decodeHtml,fetchArxivXML:fetchArxivXML,fetchCrossRefDataForDoi:fetchCrossRefDataForDoi,fetchCvfHTML:fetchCvfHTML,fetchDom:fetchDom,getOpenReviewForumJSON:getOpenReviewForumJSON,getOpenReviewNoteJSON:getOpenReviewNoteJSON,fetchSemanticScholarDataForDoi:fetchSemanticScholarDataForDoi,fetchText:fetchText,findACLValue:findACLValue,findFuzzyPaperMatch:findFuzzyPaperMatch,flipAndAuthors:flipAndAuthors,flipAuthor:flipAuthor,initPaper:initPaper,makeACLPaper:makeACLPaper,makeACMPaper:makeACMPaper,makeACSPaper:makeACSPaper,makeAPSPaper:makeAPSPaper,makeArxivPaper:makeArxivPaper,makeBioRxivPaper:makeBioRxivPaper,makeCVFPaper:makeCVFPaper,makeIEEEPaper:makeIEEEPaper,makeIJCAIPaper:makeIJCAIPaper,makeIOPPaper:makeIOPPaper,makeJMLRPaper:makeJMLRPaper,makeNaturePaper:makeNaturePaper,makeNeuripsPaper:makeNeuripsPaper,makeOpenReviewBibTex:makeOpenReviewBibTex,makeOpenReviewPaper:makeOpenReviewPaper,makePaper:makePaper,makePMCPaper:makePMCPaper,makePMLRPaper:makePMLRPaper,makePNASPaper:makePNASPaper,makePubMedPaper:makePubMedPaper,makePLOSPaper:makePLOSPaper,makeSpringerPaper:makeSpringerPaper,makeWileyPaper:makeWileyPaper,tryCrossRef:tryCrossRef,tryDBLP:tryDBLP,tryPreprintMatch:tryPreprintMatch,tryPWCMatch:tryPWCMatch,trySemanticScholar:trySemanticScholar}); \ No newline at end of file +`+"}"},extractAPIv2ContentValue=e=>{const t={};let r=!1;for(var[i,a]of Object.entries(e.content))a&&a.value?(t[i]=a.value,r=!0):t[i]=a;return e.content=t,{isV2:r,paper:e}},makeOpenReviewPaper=async e=>{var t=await getOpenReviewNoteJSON(e),r=await getOpenReviewForumJSON(e);if(403===t.status&&"ForbiddenError"===t.name)throw logError(dedent(`Error parsing OpenReview url ${e}. Most likely because this entry is protected and you do not have the rights to access it. 1/ Make sure you are logged in. 2/ Alternatively, this may be due to OpenReview changing the visibility of this paper. Try accessing this URL manually to make sure.`)),Error(t.message);if(404===t.status&&"NotFoundError"===t.name)throw logError(dedent(`Error parsing OpenReview url ${e}.`)),Error(t.message);var t=t.notes[0],i=!1,r=r.notes,a=({isV2:i,paper:t}=extractAPIv2ContentValue(t),t.content.title),n=(t.content.authors||t.content.authors.value).join(" and "),o=bibtexToString(t.content._bibtex||makeOpenReviewBibTex(t,e)),s=bibtexToObject(o),l=s.citationKey,s=s.year;let c;c=t.pdf?"https://openreview.net/pdf?id="+t.id:(t.html||e).replace("/forum?id=","/pdf?id=");const p=t.invitation?.split("/")||t.domain.split("/");let u=p[0].split(".")[0],d=p.slice(1).join("/").split("-")[0].replaceAll("/"," ").replace(" Conference",""),h=u,f=!1;global.overrideORConfs.hasOwnProperty(u)&&(h=global.overrideORConfs[u],f=!0),f&&(d=d.replace(h,""),u=h);e=(u+" "+d).replace(/ \d\d\d\d/g,"").replace(/\s\s+/g," "),t=`OR-${u}-${s}_`+t.id;let m,g,y,b="";return(m=i?r.filter(e=>e?.content?.recommendation?.value):r.filter(e=>-1<["Final Decision","Paper Decision","Acceptance Decision"].indexOf(e?.content?.title)))&&00===t?cleanStr(e)+"ed":e).join(" "),y=g+` @ ${e} (${s})`,g.toLowerCase().indexOf("rejected")<0&&(b=e)),{author:n,bibtex:o,id:t,key:l,note:y="Anonymous"===n&&"Rejected"!=g?`Under review @ ${e} (${s}) (${(new Date).toLocaleDateString()})`:y,pdfLink:c,title:a,venue:b,year:s}},makeBioRxivPaper=async e=>{var t=e.replace(".full.pdf",""),r="https://api.biorxiv.org//details/biorxiv/"+e.split("/").slice(-2).join("/").replace(".full.pdf","").split("v")[0];const i=await fetch(r).then(e=>e.json());if("ok"!==i.messages[0].status)throw new Error(r+" returned "+i.messages[0].status);const a=i.collection.last(),n=await fetchText(t),o=(new DOMParser).parseFromString(n.replaceAll("\n",""),"text/html");r=o.querySelector(".bibtext a").getAttribute("href");const s=bibtexToString(await(await fetch(r)).text());var t=extractAuthor(s),r=await parseIdFromUrl(e),l=s.split("\n")[0].split("{")[1].replace(",","").trim(),e=cleanBiorxivURL(e)+".full.pdf",c=a.title,p=a.date.split("-")[0];return{author:t,bibtex:s,id:r,key:l,note:"",pdfLink:e,title:c,venue:"",year:p}},makePMLRPaper=async e=>{var t=e.split("/").last().split(".")[0],r=await parseIdFromUrl(e);const i=e.includes(".html")?e:e.split("/").slice(0,-2).join("/")+`/${t}.html`;e=i.replace(".html","")+`/${t}.pdf`;const a=await fetchDom(i),n=a.getElementById("bibtex").innerText.replaceAll("\t"," ").replaceAll(/\s\s+/g," ");let o=n;for(const d of n.match(/,\ ?\w+ ?= ?{/g))o=o.replace(d,d.replace(", ",",\n ").replace(" = ","="));o.endsWith("}}")&&(o=o.slice(0,-2)+"}\n}"),o=bibtexToString(o);var s=extractAuthor(o),l=a.getElementsByTagName("h1")[0].innerText,c=extractBibtexValue(o,"year");let p=extractBibtexValue(o,"booktitle").replaceAll("Proceedings of the",""),u=p;note=`Accepted @ ${u} (${c})`;for(const h in global.overridePMLRConfs)if(p.includes(h)){u=global.overridePMLRConfs[h],p=u+" "+c,note="Accepted @ "+p;break}return{author:s,bibtex:o,id:r,key:t,note:note,pdfLink:e,title:l,venue:u,year:c}},findACLValue=(e,t)=>{return queryAll("dt",e).filter(e=>e.innerText.includes(t))[0].nextElementSibling.innerText},makeACLPaper=async e=>{e=e.replace(".pdf","");const t=await fetchDom(e);e=t.getElementById("citeBibtexContent");if(e){var r=t.getElementById("title").innerText,e=bibtexToString(e.innerText);const l=bibtexToObject(e);var i=l.year,a=l.author.replace(/\s+/g," ").split(" and ").map(e=>e.split(",").map(e=>e.trim()).reverse().join(" ")).join(" and "),n=l.citationKey,o=findACLValue(t,"Venue"),s=findACLValue(t,"PDF");return{author:a,bibtex:e,id:`ACL-${o}-${i}_`+findACLValue(t,"Anthology ID"),key:n,note:`Accepted @ ${o} (${i})`,pdfLink:s,title:r,venue:o,year:i}}},makePNASPaper=async e=>{e=e.replace(".full.pdf","").replace(/\/doi\/e?pdf\//,"/doi/abs/");const t=await fetchDom(e);var r=t.getElementsByTagName("h1")[0].innerText,i=queryAll(".authors span[property='author'] a:not([property='email']):not(.orcid-id)",t).filter(e=>!e.getAttribute("href").includes("mailto:")).map(e=>e.innerText).join(" and "),a=t.querySelector("span[property='datePublished']").innerText.match(/\d{4}/g)[0],n=`PNAS-${a}_`+(e.endsWith("/")?e.split("/").slice(-2):e.split("/").slice(-1))[0];const o=e.includes("/doi/pdf/")||e.includes("/doi/epdf/")?e.replace("/doi/epdf/","/doi/pdf/"):e.replace("/doi/abs/","/doi/pdf/").replace("/doi/full/","/doi/pdf/");var e=[...t.querySelector(".core-container").getElementsByTagName("a")].map(e=>e.getAttribute("href")).filter(e=>e?.includes("https://doi.org"))[0].split("/").slice(-2).join("/"),s="doi:"+e;return{author:i,bibtex:bibtexToString(`@article{${s}, author={${i}}, title={${r}}, journal = {Proceedings of the National Academy of Sciences}, year={${a}}, doi={${e}}, eprint={${o}}, URL={${o.replace("/doi/pdf/","/doi/abs/")}} }`),id:n,key:s,note:`Published @ PNAS (${a})`,pdfLink:o,title:r,venue:"PNAS",year:a}},makeNaturePaper=async e=>{var t=(e=e.replace(".pdf","").split("#")[0])+".pdf",r=e.split("/").last();const i=await fetchDom(e);e=i.querySelector("h1.c-article-title").innerText;const a=queryAll("ul.c-article-author-list li",i).map(e=>e.innerText.replace(/(\ ?,)|&|…|\d/g,"").split(/orcid/i)[0].trim()).filter(e=>0e.innerText).filter(e=>e.includes("https://doi.org"))[0];var l=""+a.split(" ")[1]+n+firstNonStopLowercase(e);let c={citationKey:l,entryType:"article",author:a,title:e,journal:o,year:n};s&&(c.doi=s,c.url="https://doi.org/"+s);var p=bibtexToString(c);return{author:a,bibtex:p,id:r,key:l,note:`Published @ ${o} (${n})`,pdfLink:t,title:e,venue:o,year:n}},makeACSPaper=async e=>{const t=(e=e.replace("pubs.acs.org/doi/pdf/","pubs.acs.org/doi/").split("?")[0]).replace("/abs/","/").split("/doi/")[1];e=`https://pubs.acs.org/action/downloadCitation?doi=${t}&include=cit&format=bibtex&direct=true`,e=await fetchText(e);const r=bibtexToObject(e);var i=r.author.replaceAll("\n","").trim(),a=r.title.trim(),n=r.year.trim(),o=r.citationKey.trim(),s="https://pubs.acs.org/doi/pdf/"+t,l=`Published @ ${r.journal} (${r.year})`;return{author:i,bibtex:e,id:"ACS_"+t.replaceAll(".","").replaceAll("/",""),key:o,note:l,pdfLink:s,title:a,venue:r.journal,year:n}},makeIOPPaper=async e=>{(e=e.split("#")[0]).endsWith("/pdf")&&(e=e.slice(0,-4));var t=await fetchDom(e),t=queryAll(".btn-multi-block a",t).filter(e=>"BibTeX"===e.innerText).map(e=>e.getAttribute("href"))[0],t="https://"+parseUrl(e).host+t,t=await fetchText(t);const r=bibtexToObject(t);var i=r.author.replaceAll("\n","").trim(),a=r.title.trim(),n=r.year.trim(),o=r.citationKey.trim(),s=e+"/pdf",l=r.journal,c=`Published @ ${l} (${n})`,e=e.split("/article/").last().split("/meta")[0];return{author:i,bibtex:t,id:"IOPscience_"+miniHash(e),key:o,note:c,pdfLink:s,title:a,venue:l,year:n}},makeJMLRPaper=async e=>{var t=(e=(e=(e=e.includes("/papers/volume")?e.replace("/papers/volume","/papers/v"):e).endsWith(".pdf")?e.split("/").slice(0,-1).join("/"):e).replace(".html","")).split("/").last(),r=e+".bib",r=await fetchText(r);const{author:i,year:a,title:n,citationKey:o}=bibtexToObject(r);return{author:i,bibtex:r,id:`JMLR-${a}_`+t,key:o.trim(),note:`Published @ JMLR (${a})`,pdfLink:e.replace("/papers/v","/papers/volume")+`/${t}.pdf`,title:n,venue:"JMLR",year:a}},makePMCPaper=async e=>{var t=e.match(/PMC\d+/)[0].replace("PMC",""),r=e.split("PMC"+t)[0]+"PMC"+t;const i=await(await fetch(`https://api.ncbi.nlm.nih.gov/lit/ctxp/v1/pmc/?format=csl&id=${t}&download=true`)).json();var a=i["epub-date"]?i["epub-date"]["date-parts"][0][0]+"":i.issued["date-parts"][0][0]+"",n=i.author.map(e=>e.given+" "+e.family).join(" and "),o=i["container-title"].split(" ").map(e=>e.capitalize()).join(" "),s=i.title,t=`PMC-${a}_`+t,l=i.author[0].family+a+firstNonStopLowercase(s);let c;return{author:n,bibtex:bibtexToString({entryType:"article",citationKey:l,journal:o,issn:i.ISSN,volume:i.volume,page:i.page,doi:i.DOI,PMID:i.PMID,PMCID:i.PMCID,publisher:i.publisher,author:n,title:s}),id:t,key:l,note:`Published @ ${o} (${a})`,pdfLink:c=isPdfUrl(e)?e:r+"/pdf",title:s,venue:o,year:a}},makePubMedPaper=async e=>{const t=await fetchDom(e.split("?")[0]),r=[...t.getElementsByTagName("meta")].filter(e=>e.getAttribute("name")?.includes("citation_")),i=Object.fromEntries(r.map(e=>[e.getAttribute("name").replace("citation_",""),e.getAttribute("content")])),a=document.querySelector("div.authors-list").innerText.replace(/\d/gi,"").split(",").map(e=>e.trim()).join(" and ");var e=i.title,n=i.journal_title,o=i.date.split("/")[2],s=`PubMed-${o}_`+i.pmid,l=""+a.split(" and ")[0].split(" ").last()+o+firstNonStopLowercase(i.title),c={entryType:"article",citationKey:l,publisher:i.publisher,doi:i.doi,issn:i.issn,journal:n,year:o,author:a},c=bibtexToString(c),p=`Accepted @ ${journal} (${o})`;return{author:a,bibtex:c,id:s,key:l,note:p,pdfLink:"",title:e,venue:n,year:o}},makeIJCAIPaper=async e=>{const t=e.endsWith(".pdf")?e.replace(".pdf","").split("/").last().match(/[1-9]\d*/)[0]:e.split("/").last();e=e.match(/proceedings\/\d+/gi)[0].split("/")[1];const r=(await fetchText(`https://www.ijcai.org/proceedings/${e}/bibtex/`+t)).replace(/}\n/gi,"},\n");var i=bibtexToObject(r.split("\n").filter(e=>!/note\s+=/gi.test(e)).join("\n")),a=i.citationKey,n=i.title,i=flipAndAuthors(i.author),o=`IJCAI-${e}_`+t,s=`Accepted @ IJCAI (${e})`,l=t.padStart(4,0);return{author:i,bibtex:r,id:o,key:a,note:s,pdfLink:`https://www.ijcai.org/proceedings/${e}/${l}.pdf`,title:n,venue:"IJCAI",year:e}},makeACMPaper=async e=>{let t;t=isPdfUrl(e)?e:e.replace(/\/doi\/?(abs|full)?\//,"/doi/pdf/");const r=await fetchDom(e.replace("/doi/pdf/","/doi/"));let i,a,n,o,s,l,c,p;var u=extractDataFromDCMetaTags(r);if(u)({author:i,year:a,title:n,venue:o,key:s,doi:l,bibtex:c,note:p}=u);else{n=r.querySelector(".citation__title").innerText,i=queryAll("ul[ariaa-label='authors'] li.loa__item .loa__author-name",r).map(e=>e.innerText.replace(",","").trim()).join(" and ");const d=r.querySelector(".issue-item__detail a").innerText;o=d.split("'")[0].trim(),a="20"+d.split("'")[1].split(":")[0].trim(),l=t.split("/doi/pdf/")[1],p=`Accepted @ ${o} (${a})`,s=l,c=bibtexToString({entryType:"article",citationKey:l,journal:o,author:i,title:n,year:a,publisher:"Association for Computing Machinery",address:"New York, NY, USA",url:noParamUrl(e).replace("/doi/pdf/","/doi/")})}u=`ACM-${a}_`+miniHash(l);return{author:i,bibtex:c,id:u,key:s,note:p,pdfLink:t,title:n,venue:o,year:a}},makeIEEEPaper=async e=>{isPdfUrl(e)&&(e=`https://ieeexplore.ieee.org/document/${e.split("/stamp/stamp.jsp?tp=&arnumber=")[1].match(/\d+/)[0]}/`);const t=await fetchDom(e),r=JSON.parse([...t.getElementsByTagName("script")].filter(e=>e.innerHTML?.includes("metadata="))[0].innerHTML.split("metadata=")[1].split(/};\s*/)[0]+"}");var i=r.title,a=r.authors.map(e=>e.name).join(" and "),n=r.publicationYear,e=""+parseUrl(e).origin+r.pdfUrl,o=r.publicationTitle,s=r.articleId;return{author:a,bibtex:bibtexToString({entryType:"article",citationKey:s,journal:o,volume:r.volume,pages:r.startPage+"-"+r.endPage,doi:r.doi,title:i,year:n,author:a}),id:`IEEE-${n}_`+s,key:s,note:`Accepted @ ${o} (${n})`,pdfLink:e,title:i,venue:o,year:n}},makeSpringerPaper=async t=>{const e=[...global.sourceExtras.springer.types,"content/pdf"];var r=e.find(e=>t.includes(`/${e}/`));if(!r)throw new Error(`Could not find Springer type for ${t} (known: ${e.join(", ")})`);var i=t.split(`/${r}/`)[1].split("?")[0].replace(".pdf",""),a=(await fetchCrossRefDataForDoi(i))["data"];if(!a)throw new Error("Aborting Springer paper parsing, see error above");var{author:n,bibtex:o,citationKey:s,year:l,title:c,venue:p}=a;return{author:n,bibtex:o,id:`Springer-${l}_`+miniHash(i),key:s,note:`Published @ ${p} (${l})`,pdfLink:a.pdf??("content/pdf"===r?t:t.replace(`/${r}/`,"/content/pdf/")+".pdf"),title:c,venue:p,year:l,extra:{url:"https://doi.org/"+i}}},makeAPSPaper=async e=>{e=e.split("#")[0];var[t,r]=parseUrl(e).pathname.split("/").slice(1,3),i=e.split(`/${t}/${r}/`).last(),a=e.replace(`/${t}/${r}/`,`/${t}/export/`),a=await fetchText(a+"?type=bibtex&download=true"),n=bibtexToObject(a),e=e.replace(`/${t}/${r}/`,`/${t}/pdf/`),r=`APS-${n.year}_`+miniHash(i),t=n.journal??n.publisher,i=(await readJournalAbbreviations(),global.journalAbbreviations[miniHash(t)]??t),t=`Published @ ${i} (${n.year})`;return{author:flipAndAuthors(n.author),bibtex:a,id:r,key:n.citationKey,note:t,pdfLink:e,title:n.title,venue:i,year:n.year}},makeWileyPaper=async e=>{const t=e.replace(/\/doi\/(abs|epdf|full)\//g,"/doi/pdf/");e=t.replace("/doi/pdf/","/doi/abs/");const r=await fetchDom(e);var e=queryAll("meta[name=citation_author]",r).map(e=>e.getAttribute("content")).join(" and "),i=r.querySelector("meta[name=citation_journal_title]").getAttribute("content"),a=r.querySelector("meta[name=citation_title]").getAttribute("content"),n=r.querySelector("meta[name=citation_publisher]").getAttribute("content"),o=r.querySelector("meta[name=citation_publication_date]")?.getAttribute("content")?.split("/")[0]??r.querySelector("meta[name=citation_online_date]")?.getAttribute("content")?.split("/")[0],s=r.querySelector("meta[name=citation_doi]").getAttribute("content"),l=`Published @ ${i} (${o})`,c=`Wiley-${o}_`+miniHash(s);return{author:e,bibtex:bibtexToString({citationKey:s,entryType:"article",title:a,author:e,year:o,doi:s,publisher:n,journal:i}),id:c,key:s,note:l,pdfLink:t,title:a,venue:i,year:o}},makeScienceDirectPaper=async e=>{var e=e.split("/pii/")[1].split("/")[0].split("#")[0].split("?")[0],t=await fetchText(`https://www.sciencedirect.com/sdfe/arp/cite?pii=${e}&format=text%2Fx-bibtex&withabstract=false`),{author:r,journal:i,year:a,title:n,citationKey:o}=bibtexToObject(t),s=`Published @ ${i} (${a})`;return{author:r,bibtex:t,id:`ScienceDirect-${a}_`+miniHash(e),key:o,note:s,pdfLink:"https://reader.elsevier.com/reader/sd/pii/"+e,title:n,venue:i??"Science Direct",year:a}},makeSciencePaper=async e=>{let t,r,i,a,n,o,s,l,c,p,u;o="https://science.org/doi/pdf/"+(p=(p=noParamUrl(e).split("/doi/")[1]).startsWith("10.")?p:p.split("/").slice(1).join("/")),u="https://science.org/doi/full/"+p;var e=(await fetchCrossRefDataForDoi(p))["data"];return e?({author:t,bibtex:r,title:s,venue:l,year:c}=e,a=e.citationKey,n=`Published @ ${l} (${c})`):(e=await fetchDom(u),{author:t,year:c,publisher,title:s,venue:l,key:a,bibtex:r,note:n}=extractDataFromDCMetaTags(e)),i=`Science-${c}_`+miniHash(p),{author:t,bibtex:r,id:i,key:a,note:n,pdfLink:o,title:s,venue:l,year:c}},makeFrontiersPaper=async e=>{e=e.replace(/\/pdf$/,"/full");var t=noParamUrl(e).split("/articles/")[1].split("/full")[0],r=await fetchText(`https://www.frontiersin.org/articles/${t}/bibTex`);const i=Object.fromEntries(Object.entries(bibtexToObject(r)).map(([e,t])=>["citationKey"===e||"entryType"===e?e:e.toLowerCase(),t]));i.author=flipAndAuthors(i.author),delete i.abstract;var{author:r,journal:a,year:n,title:o,citationKey:s}=i,l=`Published @ ${a} (${n})`;return{author:r,bibtex:bibtexToString(i),id:`Frontiers-${n}_`+miniHash(t),key:s,note:l,pdfLink:e.replace(/\/full$/,"/pdf"),title:o,venue:a,year:n}},makeIHEPPaper=async t=>{let r,i;if(t.includes("/files/")){const d=t.split("/files/")[1].split("/")[0];var a="https://inspirehep.net/api/literature?q=documents.key:"+d;const e=(await fetchJSON(a)).data;if(!(r=e.hits.hits.find(e=>!!e.metadata.documents.find(e=>e.key===d))))return void warn("Could not find an Inspire HEP record for the url",t);i=r.metadata.control_number}else i=t.match(/\/literature\/(\d+)/)[1];if(i){var a=await fetchText(`https://inspirehep.net/api/literature/${i}?format=bibtex`),n=(r||({data:r}=await fetchJSON(`https://inspirehep.net/api/literature/${i}?format=json`)),bibtexToObject(a));let e=n.title??r.metadata.titles[0].title;e.startsWith("{")&&e.endsWith("}")&&(e=e.slice(1,-1));var o=r.metadata.documents?.[0]?.url??t,s=flipAndAuthors(n.author),l=n.year??r.created.split("-")[0],c="IHEP-"+i,p=n.journal??"Inspire HEP",u=n.citationKey,n=n.doi??"";return{author:s,bibtex:a,id:c,key:u,note:`Published @ ${p} (${l})`,pdfLink:o,title:e,venue:p,year:l,doi:n}}warn("Could not find an Inspire HEP id for the url",t)},makePLOSPaper=async e=>{var t=e.split("?id=").last().split("&")[0],{bibtex:r,key:i,author:a,venue:n,title:o,note:s,year:l}=await fetchBibtex(e.split("/article")[0]+"/article/citation/bibtex?id="+t),c=e.split("/article")[0]+`/article/file?id=${t}&type=printable`,e=e.split("journals.plos.org/")[1].split("/")[0];return{author:flipAndAuthors(a),bibtex:r,id:`PLOS-${e}_`+miniHash(t),key:i,note:s,pdfLink:c,title:o,venue:n,year:l,doi:t}},makeRSCPaper=async e=>{var t=noParamUrl(e).split("/").last(),r=e.split("/").find(e=>"articlehtml"===e||"articlepdf"===e||"articlelanding"===e).replace("article",""),e="articlepdf"===r?e:e.replace(`/article${r}/`,"/articlepdf/");let{bibtex:i,key:a,author:n,venue:o,title:s,note:l,year:c,doi:p}=await fetchBibtex(`https://pubs.rsc.org/en/content/formatedresult?markedids=${t}&downloadtype=article&managertype=bibtex`);return{author:flipAndAuthors(n),bibtex:i,id:`RSC-${o.replaceAll(" ","")}_`+miniHash(t),key:a,note:l,pdfLink:e,title:s,venue:o,year:c,doi:p}},makeWebsitePaper=async e=>{var t=e.url;const r=await fetchDom(t);var i=Object.fromEntries([...r.querySelectorAll("meta")].filter(e=>e.getAttribute("property")).filter(e=>e.getAttribute("property").startsWith("og:")).map(e=>[e.getAttribute("property").replace("og:",""),e.getAttribute("content")])),a=i.site_name||parseUrl(t).hostname.replace("www.","").capitalize(),n=(new Date).getFullYear()+"",o="Website_"+urlToWebsiteId(t),s=i.description||"",l=t,i=i.title||e.title,e=miniHash(a)+n+firstNonStopLowercase(i),t=`@misc{${e}, author = {${a}}, title = {${i}}, year = {${n}}, url = {${t}}, note = {Accessed ${(new Date).toISOString().split("T")[0]}} }`;return{author:a,bibtex:bibtexToString(bibtexToObject(t)),id:o,key:e,note:s,pdfLink:l,title:i,venue:"",year:n}},makeMDPIPaper=async e=>{(e=(e=(e=noParamUrl(e)).split("/").last().startsWith("pdf")?e.split("/").slice(0,-1).join("/"):e).endsWith("/notes")?e.replace("/notes",""):e).endsWith("/reprints")&&(e=e.replace("/reprints",""));var t=await fetchDom(e),{author:t,year:r,title:i,venue:a,key:n,doi:o,bibtex:s,note:l,pdfLink:c}=extractDataFromDCMetaTags(t);return{author:t,bibtex:s,id:`MDPI-${r}_`+miniHash(e.split("mdpi.com/")[1]),key:n,note:l,pdfLink:c,title:i,venue:a,year:r,doi:o}},tryPWCMatch=async e=>{let t;var r={type:"papersWithCode",pwcPrefs:await getStorage("pwcPrefs")??{},paper:e},{url:r,note:i,venue:a,pubYear:n}=await sendMessageToBackground(r)??{};return r&&!e.codeLink?log("[PapersWithCode] Discovered a code repository:",r):log("[PapersWithCode] No code repository found"),a&&!e.venue?(log("[PapersWithCode] Found a publication venue:",a),e=bibtexToObject(e.bibtex),t=bibtexToString({...e,year:n,journal:a})):log("[PapersWithCode] No publication found"),{codeLink:r,note:i,venue:a,bibtex:t}},tryCrossRef=async e=>{try{var t="https://api.crossref.org/works?rows=1&mailto=schmidtv%40mila.quebec&select=event%2Ctitle&query.title="+encodeURI(e.title);const i=await fetch(t).then(e=>e.json());if("ok"!==i.status)return log(`[Crossref] ${t} returned `+i.message.status),{note:null};if(0===i.message.items.length)return{note:null};if(i.message.items[0].title[0]?.toLowerCase().replaceAll("\n"," ").replaceAll(/\s\s+/g," ")!==e.title.toLowerCase().replaceAll("\n"," ").replaceAll(/\s\s+/g," "))return{note:null};if(!i.message.items[0].event||!i.message.items[0].event.name)return{note:null};info("Found a CrossRef match");var r=i.message.items[0].event.name.trim();return{venue:r,note:`Accepted @ ${r} -- [crossref.org]`}}catch(e){return logError("[Crossref]",e),{note:null}}},tryDBLP=async e=>{try{var t,r,i,a,n=encodeURI(e.title);const o=await fetch(`https://dblp.org/search/publ/api?q=${n}&format=json`);if(429===o.status)return{note:null,status:429};const s=await o.json();if(!(s.result&&s.result.hits&&s.result.hits.hit&&s.result.hits.hit.length))return{note:null};for(const l of s.result.hits.hit.sort((e,t)=>parseInt(e.info.year,10)-parseInt(t.info.year,10)))if(decodeHtml(l.info.title?.toLowerCase().replaceAll("\n"," ").replaceAll(".","").replaceAll(/\s\s+/g," "))===e.title.toLowerCase().replaceAll("\n"," ").replaceAll(".","").replaceAll(/\s\s+/g," ")&&"CoRR"!==l.info.venue)return info("Found a DBLP match"),t=await fetchText(l.info.url+".bib"),r=miniHash(l.info.venue),await readJournalAbbreviations(),i=(global.journalAbbreviations[r]??l.info.venue).trim(),a=l.info.year,l.info.url,{venue:i,note:`Accepted @ ${i} ${a} -- [dblp.org]`,bibtex:t};return{note:null}}catch(e){return logError("[DBLP]",e),{note:null}}},trySemanticScholar=async t=>{try{var{data:e,status:r}=await fetchJSON(`https://api.semanticscholar.org/graph/v1/paper/search?query=${encodeURI(t.title)}&fields=title,venue,year,authors,externalIds,url&limit=50`);if(e&&e.data&&0e.name).join(" and "),o=l.externalIds.DOI,s=bibtexToString({entryType:"article",citationKey:miniHash(l.authors[0].name.split(" ").last())+i+firstNonStopLowercase(t.title),title:t.title,author:n,journal:e,year:i,doi:o,bibSource:"Semantic Scholar "+l.url});return{venue:e,note:a,bibtex:s,status:r}}}catch(e){logError("[SemanticScholar]",e)}},tryGoogleScholar=async e=>{return await sendMessageToBackground({type:"google-scholar",paper:e})},tryPreprintMatch=async(e,t=!1)=>{let r,i,a,n,o={},s=["DBLP","SemanticScholar","CrossRef","GoogleScholar"],l=[silentPromiseTimeout(tryGoogleScholar(e)),silentPromiseTimeout(trySemanticScholar(e)),silentPromiseTimeout(tryCrossRef(e)),silentPromiseTimeout(tryDBLP(e))];t&&(l.push(silentPromiseTimeout(tryPWCMatch(e))),s.push("PapersWithCode"));for(var[c,p]of Object.entries(s)){if(o[p]=await l[c],{note:r,venue:i,bibtex:a}=o[p]??{},r)break;log(`[${p}] No publication found`)}return t&&(t="PapersWithCode",o.hasOwnProperty(t)||(o[t]=await l[t]),o[t].codeLink&&!e.codeLink&&(n=o[t].codeLink)),{note:r,venue:i,bibtex:a,code:n}},initPaper=async e=>{e.note||(e.note=""),e.md=`[${e.title}](${e.pdfLink})`,e.tags=[],e.codeLink=e.codeLink??"",e.favorite=!1,e.favoriteDate="",e.addDate=(new Date).toJSON(),e.lastOpenDate=e.addDate,e.count=1,e.code={};for(const t in e)e.hasOwnProperty(t)&&"string"==typeof e[t]&&(e[t]=e[t].trim());return e=await autoTagPaper(e),validatePaper(e),e},autoTagPaper=async r=>{try{var e,i,a=await getStorage("autoTags");if(!a||!a.length)return r;let t=new Set;for(const n of a)n.tags?.length&&(n.title||n.author)&&(e=!n.title||new RegExp(n.title,"i").test(r.title),i=!n.author||new RegExp(n.author,"i").test(r.author),e&&i&&n.tags.forEach(e=>t.add(e)));return r.tags=[...t].sort(),r.tags.length&&log("Automatically adding tags:",r.tags),r}catch(e){return log("Error auto-tagging:",e),log("Paper:",r),r}},makePaper=async(e,t,r=!1)=>{let i;if(r)(i=await makeWebsitePaper(r))&&(i.source="website");else if(e.arxiv)(i=await makeArxivPaper(t))&&(i.source="arxiv");else if(e.neurips)(i=await makeNeuripsPaper(t))&&(i.source="neurips");else if(e.cvf)(i=await makeCVFPaper(t))&&(i.source="cvf");else if(e.openreview)(i=await makeOpenReviewPaper(t))&&(i.source="openreview");else if(e.biorxiv)(i=await makeBioRxivPaper(t))&&(i.source="biorxiv");else if(e.pmlr)(i=await makePMLRPaper(t))&&(i.source="pmlr");else if(e.acl)(i=await makeACLPaper(t))&&(i.source="acl");else if(e.pnas)(i=await makePNASPaper(t))&&(i.source="pnas");else if(e.nature)(i=await makeNaturePaper(t))&&(i.source="nature");else if(e.acs)(i=await makeACSPaper(t))&&(i.source="acs");else if(e.iop)(i=await makeIOPPaper(t))&&(i.source="iop");else if(e.jmlr)(i=await makeJMLRPaper(t))&&(i.source="jmlr");else if(e.pmc)(i=await makePMCPaper(t))&&(i.source="pmc");else if(e.ijcai)(i=await makeIJCAIPaper(t))&&(i.source="ijcai");else if(e.acm)(i=await makeACMPaper(t))&&(i.source="acm");else if(e.ieee)(i=await makeIEEEPaper(t))&&(i.source="ieee");else if(e.springer)(i=await makeSpringerPaper(t))&&(i.source="springer");else if(e.aps)(i=await makeAPSPaper(t))&&(i.source="aps");else if(e.wiley)(i=await makeWileyPaper(t))&&(i.source="wiley");else if(e.sciencedirect)(i=await makeScienceDirectPaper(t))&&(i.source="sciencedirect");else if(e.science)(i=await makeSciencePaper(t))&&(i.source="science");else if(e.frontiers)(i=await makeFrontiersPaper(t))&&(i.source="frontiers");else if(e.ihep)(i=await makeIHEPPaper(t))&&(i.source="ihep");else if(e.plos)(i=await makePLOSPaper(t))&&(i.source="plos");else if(e.rsc)(i=await makeRSCPaper(t))&&(i.source="rsc");else{if(!e.mdpi)throw new Error("Unknown paper source: "+JSON.stringify({is:e,url:t}));(i=await makeMDPIPaper(t))&&(i.source="mdpi")}if(void 0!==i)return initPaper(i)},findFuzzyPaperMatch=(e,t)=>{t=miniHash(t.title);if(e.hasOwnProperty(t)){const r=e[t];e=r.find(t=>!global.preprintSources.some(e=>t.toLowerCase().startsWith(e)));return e?e:r[0]}return null};"undefined"!=typeof module&&null!=module.exports&&((dummyModule=module).exports={autoTagPaper:autoTagPaper,decodeHtml:decodeHtml,fetchArxivXML:fetchArxivXML,fetchCrossRefDataForDoi:fetchCrossRefDataForDoi,fetchCvfHTML:fetchCvfHTML,fetchDom:fetchDom,getOpenReviewForumJSON:getOpenReviewForumJSON,getOpenReviewNoteJSON:getOpenReviewNoteJSON,fetchSemanticScholarDataForDoi:fetchSemanticScholarDataForDoi,fetchText:fetchText,findACLValue:findACLValue,findFuzzyPaperMatch:findFuzzyPaperMatch,flipAndAuthors:flipAndAuthors,flipAuthor:flipAuthor,initPaper:initPaper,makeACLPaper:makeACLPaper,makeACMPaper:makeACMPaper,makeACSPaper:makeACSPaper,makeAPSPaper:makeAPSPaper,makeArxivPaper:makeArxivPaper,makeBioRxivPaper:makeBioRxivPaper,makeCVFPaper:makeCVFPaper,makeIEEEPaper:makeIEEEPaper,makeIJCAIPaper:makeIJCAIPaper,makeIOPPaper:makeIOPPaper,makeJMLRPaper:makeJMLRPaper,makeNaturePaper:makeNaturePaper,makeNeuripsPaper:makeNeuripsPaper,makeOpenReviewBibTex:makeOpenReviewBibTex,makeOpenReviewPaper:makeOpenReviewPaper,makePaper:makePaper,makePMCPaper:makePMCPaper,makePMLRPaper:makePMLRPaper,makePNASPaper:makePNASPaper,makePubMedPaper:makePubMedPaper,makePLOSPaper:makePLOSPaper,makeSpringerPaper:makeSpringerPaper,makeWileyPaper:makeWileyPaper,tryCrossRef:tryCrossRef,tryDBLP:tryDBLP,tryPreprintMatch:tryPreprintMatch,tryPWCMatch:tryPWCMatch,trySemanticScholar:trySemanticScholar}); \ No newline at end of file