From c7f3ffcdebe12e098bae2623cbc23b22ea5504b1 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Tue, 17 Oct 2023 10:40:18 -0400 Subject: [PATCH 01/40] v0 working --- src/fullMemory/bibMatcher.css | 266 +++++++++++++++++++++++++++++++++ src/fullMemory/bibMatcher.html | 124 +++++++++++++++ src/fullMemory/bibMatcher.js | 189 +++++++++++++++++++++++ 3 files changed, 579 insertions(+) create mode 100644 src/fullMemory/bibMatcher.css create mode 100644 src/fullMemory/bibMatcher.html create mode 100644 src/fullMemory/bibMatcher.js diff --git a/src/fullMemory/bibMatcher.css b/src/fullMemory/bibMatcher.css new file mode 100644 index 00000000..e4342720 --- /dev/null +++ b/src/fullMemory/bibMatcher.css @@ -0,0 +1,266 @@ +/* +--------------------- +----- Globals ----- +--------------------- +*/ +:root { + --maxWidth: 1000px; + --color: unset; +} +body { + margin: 0; + font-family: "Yantramanav"; + font-weight: 400; +} + +svg { + stroke-width: 1.15; + stroke: #7c7f8b; + fill: none; + stroke-linecap: round; + stroke-linejoin: round; +} + +code { + font-family: "Fira Code", monospace !important; + color: inherit !important; + padding: 1px 4px; + vertical-align: text-top; + border-radius: var(--round); + background-color: rgb(238, 238, 238); +} + +.pm-tabler-icon { + height: 32px; + width: 32px; + color: var(--red); + stroke-width: 1px; +} + +h2, +h3, +h4, +h5, +h6 { + padding-top: 1.5rem; +} + +/* +-------------------- +----- Header ----- +-------------------- +*/ +#header { + background-color: var(--red); + padding: 12px; + color: white; + display: flex; + justify-content: start; + align-items: center; + border-radius: 0 0 75% 0/50%; + box-shadow: 14px 30px 122px -30px rgba(0, 0, 0, 0.75); +} +#header-wrapper { + max-width: var(--maxWidth); + margin: auto; + display: flex; + justify-content: center; + align-items: center; +} +#header-wrapper h1 { + font-weight: 300; +} +#header-icon { + stroke: white; + margin-left: 1rem; +} + +#toc { + text-align: center; + max-width: 75%; + margin: auto; + margin-top: 2rem; + font-size: 1.2rem; +} + +.toc-item { + display: inline-block; +} + +/* +--------------------- +----- Content ----- +--------------------- +*/ +#content { + max-width: var(--maxWidth); + margin: auto; + padding: 32px; +} + +hr { + border: none; + border-top: 1px solid var(--lighterColor); + margin: 4rem; +} + +textarea { + border-radius: var(--round); + border: 1px solid #aaaaaa; + font-family: "Yantramanav"; + padding: 6px; +} + +button, +.file-upload-label { + border: 1px solid var(--red); + border-radius: var(--rounder); + padding: 4px 6px; + background-color: white; + transition: all ease 200ms; + cursor: pointer; +} +button:disabled, +.file-upload-label:disabled { + cursor: not-allowed; + pointer-events: none; + border-color: #e7a9a9; +} + +button:hover, +.file-upload-label:hover { + border-color: var(--red); + background-color: rgb(253, 235, 235); +} + +input { + border-radius: var(--round); + border: 1px solid #aaa; + margin-top: 8px; + line-height: 1.1rem; + padding: 6px; + margin-bottom: 4px; +} + +/* +----------------------------- +----- Matcher options ----- +----------------------------- +*/ +.option-item { + margin-bottom: 1rem; + margin-top: 1rem; +} + +.option-help { + margin-left: 1rem; + color: #7c7f8b; +} + +#match-bib, +#match-bib-stop, +#copy-results { + max-width: 200px; + margin: auto; +} +#bib-text { + max-width: 100%; + margin: 1rem; +} + +#match-results { + padding: 1rem; + border: 1px solid #ff4754; + border-radius: var(--round); +} +#copy-results { + background-color: rgb(86, 168, 86); + margin: 2rem auto; + color: white; +} +#copy-results:hover { + color: wheat; + background-color: rgb(86, 168, 86, 0.8); +} +.match-citation-key { + color: #7c7f8b; + padding-right: 0.5rem; + font-family: "Fira Code", monospace; + font-size: 0.85rem; + font-weight: 400; +} +.match-title { + font-weight: 400; +} +#match-bib-stop { + display: flex; + height: 34px; + align-items: center; + justify-content: center; +} +#match-bib-stop:hover { + background-color: rgb(253, 235, 235); +} +/* +---------------------- +----- Progress ----- +---------------------- +*/ + +.progress-container { + margin: 30px; + margin-top: 0; + height: 0.8rem; + width: 40%; + border-radius: 0.4rem; + background: #000; +} + +.progress-container .progress { + height: 100%; + width: 0; + border-radius: 0.4rem; + background: #ff4754; + transition: width 0.4s ease; +} + +#matching-progress-container { + display: flex; + justify-content: space-evenly; + align-items: center; + width: 100%; + padding-top: 24px; +} + +#matching-status-title { + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + display: inline-block; + max-width: 100%; +} + +#matching-status { + width: 60%; + min-width: 60%; + max-width: 60%; +} +.loader { + width: 16px; + height: 16px; + border: 3px solid #fff; + border-bottom-color: transparent; + border-radius: 50%; + display: inline-block; + box-sizing: border-box; + animation: rotation 1s linear infinite; +} + +@keyframes rotation { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} diff --git a/src/fullMemory/bibMatcher.html b/src/fullMemory/bibMatcher.html new file mode 100644 index 00000000..0f47cb24 --- /dev/null +++ b/src/fullMemory/bibMatcher.html @@ -0,0 +1,124 @@ + + + + + PaperMemory Options + + + + + + + + + + + + + +
+

+ Paste the content of your .bib file and PaperMemory will automatically match the Arxiv entries + to publications by + fetching information from PapersWithCode, DBLP, Semantic Scholar, CrossRef and Google Scholar. +

+ +

Warning: the matching procedure produces an output which + does + NOT maintain comments. Select + matched + entries one by one if you want to keep your initial comment structure. +

+ +

TODO

+ + + +
+ +

+
+
+
+ + + When a pre-print is matched to a publication, the latter may have a + standard citation key. You can either update the entry's citation key or use the new one. + Note that if you use the new one, your existing citations will be broken. +
+
+ + + You can choose to EITHER (default) get the same list of references, + with matched items updated (easier to copy-paste a full bibliography) OR just see the new + matches +
+ +
+
+ + +
+ +
+
+

+
+ +
+ +
+
+

+
+ +
+ +
+ + +
+ +
+ +
+ + + + + + + + + \ No newline at end of file diff --git a/src/fullMemory/bibMatcher.js b/src/fullMemory/bibMatcher.js new file mode 100644 index 00000000..a09a69a2 --- /dev/null +++ b/src/fullMemory/bibMatcher.js @@ -0,0 +1,189 @@ +var STOPMATCH = false; + +const setListeners = () => { + const stopMatch = document.getElementById("match-bib-stop"); + stopMatch.addEventListener("click", () => { + STOPMATCH = true; + setHTML("match-bib-stop", ''); + }); + document.getElementById("copy-results").addEventListener("click", () => { + copyTextToClipboard(document.getElementById("match-results").innerText); + setHTML("copy-results", "Copied!"); + setTimeout(() => { + setHTML("copy-results", "Copy to clipboard"); + }, 1500); + }); + const bibMatcher = document.getElementById("match-bib"); + bibMatcher.addEventListener("click", async () => { + const text = document.getElementById("bib-text").value; + let parsed = parseBibText(text); + console.log("parsed: ", parsed); + let arxivIndices = []; + let arxivs = []; + for (const [idx, entry] of parsed.entries()) { + if (JSON.stringify(entry).toLowerCase().includes("arxiv")) { + arxivIndices.push(idx); + arxivs.push(entry); + } + } + parsed = parsed.map((entry) => { + return { + ...entry.entryTags, + entryType: entry.entryType, + citationKey: entry.citationKey, + }; + }); + arxivs = arxivs.map((entry) => { + return { + ...entry.entryTags, + entryType: entry.entryType, + citationKey: entry.citationKey, + }; + }); + + console.log("arxivs: ", arxivs); + setHTML( + "n-arxivs", + `Matching ${arxivs.length} arXiv entries, out of ${parsed.length} total entries:` + ); + showId("match-bib-stop", "flex"); + const matched = arxivs.length && (await matchItems(arxivs)); + const nMatched = matched.filter((e) => e).length; + const found = + nMatched > 1 ? `Found ${nMatched} matches` : `Found ${nMatched} match`; + const showOnlyMatches = document.getElementById("show-only-matches").checked; + if (showOnlyMatches && nMatched) { + const html = matched + .filter((e) => e) + .map(bibtexToString) + .join("
"); + setHTML("match-results-title", found + " (showing only matches)"); + showId("match-results"); + setHTML("match-results", html); + showId("copy-results"); + } else if (nMatched) { + let htmls = []; + for (const [idx, entry] of parsed.entries()) { + if (arxivIndices.includes(idx)) { + if (matched[arxivIndices.indexOf(idx)]) { + htmls.push(bibtexToString(matched[arxivIndices.indexOf(idx)])); + } else { + htmls.push(bibtexToString(entry)); + } + } else { + htmls.push(bibtexToString(entry)); + } + } + const html = htmls.join("
"); + setHTML( + "match-results-title", + found + ` (showing all ${parsed.length} entries)` + ); + showId("match-results"); + setHTML("match-results", html); + showId("copy-results"); + } else { + setHTML("match-results-title", found); + showId("match-results"); + setHTML("match-results", ""); + } + }); +}; + +const parseBibText = (text) => { + var b = new BibtexParser(); + b.setInput(text); + b.bibtex(); + return b.getEntries(); +}; + +const matchItems = async (papersToMatch) => { + showId("matching-progress-container", "flex"); + setHTML("matching-status-total", papersToMatch.length); + + const progressbar = document.querySelector("#matching-progress-bar"); + + const changeProgress = (progress) => { + progressbar.style.width = `${progress}%`; + }; + changeProgress(0); + + let matchedBibtexStrs = []; + + for (const [idx, paper] of papersToMatch.entries()) { + console.log("idx: ", idx); + console.log("paper: ", paper); + setHTML("matching-status-index", idx + 1); + setHTML( + "matching-status-title", + paper.title.replaceAll("{", "").replaceAll("}", "") + ); + changeProgress(parseInt((idx / papersToMatch.length) * 100)); + + let bibtex, venue, match; + + if (!venue) { + setHTML("matching-status-provider", "dblp.org ..."); + match = await tryDBLP(paper); + console.log("dblpMatch: ", match); + bibtex = match?.bibtex; + venue = match?.venue; + } + + if (!venue) { + setHTML("matching-status-provider", "crossref.org ..."); + match = await tryCrossRef(paper); + console.log("crossRefMatch: ", match); + venue = match?.venue; + } + + if (!venue) { + setHTML("matching-status-provider", "semanticscholar.org ..."); + match = await trySemanticScholar(paper); + console.log("semanticScholarMatch: ", match); + venue = match?.venue; + } + + if (!venue) { + setHTML("matching-status-provider", "scholar.google.com ..."); + match = await tryCrossRef(paper); + console.log("googleScholarMatch: ", match); + venue = match?.venue; + } + if (venue) { + matchedBibtexStrs.push(match.bibtex); + console.log("matchedBibtexStrs: ", matchedBibtexStrs); + updateMatchedTitles(matchedBibtexStrs); + } else { + matchedBibtexStrs.push(null); + } + if (STOPMATCH) { + STOPMATCH = false; + setHTML("matching-status", "Interrupted

"); + hideId("match-bib-stop"); + setHTML("match-bib-stop", "Stop"); + return matchedBibtexStrs; + } + } + changeProgress(100); + setHTML("matching-status", "All done!

"); + return matchedBibtexStrs; +}; + +const updateMatchedTitles = (matchedBibtexStrs) => { + const entries = matchedBibtexStrs.filter((e) => e).map(bibtexToObject); + const keys = entries.map((e) => e.citationKey); + const titles = entries.map((e) => e.title.replaceAll("{", "").replaceAll("}", "")); + const htmls = [""]; + for (const [idx, title] of titles.entries()) { + htmls.push( + `` + ); + } + htmls.push("
${keys[idx]}${title}
"); + setHTML("matched-list", "

Papers matched:

" + htmls.join("")); +}; + +(async () => { + setListeners(); +})(); From b3cc3a1d10e9593e7732650ebf47e60f4a2fa1e2 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Tue, 17 Oct 2023 11:49:04 -0400 Subject: [PATCH 02/40] fix `val` by converting string to element before checking for checkbox --- src/shared/js/utils/miniquery.js | 6 +++--- src/shared/min/utils.min.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shared/js/utils/miniquery.js b/src/shared/js/utils/miniquery.js index b317d49d..64e3cc38 100644 --- a/src/shared/js/utils/miniquery.js +++ b/src/shared/js/utils/miniquery.js @@ -37,15 +37,15 @@ const fadeIn = (el, display = "block", duration = 250, callback = () => {}) => { }; const val = (el, value) => { + if (typeof el === "string") { + el = findEl(el); + } if (el instanceof HTMLInputElement && el.type === "checkbox") { if (typeof value === "undefined") { return el.checked; } el.checked = value; } - if (typeof el === "string") { - el = findEl(el); - } if (typeof value === "undefined") { return el ? el.value : ""; } diff --git a/src/shared/min/utils.min.js b/src/shared/min/utils.min.js index a60ebef7..203bd71c 100644 --- a/src/shared/min/utils.min.js +++ b/src/shared/min/utils.min.js @@ -1,4 +1,4 @@ -const findEl=(e,t)=>void 0===t?"string"==typeof e?document.getElementById(e):e:findEl("memory-container--"+e).querySelector("."+t),fadeOut=(e,t=250,r=()=>{})=>{(e=findEl(e)).style.transition=t+"ms",e.style.opacity=0,setTimeout(()=>{e.style.display="none",r()},t)},fadeIn=(e,t="block",r=250,i=()=>{})=>{(e=findEl(e)).style.opacity=0,"none"===e.style.display&&(e.style.display=t),setTimeout(()=>{e.style.transition=r+"ms",e.style.opacity=1,setTimeout(()=>{i()},r)},0)},val=(e,t)=>{if(e instanceof HTMLInputElement&&"checkbox"===e.type){if(void 0===t)return e.checked;e.checked=t}if("string"==typeof e&&(e=findEl(e)),void 0===t)return e?e.value:"";e&&(e.value=t)},showId=(e,t="block")=>{let r=findEl(e);r&&(r.style.display=t)},hideId=e=>{(el=findEl(e))&&(el.style.display="none")},setTextId=(e,t)=>{let r=findEl(e);r&&(r.innerText=t)},setHTML=(e,t)=>{(e="string"==typeof e?findEl(e):e)&&(e.innerHTML=t)},dispatch=(e,t)=>{if("string"==typeof e&&(e=findEl(e)),"string"==typeof t){if("focus"===t)return void e.focus();if("blur"===t)return void e.blur();t=new Event(t)}e&&e.dispatchEvent(t)},hasClass=(e,t)=>{let r;if(r="string"==typeof e?findEl(e):e)return r.classList.contains(t)},addClass=(e,t)=>{let r;(r="string"==typeof e?findEl(e):e)&&r.classList.add(t)},removeClass=(e,t)=>{let r;(r="string"==typeof e?findEl(e):e)&&r.classList.remove(t)},addListener=(e,t,r)=>{(e="string"==typeof e?findEl(e):e)&&e.addEventListener(t,r)},setPlaceholder=(e,t)=>{(e="string"==typeof e?findEl(e):e)&&void 0!==e.placeholder&&(e.placeholder=t)},style=(e,t,r)=>{if(e="string"==typeof e?findEl(e):e){if(void 0===r)return e.style[t];e.style[t]=r}},disable=(e,t=!0)=>{(e="string"==typeof e?findEl(e):e)&&(e.disabled=t)},slideUp=(e,t=250,r=()=>{})=>{(e="string"==typeof e?findEl(e):e)&&(e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.height=e.offsetHeight+"px",e.offsetHeight,e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,window.setTimeout(()=>{e.style.display="none",e.style.removeProperty("height"),e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property"),e.style.removeProperty("box-sizing"),r()},t))},slideDown=(t,r=500,i=()=>{})=>{if(t="string"==typeof t?findEl(t):t){t.style.removeProperty("display");let e=window.getComputedStyle(t).display;"none"===e&&(e="block"),t.style.display=e;var a=t.offsetHeight;t.style.overflow="hidden",t.style.height=0,t.style.paddingTop=0,t.style.paddingBottom=0,t.style.marginTop=0,t.style.marginBottom=0,t.offsetHeight,t.style.transitionProperty="height, margin, padding",t.style.transitionDuration=r+"ms",t.style.height=a+"px",t.style.removeProperty("padding-top"),t.style.removeProperty("padding-bottom"),t.style.removeProperty("margin-top"),t.style.removeProperty("margin-bottom"),window.setTimeout(()=>{t.style.removeProperty("height"),t.style.removeProperty("overflow"),t.style.removeProperty("transition-duration"),t.style.removeProperty("transition-property"),i()},r)}},slideToggle=(e,t=500,r=()=>{})=>("none"===window.getComputedStyle(e).display?slideDown:slideUp)(e,t,r),queryAll=(e,t)=>[...e.querySelectorAll(t)],createElementFromHTML=e=>{var t=document.createElement("div");return t.innerHTML=e.trim(),t.firstChild},addEventToClass=(e,t,r)=>{e.startsWith(".")||(e="."+e),document.querySelectorAll(e).forEach(e=>{e.addEventListener(t,r)})};var dummyModule,global=("undefined"!=typeof module&&null!=module.exports&&(dummyModule=module,dummyModule.exports={findEl:findEl,fadeOut:fadeOut,fadeIn:fadeIn,val:val,showId:showId,hideId:hideId,setTextId:setTextId,setHTML:setHTML,dispatch:dispatch,hasClass:hasClass,addClass:addClass,removeClass:removeClass,addListener:addListener,setPlaceholder:setPlaceholder,style:style,disable:disable,slideUp:slideUp,slideDown:slideDown,slideToggle:slideToggle,queryAll:queryAll,addEventToClass:addEventToClass,createElementFromHTML:createElementFromHTML}),Object.defineProperty(Array.prototype,"last",{value:function(e=0){return this.reverse()[e]}}),Object.defineProperty(String.prototype,"capitalize",{value:function(e=!1){return e?this.split(" ").map(e=>e.capitalize()).join(" "):this.charAt(0).toUpperCase()+this.slice(1).toLowerCase()}}),{}),dummyModule,dummyModule,dummyModule,dummyModule,dummyModule,dummyModule,dummyModule;function _min(e,t,r,i,a){return eBoolean(e.match(/journals\.aps\.org\/\w+\/(abstract|pdf)\//g))],acs:["pubs.acs.org/doi/"],arxiv:["arxiv.org/abs/","arxiv.org/pdf/","scirate.com/arxiv/","ar5iv.labs.arxiv.org/html/","arxiv-vanity.com/papers/",e=>e.includes("huggingface.co/papers/")&&e.split("huggingface.co/papers/")[1].match(/\d+\.\d+/)],biorxiv:["biorxiv.org/content"],cvf:["openaccess.thecvf.com/content"],frontiers:["frontiersin.org/articles"],ihep:["inspirehep.net/literature/","inspirehep.net/files/"],ijcai:[e=>/ijcai\.org\/proceedings\/\d{4}\/\d+/gi.test(e)],ieee:["ieeexplore.ieee.org/document/","ieeexplore.ieee.org/abstract/document/","ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber="],iop:["iopscience.iop.org/article/"],jmlr:[e=>e.includes("jmlr.org/papers/v")&&!e.endsWith("/")],nature:["nature.com/articles/"],neurips:["neurips.cc/paper/","neurips.cc/paper_files/paper/","nips.cc/paper/"],openreview:["openreview.net/forum","openreview.net/pdf","openreview.net/attachment"],plos:[e=>/journals\.plos\.org\/.+\/article.+id=/gi.test(e)],pmc:["ncbi.nlm.nih.gov/pmc/articles/PMC"],pmlr:["proceedings.mlr.press/"],pnas:["pnas.org/content/","pnas.org/doi/"],rsc:["pubs.rsc.org/en/content/article"],science:[e=>Boolean(e.match(/science\.org\/doi\/?(abs|full|pdf|epdf)?\//g))],sciencedirect:["sciencedirect.com/science/article/pii/","sciencedirect.com/science/article/abs/pii/","reader.elsevier.com/reader/sd/pii/"],springer:[...global.sourceExtras.springer.types.map(e=>`link.springer.com/${e}/`),"link.springer.com/content/pdf/"],website:[],wiley:[e=>Boolean(e.match(/onlinelibrary\.wiley\.com\/doi\/(abs|full|pdf|epdf)\//g))]},global.sourcesNames={acl:"Association for Computational Linguistics (ACL)",acm:"Association for Computing Machinery (ACM)",acs:"American Chemical Society (ACS)",aps:"American Physical Society",arxiv:"ArXiv",biorxiv:"BioRxiv",cvf:"Computer Vision Foundation (CVF)",ijcai:"International Joint Conferences on Artificial Intelligence (IJCAI)",iop:"Institute Of Physics (IOP)",jmlr:"Journal of Machine Learning Research (JMLR)",nature:"Nature",neurips:"NeurIPS",openreview:"OpenReview",pmc:"PubMed Central",pmlr:"Proceedings of Machine Learning Research (PMLR)",pnas:"Proceedings of the National Academy of Sciences (PNAS)",science:"Science",sciencedirect:"ScienceDirect",springer:"Springer",wiley:"Wiley"},global.overrideORConfs={"robot-learning":"CoRL",ijcai:"IJCAI"},global.overridePMLRConfs={"Conference on Learning Theory":"CoLT","International Conference on Machine Learning":"ICML","Conference on Uncertainty in Artificial Intelligence":"UAI","Conference on Robot Learning":"CoRL","International Conference on Artificial Intelligence and Statistics":"AISTATS","International Conference on Algorithmic Learning Theory":"ALT"},global.overrideDBLPVenues={"J. Mach. Learn. Res.":"JMLR"},global.consolHeaderStyle="@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300');font-family:'Fira Code' monospace;font-size:1rem;font-weight:300;display:inline-block;border:2px solid #A41716;border-radius: 4px;padding: 12px; margin: 12px;",global.fuzzyTitleMatchMinDist=4,global.defaultTitleFunctionCode=`(paper) => { +const findEl=(e,t)=>void 0===t?"string"==typeof e?document.getElementById(e):e:findEl("memory-container--"+e).querySelector("."+t),fadeOut=(e,t=250,r=()=>{})=>{(e=findEl(e)).style.transition=t+"ms",e.style.opacity=0,setTimeout(()=>{e.style.display="none",r()},t)},fadeIn=(e,t="block",r=250,i=()=>{})=>{(e=findEl(e)).style.opacity=0,"none"===e.style.display&&(e.style.display=t),setTimeout(()=>{e.style.transition=r+"ms",e.style.opacity=1,setTimeout(()=>{i()},r)},0)},val=(e,t)=>{if((e="string"==typeof e?findEl(e):e)instanceof HTMLInputElement&&"checkbox"===e.type){if(void 0===t)return e.checked;e.checked=t}if(void 0===t)return e?e.value:"";e&&(e.value=t)},showId=(e,t="block")=>{let r=findEl(e);r&&(r.style.display=t)},hideId=e=>{(el=findEl(e))&&(el.style.display="none")},setTextId=(e,t)=>{let r=findEl(e);r&&(r.innerText=t)},setHTML=(e,t)=>{(e="string"==typeof e?findEl(e):e)&&(e.innerHTML=t)},dispatch=(e,t)=>{if("string"==typeof e&&(e=findEl(e)),"string"==typeof t){if("focus"===t)return void e.focus();if("blur"===t)return void e.blur();t=new Event(t)}e&&e.dispatchEvent(t)},hasClass=(e,t)=>{let r;if(r="string"==typeof e?findEl(e):e)return r.classList.contains(t)},addClass=(e,t)=>{let r;(r="string"==typeof e?findEl(e):e)&&r.classList.add(t)},removeClass=(e,t)=>{let r;(r="string"==typeof e?findEl(e):e)&&r.classList.remove(t)},addListener=(e,t,r)=>{(e="string"==typeof e?findEl(e):e)&&e.addEventListener(t,r)},setPlaceholder=(e,t)=>{(e="string"==typeof e?findEl(e):e)&&void 0!==e.placeholder&&(e.placeholder=t)},style=(e,t,r)=>{if(e="string"==typeof e?findEl(e):e){if(void 0===r)return e.style[t];e.style[t]=r}},disable=(e,t=!0)=>{(e="string"==typeof e?findEl(e):e)&&(e.disabled=t)},slideUp=(e,t=250,r=()=>{})=>{(e="string"==typeof e?findEl(e):e)&&(e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.height=e.offsetHeight+"px",e.offsetHeight,e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,window.setTimeout(()=>{e.style.display="none",e.style.removeProperty("height"),e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property"),e.style.removeProperty("box-sizing"),r()},t))},slideDown=(t,r=500,i=()=>{})=>{if(t="string"==typeof t?findEl(t):t){t.style.removeProperty("display");let e=window.getComputedStyle(t).display;"none"===e&&(e="block"),t.style.display=e;var a=t.offsetHeight;t.style.overflow="hidden",t.style.height=0,t.style.paddingTop=0,t.style.paddingBottom=0,t.style.marginTop=0,t.style.marginBottom=0,t.offsetHeight,t.style.transitionProperty="height, margin, padding",t.style.transitionDuration=r+"ms",t.style.height=a+"px",t.style.removeProperty("padding-top"),t.style.removeProperty("padding-bottom"),t.style.removeProperty("margin-top"),t.style.removeProperty("margin-bottom"),window.setTimeout(()=>{t.style.removeProperty("height"),t.style.removeProperty("overflow"),t.style.removeProperty("transition-duration"),t.style.removeProperty("transition-property"),i()},r)}},slideToggle=(e,t=500,r=()=>{})=>("none"===window.getComputedStyle(e).display?slideDown:slideUp)(e,t,r),queryAll=(e,t)=>[...e.querySelectorAll(t)],createElementFromHTML=e=>{var t=document.createElement("div");return t.innerHTML=e.trim(),t.firstChild},addEventToClass=(e,t,r)=>{e.startsWith(".")||(e="."+e),document.querySelectorAll(e).forEach(e=>{e.addEventListener(t,r)})};var dummyModule,global=("undefined"!=typeof module&&null!=module.exports&&(dummyModule=module,dummyModule.exports={findEl:findEl,fadeOut:fadeOut,fadeIn:fadeIn,val:val,showId:showId,hideId:hideId,setTextId:setTextId,setHTML:setHTML,dispatch:dispatch,hasClass:hasClass,addClass:addClass,removeClass:removeClass,addListener:addListener,setPlaceholder:setPlaceholder,style:style,disable:disable,slideUp:slideUp,slideDown:slideDown,slideToggle:slideToggle,queryAll:queryAll,addEventToClass:addEventToClass,createElementFromHTML:createElementFromHTML}),Object.defineProperty(Array.prototype,"last",{value:function(e=0){return this.reverse()[e]}}),Object.defineProperty(String.prototype,"capitalize",{value:function(e=!1){return e?this.split(" ").map(e=>e.capitalize()).join(" "):this.charAt(0).toUpperCase()+this.slice(1).toLowerCase()}}),{}),dummyModule,dummyModule,dummyModule,dummyModule,dummyModule,dummyModule,dummyModule;function _min(e,t,r,i,a){return eBoolean(e.match(/journals\.aps\.org\/\w+\/(abstract|pdf)\//g))],acs:["pubs.acs.org/doi/"],arxiv:["arxiv.org/abs/","arxiv.org/pdf/","scirate.com/arxiv/","ar5iv.labs.arxiv.org/html/","arxiv-vanity.com/papers/",e=>e.includes("huggingface.co/papers/")&&e.split("huggingface.co/papers/")[1].match(/\d+\.\d+/)],biorxiv:["biorxiv.org/content"],cvf:["openaccess.thecvf.com/content"],frontiers:["frontiersin.org/articles"],ihep:["inspirehep.net/literature/","inspirehep.net/files/"],ijcai:[e=>/ijcai\.org\/proceedings\/\d{4}\/\d+/gi.test(e)],ieee:["ieeexplore.ieee.org/document/","ieeexplore.ieee.org/abstract/document/","ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber="],iop:["iopscience.iop.org/article/"],jmlr:[e=>e.includes("jmlr.org/papers/v")&&!e.endsWith("/")],nature:["nature.com/articles/"],neurips:["neurips.cc/paper/","neurips.cc/paper_files/paper/","nips.cc/paper/"],openreview:["openreview.net/forum","openreview.net/pdf","openreview.net/attachment"],plos:[e=>/journals\.plos\.org\/.+\/article.+id=/gi.test(e)],pmc:["ncbi.nlm.nih.gov/pmc/articles/PMC"],pmlr:["proceedings.mlr.press/"],pnas:["pnas.org/content/","pnas.org/doi/"],rsc:["pubs.rsc.org/en/content/article"],science:[e=>Boolean(e.match(/science\.org\/doi\/?(abs|full|pdf|epdf)?\//g))],sciencedirect:["sciencedirect.com/science/article/pii/","sciencedirect.com/science/article/abs/pii/","reader.elsevier.com/reader/sd/pii/"],springer:[...global.sourceExtras.springer.types.map(e=>`link.springer.com/${e}/`),"link.springer.com/content/pdf/"],website:[],wiley:[e=>Boolean(e.match(/onlinelibrary\.wiley\.com\/doi\/(abs|full|pdf|epdf)\//g))]},global.sourcesNames={acl:"Association for Computational Linguistics (ACL)",acm:"Association for Computing Machinery (ACM)",acs:"American Chemical Society (ACS)",aps:"American Physical Society",arxiv:"ArXiv",biorxiv:"BioRxiv",cvf:"Computer Vision Foundation (CVF)",ijcai:"International Joint Conferences on Artificial Intelligence (IJCAI)",iop:"Institute Of Physics (IOP)",jmlr:"Journal of Machine Learning Research (JMLR)",nature:"Nature",neurips:"NeurIPS",openreview:"OpenReview",pmc:"PubMed Central",pmlr:"Proceedings of Machine Learning Research (PMLR)",pnas:"Proceedings of the National Academy of Sciences (PNAS)",science:"Science",sciencedirect:"ScienceDirect",springer:"Springer",wiley:"Wiley"},global.overrideORConfs={"robot-learning":"CoRL",ijcai:"IJCAI"},global.overridePMLRConfs={"Conference on Learning Theory":"CoLT","International Conference on Machine Learning":"ICML","Conference on Uncertainty in Artificial Intelligence":"UAI","Conference on Robot Learning":"CoRL","International Conference on Artificial Intelligence and Statistics":"AISTATS","International Conference on Algorithmic Learning Theory":"ALT"},global.overrideDBLPVenues={"J. Mach. Learn. Res.":"JMLR"},global.consolHeaderStyle="@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@300');font-family:'Fira Code' monospace;font-size:1rem;font-weight:300;display:inline-block;border:2px solid #A41716;border-radius: 4px;padding: 12px; margin: 12px;",global.fuzzyTitleMatchMinDist=4,global.defaultTitleFunctionCode=`(paper) => { const title = paper.title.replaceAll("\\n", ''); const id = paper.id; let name = \`\${title} - \${id}\`; From b1ae21eb42ec74959fca227c6501af1e85882ba8 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Tue, 17 Oct 2023 11:49:16 -0400 Subject: [PATCH 03/40] switch all/new --- src/fullMemory/bibMatcher.css | 135 +++++++++++++++++++++++++++++++++ src/fullMemory/bibMatcher.html | 37 +++++---- src/fullMemory/bibMatcher.js | 116 +++++++++++++++++----------- 3 files changed, 228 insertions(+), 60 deletions(-) diff --git a/src/fullMemory/bibMatcher.css b/src/fullMemory/bibMatcher.css index e4342720..2d6db5ea 100644 --- a/src/fullMemory/bibMatcher.css +++ b/src/fullMemory/bibMatcher.css @@ -45,6 +45,11 @@ h6 { padding-top: 1.5rem; } +.d-flex-center-center { + display: flex; + justify-content: center; + align-items: center; +} /* -------------------- ----- Header ----- @@ -177,6 +182,8 @@ input { background-color: rgb(86, 168, 86); margin: 2rem auto; color: white; + padding: 4px 8px; + width: 200px; } #copy-results:hover { color: wheat; @@ -201,6 +208,10 @@ input { #match-bib-stop:hover { background-color: rgb(253, 235, 235); } +#bib-desc { + font-style: italic; + color: #7c7f8b; +} /* ---------------------- ----- Progress ----- @@ -264,3 +275,127 @@ input { transform: rotate(360deg); } } + +/* +------------------------ +----- Checkboxes ----- +------------------------ +*/ + +@supports (-webkit-appearance: none) or (-moz-appearance: none) { + input[type="checkbox"] { + --active: rgb(201, 19, 19, 0.65); + --active-inner: #fff; + --focus: 2px rgba(254, 39, 39, 0.596); + --border: #c5aaaa; + --border-hover: #b94141; + --background: #fff; + --disabled: #f9e1e1; + --disabled-inner: #f9e1e1; + -webkit-appearance: none; + -moz-appearance: none; + height: 21px; + outline: none; + display: inline-block; + vertical-align: top; + position: relative; + margin: 0; + cursor: pointer; + border: 1px solid var(--bc, var(--border)); + background: var(--b, var(--background)); + -webkit-transition: background 0.3s, border-color 0.3s, box-shadow 0.2s; + transition: background 0.3s, border-color 0.3s, box-shadow 0.2s; + } + + input[type="checkbox"]:after { + content: ""; + display: block; + left: 0; + top: 0; + position: absolute; + -webkit-transition: opacity var(--d-o, 0.2s), + -webkit-transform var(--d-t, 0.3s) var(--d-t-e, ease); + transition: opacity var(--d-o, 0.2s), + -webkit-transform var(--d-t, 0.3s) var(--d-t-e, ease); + transition: transform var(--d-t, 0.3s) var(--d-t-e, ease), + opacity var(--d-o, 0.2s); + transition: transform var(--d-t, 0.3s) var(--d-t-e, ease), + opacity var(--d-o, 0.2s), + -webkit-transform var(--d-t, 0.3s) var(--d-t-e, ease); + } + + input[type="checkbox"]:checked { + --b: var(--active); + --bc: var(--active); + --d-o: 0.3s; + --d-t: 0.6s; + --d-t-e: cubic-bezier(0.2, 0.85, 0.32, 1.2); + } + + input[type="checkbox"]:disabled { + --b: var(--disabled); + cursor: not-allowed; + opacity: 0.9; + } + + input[type="checkbox"]:disabled:checked { + --b: var(--disabled-inner); + --bc: var(--border); + } + + input[type="checkbox"]:disabled + label { + cursor: not-allowed; + } + + input[type="checkbox"]:hover:not(:checked):not(:disabled) { + --bc: var(--border-hover); + } + + input[type="checkbox"]:focus { + box-shadow: 0 0 0 var(--focus); + } + + input[type="checkbox"]:not(.switch) { + width: 21px; + } + + input[type="checkbox"]:not(.switch):after { + opacity: var(--o, 0); + } + + input[type="checkbox"]:not(.switch):checked { + --o: 1; + } + + input[type="checkbox"] + label { + display: inline-block; + cursor: pointer; + vertical-align: sub; + margin-left: 4px; + } + + input[type="checkbox"].switch { + width: 38px; + border-radius: 11px; + } + + input[type="checkbox"].switch:after { + left: 2px; + top: 2px; + border-radius: 50%; + width: 15px; + height: 15px; + background: var(--ab, var(--border)); + -webkit-transform: translateX(var(--x, 0)); + transform: translateX(var(--x, 0)); + } + + input[type="checkbox"].switch:checked { + --ab: var(--active-inner); + --x: 17px; + } + + input[type="checkbox"].switch:disabled:not(:checked):after { + opacity: 0.6; + } +} diff --git a/src/fullMemory/bibMatcher.html b/src/fullMemory/bibMatcher.html index 0f47cb24..afe82896 100644 --- a/src/fullMemory/bibMatcher.html +++ b/src/fullMemory/bibMatcher.html @@ -55,20 +55,21 @@

TODO



-
- - - When a pre-print is matched to a publication, the latter may have a +
+
+    + +
+
+
When a pre-print is matched to a publication, the + latter may have a standard citation key. You can either update the entry's citation key or use the new one. - Note that if you use the new one, your existing citations will be broken. -
-
- - - You can choose to EITHER (default) get the same list of references, - with matched items updated (easier to copy-paste a full bibliography) OR just see the new - matches + Note that if you use the new one, your existing citations will be broken.
+
@@ -99,10 +100,16 @@

TODO

-

-
-
+ + +

diff --git a/src/fullMemory/bibMatcher.js b/src/fullMemory/bibMatcher.js index a09a69a2..1f9c0ec2 100644 --- a/src/fullMemory/bibMatcher.js +++ b/src/fullMemory/bibMatcher.js @@ -17,6 +17,7 @@ const setListeners = () => { bibMatcher.addEventListener("click", async () => { const text = document.getElementById("bib-text").value; let parsed = parseBibText(text); + resetMatchResults(); console.log("parsed: ", parsed); let arxivIndices = []; let arxivs = []; @@ -46,48 +47,72 @@ const setListeners = () => { "n-arxivs", `Matching ${arxivs.length} arXiv entries, out of ${parsed.length} total entries:` ); - showId("match-bib-stop", "flex"); - const matched = arxivs.length && (await matchItems(arxivs)); - const nMatched = matched.filter((e) => e).length; - const found = - nMatched > 1 ? `Found ${nMatched} matches` : `Found ${nMatched} match`; - const showOnlyMatches = document.getElementById("show-only-matches").checked; - if (showOnlyMatches && nMatched) { - const html = matched - .filter((e) => e) - .map(bibtexToString) - .join("
"); - setHTML("match-results-title", found + " (showing only matches)"); - showId("match-results"); - setHTML("match-results", html); - showId("copy-results"); - } else if (nMatched) { - let htmls = []; - for (const [idx, entry] of parsed.entries()) { - if (arxivIndices.includes(idx)) { - if (matched[arxivIndices.indexOf(idx)]) { - htmls.push(bibtexToString(matched[arxivIndices.indexOf(idx)])); - } else { - htmls.push(bibtexToString(entry)); - } + const matched = arxivs.length ? await matchItems(arxivs) : []; + showPapers(parsed, matched, arxivIndices); + addListener("show-only-matches", "change", () => { + showPapers(parsed, matched, arxivIndices); + }); + }); +}; + +const resetMatchResults = () => { + setHTML("match-results-title", ""); + hideId("result-controls"); + hideId("match-results"); + setHTML("match-results", ""); + hideId("bib-header"); + setHTML("bib-desc", ""); +}; + +const showPapers = (parsed, matched, arxivIndices) => { + const nMatched = matched.filter((e) => e).length; + const found = + nMatched > 1 ? `Found ${nMatched} matches` : `Found ${nMatched} match`; + if (!nMatched) { + showId("match-results"); + setHTML("match-results", ""); + return; + } + const showOnlyMatches = val("show-only-matches"); + const desc = showOnlyMatches + ? `

Showing only ${nMatched} new matched entries

` + : `

Showing all ${parsed.length} entries (with ${nMatched} updated match${ + nMatched > 1 ? "s" : "" + })

`; + if (showOnlyMatches && nMatched) { + const html = matched + .filter((e) => e) + .map(bibtexToString) + .join("
"); + setHTML("match-results-title", found + " (showing only matches)"); + showId("match-results"); + setHTML("match-results", html); + showId("result-controls", "flex"); + } else if (nMatched) { + let htmls = []; + for (const [idx, entry] of parsed.entries()) { + if (arxivIndices.includes(idx)) { + if (matched[arxivIndices.indexOf(idx)]) { + htmls.push(bibtexToString(matched[arxivIndices.indexOf(idx)])); } else { htmls.push(bibtexToString(entry)); } + } else { + htmls.push(bibtexToString(entry)); } - const html = htmls.join("
"); - setHTML( - "match-results-title", - found + ` (showing all ${parsed.length} entries)` - ); - showId("match-results"); - setHTML("match-results", html); - showId("copy-results"); - } else { - setHTML("match-results-title", found); - showId("match-results"); - setHTML("match-results", ""); } - }); + const html = htmls.join("
"); + setHTML( + "match-results-title", + found + ` (showing all ${parsed.length} entries)` + ); + showId("match-results"); + setHTML("match-results", html); + showId("result-controls", "flex"); + } + showId("bib-header"); + setHTML("match-results-title", found); + setHTML("bib-desc", desc); }; const parseBibText = (text) => { @@ -100,6 +125,7 @@ const parseBibText = (text) => { const matchItems = async (papersToMatch) => { showId("matching-progress-container", "flex"); setHTML("matching-status-total", papersToMatch.length); + showId("match-bib-stop", "flex"); const progressbar = document.querySelector("#matching-progress-bar"); @@ -111,8 +137,6 @@ const matchItems = async (papersToMatch) => { let matchedBibtexStrs = []; for (const [idx, paper] of papersToMatch.entries()) { - console.log("idx: ", idx); - console.log("paper: ", paper); setHTML("matching-status-index", idx + 1); setHTML( "matching-status-title", @@ -125,7 +149,7 @@ const matchItems = async (papersToMatch) => { if (!venue) { setHTML("matching-status-provider", "dblp.org ..."); match = await tryDBLP(paper); - console.log("dblpMatch: ", match); + match.venue && console.log("dblpMatch: ", match); bibtex = match?.bibtex; venue = match?.venue; } @@ -133,26 +157,25 @@ const matchItems = async (papersToMatch) => { if (!venue) { setHTML("matching-status-provider", "crossref.org ..."); match = await tryCrossRef(paper); - console.log("crossRefMatch: ", match); + match.venue && console.log("crossRefMatch: ", match); venue = match?.venue; } if (!venue) { setHTML("matching-status-provider", "semanticscholar.org ..."); match = await trySemanticScholar(paper); - console.log("semanticScholarMatch: ", match); + match.venue && console.log("semanticScholarMatch: ", match); venue = match?.venue; } if (!venue) { setHTML("matching-status-provider", "scholar.google.com ..."); match = await tryCrossRef(paper); - console.log("googleScholarMatch: ", match); + match.venue && console.log("googleScholarMatch: ", match); venue = match?.venue; } if (venue) { matchedBibtexStrs.push(match.bibtex); - console.log("matchedBibtexStrs: ", matchedBibtexStrs); updateMatchedTitles(matchedBibtexStrs); } else { matchedBibtexStrs.push(null); @@ -181,7 +204,10 @@ const updateMatchedTitles = (matchedBibtexStrs) => { ); } htmls.push(""); - setHTML("matched-list", "

Papers matched:

" + htmls.join("")); + setHTML( + "matched-list", + `

Papers matched: ${entries.length}

` + htmls.join("") + ); }; (async () => { From 30355a6b056d157bec1290f44e2821d7022e05db Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Tue, 17 Oct 2023 11:51:08 -0400 Subject: [PATCH 04/40] remove legacy venue check --- src/fullMemory/bibMatcher.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/fullMemory/bibMatcher.js b/src/fullMemory/bibMatcher.js index 1f9c0ec2..1d9b7ca0 100644 --- a/src/fullMemory/bibMatcher.js +++ b/src/fullMemory/bibMatcher.js @@ -144,38 +144,37 @@ const matchItems = async (papersToMatch) => { ); changeProgress(parseInt((idx / papersToMatch.length) * 100)); - let bibtex, venue, match; + let bibtex, match; - if (!venue) { + if (!bibtex) { setHTML("matching-status-provider", "dblp.org ..."); match = await tryDBLP(paper); - match.venue && console.log("dblpMatch: ", match); + match.bibtex && console.log("dblpMatch: ", match); bibtex = match?.bibtex; - venue = match?.venue; } - if (!venue) { + if (!bibtex) { setHTML("matching-status-provider", "crossref.org ..."); match = await tryCrossRef(paper); - match.venue && console.log("crossRefMatch: ", match); - venue = match?.venue; + match.bibtex && console.log("crossRefMatch: ", match); + bibtex = match?.bibtex; } - if (!venue) { + if (!bibtex) { setHTML("matching-status-provider", "semanticscholar.org ..."); match = await trySemanticScholar(paper); - match.venue && console.log("semanticScholarMatch: ", match); - venue = match?.venue; + match.bibtex && console.log("semanticScholarMatch: ", match); + bibtex = match?.bibtex; } - if (!venue) { + if (!bibtex) { setHTML("matching-status-provider", "scholar.google.com ..."); match = await tryCrossRef(paper); - match.venue && console.log("googleScholarMatch: ", match); - venue = match?.venue; + match.bibtex && console.log("googleScholarMatch: ", match); + bibtex = match?.bibtex; } - if (venue) { - matchedBibtexStrs.push(match.bibtex); + if (bibtex) { + matchedBibtexStrs.push(bibtex); updateMatchedTitles(matchedBibtexStrs); } else { matchedBibtexStrs.push(null); From 01e51cc86600d4b74e0c22a21ab2bc172841dbc7 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Tue, 17 Oct 2023 11:51:32 -0400 Subject: [PATCH 05/40] remove mention of PWC --- src/fullMemory/bibMatcher.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fullMemory/bibMatcher.html b/src/fullMemory/bibMatcher.html index afe82896..16d59183 100644 --- a/src/fullMemory/bibMatcher.html +++ b/src/fullMemory/bibMatcher.html @@ -32,7 +32,7 @@

Bib Matcher

Paste the content of your .bib file and PaperMemory will automatically match the Arxiv entries to publications by - fetching information from PapersWithCode, DBLP, Semantic Scholar, CrossRef and Google Scholar. + fetching information from DBLP, Semantic Scholar, CrossRef and Google Scholar.

Warning: the matching procedure produces an output which From f7c75b9344469490c69a65751e6f6ca058ae3dbf Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Tue, 17 Oct 2023 12:00:38 -0400 Subject: [PATCH 06/40] add keepKeys functionality --- src/fullMemory/bibMatcher.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/fullMemory/bibMatcher.js b/src/fullMemory/bibMatcher.js index 1d9b7ca0..c881b4ab 100644 --- a/src/fullMemory/bibMatcher.js +++ b/src/fullMemory/bibMatcher.js @@ -122,18 +122,25 @@ const parseBibText = (text) => { return b.getEntries(); }; +const setKey = (bibtex, key) => { + const obj = bibtexToObject(bibtex); + obj.citationKey = key; + return bibtexToString(obj); +}; + const matchItems = async (papersToMatch) => { showId("matching-progress-container", "flex"); setHTML("matching-status-total", papersToMatch.length); showId("match-bib-stop", "flex"); const progressbar = document.querySelector("#matching-progress-bar"); - const changeProgress = (progress) => { progressbar.style.width = `${progress}%`; }; changeProgress(0); + const keepKeys = val("keep-keys"); + let matchedBibtexStrs = []; for (const [idx, paper] of papersToMatch.entries()) { @@ -149,31 +156,34 @@ const matchItems = async (papersToMatch) => { if (!bibtex) { setHTML("matching-status-provider", "dblp.org ..."); match = await tryDBLP(paper); - match.bibtex && console.log("dblpMatch: ", match); + match?.bibtex && console.log("dblpMatch: ", match); bibtex = match?.bibtex; } if (!bibtex) { setHTML("matching-status-provider", "crossref.org ..."); match = await tryCrossRef(paper); - match.bibtex && console.log("crossRefMatch: ", match); + match?.bibtex && console.log("crossRefMatch: ", match); bibtex = match?.bibtex; } if (!bibtex) { setHTML("matching-status-provider", "semanticscholar.org ..."); match = await trySemanticScholar(paper); - match.bibtex && console.log("semanticScholarMatch: ", match); + match?.bibtex && console.log("semanticScholarMatch: ", match); bibtex = match?.bibtex; } if (!bibtex) { setHTML("matching-status-provider", "scholar.google.com ..."); match = await tryCrossRef(paper); - match.bibtex && console.log("googleScholarMatch: ", match); + match?.bibtex && console.log("googleScholarMatch: ", match); bibtex = match?.bibtex; } if (bibtex) { + if (keepKeys) { + bibtex = setKey(bibtex, paper.citationKey); + } matchedBibtexStrs.push(bibtex); updateMatchedTitles(matchedBibtexStrs); } else { @@ -187,6 +197,7 @@ const matchItems = async (papersToMatch) => { return matchedBibtexStrs; } } + hideId("match-bib-stop"); changeProgress(100); setHTML("matching-status", "All done!

"); return matchedBibtexStrs; From 6c9b0cf622118da51d80abdadd5be195d028a5aa Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Tue, 17 Oct 2023 12:58:20 -0400 Subject: [PATCH 07/40] add venues and sources to feedback table --- src/fullMemory/bibMatcher.css | 25 +++++++++++- src/fullMemory/bibMatcher.html | 2 +- src/fullMemory/bibMatcher.js | 74 +++++++++++++++++++++++++--------- 3 files changed, 79 insertions(+), 22 deletions(-) diff --git a/src/fullMemory/bibMatcher.css b/src/fullMemory/bibMatcher.css index 2d6db5ea..5376a58a 100644 --- a/src/fullMemory/bibMatcher.css +++ b/src/fullMemory/bibMatcher.css @@ -189,14 +189,21 @@ input { color: wheat; background-color: rgb(86, 168, 86, 0.8); } -.match-citation-key { +.match-citation-key, +.match-source { color: #7c7f8b; padding-right: 0.5rem; font-family: "Fira Code", monospace; font-size: 0.85rem; font-weight: 400; } -.match-title { +.match-source { + font-style: italic; +} + +.match-title, +.match-source, +.match-venue { font-weight: 400; } #match-bib-stop { @@ -212,6 +219,20 @@ input { font-style: italic; color: #7c7f8b; } +table { + border-collapse: collapse; +} + +table tr { + border-bottom: 1px solid rgb(228, 228, 228); +} + +table tr:last-child { + border: 0; +} +th { + padding: 8px 2px; +} /* ---------------------- ----- Progress ----- diff --git a/src/fullMemory/bibMatcher.html b/src/fullMemory/bibMatcher.html index 16d59183..b9b5bc99 100644 --- a/src/fullMemory/bibMatcher.html +++ b/src/fullMemory/bibMatcher.html @@ -2,7 +2,7 @@ - PaperMemory Options + PaperMemory BibMatcher

\ No newline at end of file diff --git a/src/popup/min/popup.min.js b/src/popup/min/popup.min.js index da195fe1..c8814241 100644 --- a/src/popup/min/popup.min.js +++ b/src/popup/min/popup.min.js @@ -1,4 +1,4 @@ const handleBackToFocus=e=>{const t=eventId(e);setTimeout(()=>{dispatch("memory-container--"+t,"focus")},250)},handleDeleteItem=e=>{e=eventId(e);showConfirmDeleteModal(e)},handleOpenItemLink=e=>{e=eventId(e);focusExistingOrCreateNewPaperTab(global.state.papers[e],!0)},handleOpenItemScirate=e=>{var e=eventId(e),t="https://scirate.com/arxiv/"+arxivIdFromPaperID(global.state.papers[e].id);focusExistingOrCreateNewCodeTab(t),global.state.papers[e]=updatePaperVisits(global.state.papers[e]),setStorage("papers",global.state.papers)},handleOpenItemVanity=e=>{var e=eventId(e),t="https://www.arxiv-vanity.com/papers/"+arxivIdFromPaperID(global.state.papers[e].id);focusExistingOrCreateNewCodeTab(t),global.state.papers[e]=updatePaperVisits(global.state.papers[e]),setStorage("papers",global.state.papers)},handleOpenItemAr5iv=e=>{var e=eventId(e),t="https://ar5iv.labs.arxiv.org/html/"+arxivIdFromPaperID(global.state.papers[e].id);focusExistingOrCreateNewCodeTab(t),global.state.papers[e]=updatePaperVisits(global.state.papers[e]),setStorage("papers",global.state.papers)},handleOpenItemHuggingface=e=>{var e=eventId(e),t="https://huggingface.co/papers/"+arxivIdFromPaperID(global.state.papers[e].id);focusExistingOrCreateNewCodeTab(t),global.state.papers[e]=updatePaperVisits(global.state.papers[e]),setStorage("papers",global.state.papers)},handleOpenItemCodeLink=async e=>{e=eventId(e),e=global.state.papers[e].codeLink;await focusExistingOrCreateNewCodeTab(e)},handleOpenItemWebsiteURL=async e=>{var e=eventId(e),t=global.state.papers[e].pdfLink;global.state.papers[e]=updatePaperVisits(global.state.papers[e]),await setStorage("papers",global.state.papers),await focusExistingOrCreateNewCodeTab(t)},handleCopyMarkdownLink=async e=>{var e=eventId(e),t=global.state.prefs,a=t.checkPreferPdf?"PDF":"Abstract",s=global.state.papers[e],s=makeMdLink(s,t);copyAndConfirmMemoryItem(e,s,`Markdown ${a} link copied!`)},handleCopyBibtex=e=>{var e=eventId(e),t=global.state.papers[e].bibtex;let a=bibtexToObject(t);a.hasOwnProperty("url")||(a.url=paperToAbs(global.state.papers[e])),a.hasOwnProperty("pdf")||(a.pdf=paperToPDF(global.state.papers[e])),copyAndConfirmMemoryItem(e,bibtexToString(a),"Bibtex copied!")},handleCopyPDFLink=async e=>{var e=eventId(e),t=global.state.prefs,a=global.state.papers[e],a=(t.checkPreferPdf?paperToPDF:paperToAbs)(a),t=t.checkPreferPdf?"PDF":"Abstract";copyAndConfirmMemoryItem(e,a,t+" link copied!")},handleCopyHyperLink=async e=>{var e=eventId(e),t=global.state.prefs,a=global.state.papers[e],s=(t.checkPreferPdf?paperToPDF:paperToAbs)(a);t.checkPreferPdf;copyAndConfirmMemoryItem(e,s,"Hyperlink copied!",!1,a.title)},handleAddItemToFavorites=e=>{var e=eventId(e),t=hasClass("memory-container--"+e,"favorite");saveFavoriteItem(e,!t)},handleMemoryOpenLocal=e=>{var e=eventId(e),t=global.state.files[e],a=global.state.papers[e];global.state.papers[e]=updatePaperVisits(a),setStorage("papers",global.state.papers),t&&(t.id||0===t.id)&&chrome.downloads.open(t.id),window?.close&&window.close()},handleTextareaFocus=()=>{textareaFocusEnd(this)},handleMemorySaveEdits=e=>{var{note:t,codeLink:a}=getPaperEdits(e);saveNote(e,t),saveCodeLink(e,a),updatePaperTags(e,"memory-item-tags")},handleCancelPaperEdit=e=>{e.preventDefault();var e=eventId(e),t=global.state.papers[e];val(findEl(e,"form-note-textarea"),t.note),setHTML(findEl(e,"memory-item-tags"),getTagsOptions(t)),dispatch(findEl(e,"memory-item-edit"),"click")},handleTogglePaperEdit=e=>{e.preventDefault();e=eventId(e);const t=findEl("memory-container--"+e);var a=findEl(e,"code-and-note"),s=findEl(e,"extended-item"),o=findEl(e,"tag-list"),r=findEl(e,"memory-authors"),i=findEl(e,"edit-tags"),l=findEl(e,"memory-item-actions");const n=$(findEl(e,"memory-item-tags"));hasClass(t,"expand-open")?(removeClass(t,"expand-open"),slideDown(a,150),slideDown(o,150),slideDown(l,150),slideDown(r,150),slideUp(s,150),slideUp(i,150),setTimeout(()=>{n.select2("destroy")},500)):(addClass(t,"expand-open"),n.select2({...global.select2Options,width:"86%"}),hasClass(t,"has-monitoring")||n.on("change",monitorPaperEdits(e,!1)),t.classList.add("has-monitoring"),slideUp(a,150),slideUp(o,150),slideUp(l,150),slideUp(r,150),slideDown(s,150),slideDown(i,150))},handleMemorySelectChange=e=>{e=e.target.value;global.state.sortKey=e,sortMemory(),displayMemoryTable(),setMemorySortArrow("down")},handleMemorySortArrow=e=>{"memory-sort-arrow-down"===document.querySelector("#memory-sort-arrow svg").id?setMemorySortArrow("up"):setMemorySortArrow("down"),reverseMemory(),displayMemoryTable()},handleFilterFavorites=()=>{var e=!global.state.showFavorites;(global.state.showFavorites=e)?(addClass(findEl("filter-favorites").querySelector("svg"),"favorite"),sortMemory(),global.state.papersList=global.state.papersList.filter(e=>e.favorite),displayMemoryTable(),setMemorySortArrow("down"),findEl("memory-select").innerHTML+='',e=global.state.papersList.length,setPlaceholder("memory-search",`Search ${e} entries...`)):(removeClass(findEl("filter-favorites").querySelector("svg"),"favorite"),"favoriteDate"===val("memory-select")&&(val("memory-select","lastOpenDate"),global.state.sortKey="lastOpenDate"),document.querySelector('#memory-select option[value="favoriteDate"]').remove(),sortMemory(),setMemorySortArrow("down"),val("memory-search").trim()?dispatch("memory-search","keypress"):(global.state.papersList=global.state.sortedPapers,displayMemoryTable()),e=global.state.sortedPapers.length,setPlaceholder("memory-search",`Search ${e} entries...`))},handleMemorySearchKeyPress=a=>e=>{const t=val("memory-search").trim();if(log(t),t||setTimeout(()=>{style("memory-search-clear-icon","visibility","hidden")},0),!t){if(global.state.papersList.length!==global.state.sortedPapers.length)return global.state.papersList=global.state.sortedPapers,void displayMemoryTable();if(!a&&"Backspace"!==e.key)return}style("memory-search-clear-icon","visibility","visible"),(t.startsWith("t:")?searchMemoryByTags:t.startsWith("c:")?searchMemoryByCode:t.startsWith("y:")?searchMemoryByYear:searchMemory)(t),toggleTagsCollapse(t.startsWith("t:")),displayMemoryTable()},handleMemorySearchKeyUp=e=>{var t;"Backspace"==e.key&&((t=new Event("keypress")).key="Backspace",dispatch("memory-search",t)),"memory-search"===e.target.id&&dispatch("memory-search","keypress")},handleCancelModalClick=()=>{hideId("delete-paper-modal")},handleConfirmDeleteModalClick=async e=>{var t=findEl("delete-paper-modal-hidden-id").innerHTML,a=global.state.papers[t].title,s=global.state.papers[t].pdfLink;await deletePaperInStorage(t,global.state.papers),displayMemoryTable(),hideId("delete-paper-modal"),info(`Successfully deleted "${a}" (${t}) from PaperMemory`),global.state.currentId===t&&await updatePopupPaperNoMemory(s),setPlaceholder("memory-search",`Search ${global.state.papersList.length} entries ...`),addListener("memory-switch","click",handleMemorySwitchClick)},handleTagClick=e=>{e=e.target.textContent;val("memory-search","t: "+e),dispatch("memory-search","keypress")},handleClearSearch=e=>{val("memory-search",""),dispatch("memory-search","clear-search"),style("memory-search-clear-icon","visibility","hidden")},handleMemorySwitchClick=()=>{(global.state.memoryIsOpen?closeMemory:openMemory)()},handlePopupKeydown=t=>{var a,s=t.key;if(!(["Backspace","Enter","Escape","a","e"].indexOf(s)<0))if(global.state.prefsIsOpen)"Escape"===s?(t.preventDefault(),closeMenu()):"Enter"===s&&document.querySelector("#menu-switch:focus")&&closeMenu();else if(global.state.memoryIsOpen){if("Enter"===s){if(document.querySelector("#filter-favorites:focus"))return void dispatch("filter-favorites","click");if(document.querySelector("#memory-sort-arrow:focus")&&"Enter"===s)return void dispatch("memory-sort-arrow","click")}let e;const o=document.querySelector(".memory-container:focus");if("Escape"!==s){if(!o)return;e=o.id.split("--")[1]}"Backspace"===s?dispatch(findEl(e,"memory-delete"),"click"):"Enter"===s?(a="website"===global.state.papers[e].source?findEl(e,"memory-website-url"):global.state.prefs.checkEnterLocalPdf&&findEl(e,"memory-item-openLocal")||findEl(e,"memory-item-link"),dispatch(a,"click")):"Escape"===s?(t.preventDefault(),o&&hasClass(o,"expand-open")?handleTogglePaperEdit(t):closeMemory()):"e"===s&&dispatch(findEl(e,"memory-item-edit"),"click")}else if("a"===s){const e=queryAll(document,":focus");if(e.some(e=>["INPUT","TEXTAREA"].includes(e.tagName)))return;global.state.papers&&dispatch("memory-switch","click")}else"Enter"===s&&("memory-switch-open"===(a=document.querySelector(":focus")).id?dispatch("memory-switch","click"):"menu-switch"===a.id?(dispatch("menu-switch","click"),dispatch("menu-switch","blur")):hasClass(a,"memory-item-svg-div")&&dispatch(a,"click"))},handlePrefsCheckChange=async e=>{const t=e.target.id,a=findEl(t).checked;if(global.state&&global.state.prefs)global.state.prefs[t]=a,setStorage("prefs",global.state.prefs,function(){log(`Settings saved for ${t} (${a})`)});else{const s=await getStorage("prefs")??{};s[t]=a,setStorage("prefs",s,function(){log(`Settings saved for ${t} (${a})`)})}a&&"checkNoAuto"===t&&chrome.commands.getAll(e=>{e=e.find(e=>"manualParsing"===e.name).shortcut;console.log("shortcut: ",e),e||showPopupModal("manualParsing")})},handlePopupSaveEdits=e=>{var{note:t,codeLink:a,favorite:s}=getPaperEdits(e,!0);updatePaperTags(e,"#popup-item-tags--"+e),saveNote(e,t),saveCodeLink(e,a),saveFavoriteItem(e,s)},handlePopupDeletePaper=e=>()=>{showConfirmDeleteModal(e)},getMemoryItemHTML=(e,t)=>{var a=new Date(e.addDate).toLocaleString().replace(",",""),s=new Date(e.lastOpenDate).toLocaleString().replace(",",""),o=getDisplayId(e.id),r=e.note||"",i=e.id,l=new Set(e.tags),n=getTagsOptions(e),d=e.favorite?"favorite":"",p=(t.pdfLink="Open tab to "+e.title,t.copyLink="Copy URL to the paper's "+(global.state.prefs.checkPreferPdf?"PDF":"abstract"),`
${"website"==e.source&&e.pdfLink.replace(/^https?:\/\//,"")||""}
`);let c='
';e.note&&(c=`
Note: ${r}
`);var m=global.state.files.hasOwnProperty(e.id)?`
${tablerSvg("vocabulary","",["memory-icon-svg"])}
`:"",y="website"===e.source?"":``;let g="",v=(global.state.prefs.checkScirate&&"arxiv"===e.source&&(g=`
${tablerSvg("messages","",["memory-icon-svg"])}
`),""),h=(global.state.prefs.checkVanity&&"arxiv"===e.source&&(v=`
${tablerSvg("vanity","",["memory-icon-svg"])}
`),""),u=(global.state.prefs.checkAr5iv&&"arxiv"===e.source&&(h=`
${tablerSvg("ar5iv","",["memory-icon-svg"])}
`),"");return global.state.prefs.checkHuggingface&&"arxiv"===e.source&&(u=`
${tablerSvg("huggingface","",["memory-icon-svg"])}
`),`

${tablerSvg("star","",["memory-item-favorite-svg",d])} ${e.title}

${[...l].map(e=>`${e}`).join("")}
${cutAuthors(e.author)}
${p} ${c}
${tablerSvg("writing","",["memory-icon-svg"])}
${o}
${m} ${y} ${u} ${g} ${v} ${h}
${tablerSvg("markdown","",["memory-icon-svg"])}
${tablerSvg("math-function","",["memory-icon-svg"])}
Visits: ${e.count}
-
`},getPopupEditFormHTML=e=>{var t=e.id,a=getTagsOptions(e),s=e.note||"",o=getDisplayId(e.id);return`
Tags:
${o}
`},getPopupPaperIconsHTML=(e,t,a)=>{var s=e.id,t=isPdfUrl(t)?"HTML":"PDF";let o="",r=(global.state.prefs.checkScirate&&"arxiv"===e.source&&(o=``),""),i=(global.state.prefs.checkVanity&&"arxiv"===e.source&&(r=``),""),l=(global.state.prefs.checkAr5iv&&"arxiv"===e.source&&(i=``),"");global.state.prefs.checkHuggingface&&"arxiv"===e.source&&(l=``);a=global.state.prefs.checkStore&&(a.localFile||a.stored||global.state.files.hasOwnProperty(e.id))?``:``;return("website"===e.source?"":``)+` ${l} ${o} ${r} ${i}`+a},getTagsOptions=e=>{const s=new Set(e.tags);return[...global.state.paperTags].sort().map((e,t)=>{let a='
');const o=findEl("isArxiv").innerHTML;setHTML("isArxiv",a),addListener("no-paper-why-code","click",()=>{showPopupModal("noPaper")}),e&&addListener("manual-trigger-btn","click",async()=>{showId("manual-loader-container");try{var t=await isPaper(s);let e;var a=await addOrUpdatePaper({url:s,is:t});if(!a)return;(e=a.paper)&&(hideId("manual-loader-container"),setHTML("isArxiv",o),popupMain(s,t,!0))}catch(e){hideId("manual-loader-container"),setHTML("manual-parsing-error",`${"There was an issue parsing this paper.
Raise an issue on Github if you think it is a bug.
Attempted url: "+s}
`),warn("Manual Parsing Error:",e)}})},showConfirmDeleteModal=e=>{var t=global.state.papers[e].title;setTextId("delete-modal-title",t),setHTML("delete-paper-modal-hidden-id",e),showId("delete-paper-modal","flex")},copyAndConfirmMemoryItem=(e,t,a,s,o)=>{console.log("hyperLinkTitle: ",o),o?copyHyperLinkToClipboard(t,o):copyTextToClipboard(t);const r=s?findEl("popup-feedback-copied"):findEl(e,"memory-item-feedback");r&&(r.innerText=a,fadeIn(r),setTimeout(()=>{fadeOut(r)},2e3))},focusExistingOrCreateNewCodeTab=r=>new Promise(o=>{(r=r.replace("http://","https://")).startsWith("https://")||(r="https://"+r);var e=new URL(r)["origin"];chrome.tabs.query({url:e+"/*"},e=>{for(const t of e)if(t.url.includes(r)){const a={active:!0},s={focused:!0};return chrome.windows.getCurrent(e=>{e.id!==t.windowId?chrome.windows.update(t.windowId,s,()=>{chrome.tabs.update(t.id,a),o()}):(chrome.tabs.update(t.id,a),o())}),void o()}chrome.tabs.create({url:r}),o()}),o()}),focusExistingOrCreateNewPaperTab=(i,l)=>{chrome.tabs.query({},async e=>{var t=global.state.prefs;let a=[];for(const r of e){let e;try{e=r.url&&await parseIdFromUrl(r.url)}catch(e){}e&&e===i.id&&a.push(r)}let s;var o,e=t.checkPreferPdf?a.filter(e=>e.url&&isPdfUrl(e.url)):a.filter(e=>e.url&&!isPdfUrl(e.url));0e.url.startsWith("file://")),s=(0{e.id!==s.windowId?chrome.windows.update(s.windowId,{focused:!0},()=>{chrome.tabs.update(s.id,{active:!0})}):chrome.tabs.update(s.id,{active:!0})}):global.state.files.hasOwnProperty(i.id)&&!l?chrome.downloads.open(global.state.files[i.id].id):chrome.tabs.create({url:(t.checkPreferPdf?paperToPDF:paperToAbs)(i)}),global.state.papers[i.id]=updatePaperVisits(global.state.papers[i.id]),chrome.storage.local.set({papers:global.state.papers})})},saveNote=(t,a)=>{global.state.papers[t].note=a,chrome.storage.local.set({papers:global.state.papers},()=>{setHTML(findEl(t,"memory-note-div"),a?`
Note: ${a}
`:'
');var e=findEl("popup-form-note-textarea--"+t);val(e,a),val(findEl(t,"form-note-textarea"),a)})},saveCodeLink=(t,a)=>{a=a.trim(),global.state.papers[t].codeLink=a,chrome.storage.local.set({papers:global.state.papers},()=>{var e=a.replace(/^https?:\/\//,""),e=(setHTML(findEl(t,"memory-code-link"),e),setHTML("popup-code-link",e),val(findEl(t,"form-code-input"),a),(a?showId:hideId)("popup-code-link"),findEl("popup-form-codeLink--"+t));val(e,a)})},saveFavoriteItem=(s,o)=>{global.state.papers[s].favorite=o,global.state.papers[s].favoriteDate=(new Date).toJSON(),chrome.storage.local.set({papers:global.state.papers},()=>{var e,t;o?(addClass("memory-container--"+s,"favorite"),addClass(findEl(s,"memory-item-favorite").querySelector("svg"),"favorite")):(removeClass("memory-container--"+s,"favorite"),removeClass(findEl(s,"memory-item-favorite").querySelector("svg"),"favorite")),"favoriteDate"===global.state.sortKey&&(o||(sortMemory(),displayMemoryTable()),e=global.state.sortedPapers.filter(e=>e.favorite).length,(t=findEl("memory-search"))&&setPlaceholder(t,`Search ${e} entries`));let a=findEl("checkFavorite--"+s);a&&(a.checked=o)})},setMemorySortArrow=e=>{let t;t="up"===e?'':'',setHTML("memory-sort-arrow",t)},reverseMemory=()=>{global.state.sortedPapers.reverse(),global.state.papersList.reverse()},searchMemory=e=>{const t=e.toLowerCase().split(" ");let a=[];for(const s of global.state.sortedPapers){const o=s.title.toLowerCase(),r=s.author.toLowerCase(),i=s.note.toLowerCase(),l=s.tags.join(" ").toLowerCase(),n=getDisplayId(s.id).toLowerCase(),d=s.venue.toLowerCase();!t.every(e=>o.includes(e)||r.includes(e)||i.includes(e)||l.includes(e)||n.includes(e)||d.includes(e))||global.state.showFavorites&&!s.favorite||a.push(s)}global.state.papersList=a},searchMemoryByYear=e=>{var t=e.includes("<")?"smaller":e.includes(">")?"greater":"";const a=e.replace("y:","").replace(/(<|>)/g,"").toLowerCase().replaceAll(","," ").split(" ").filter(e=>04===e.length?e:"20"+e).map(e=>parseInt(e,10));console.log("searchYears: ",a);let s=[],o=(e,t)=>e===t;"smaller"==t?o=(e,t)=>teo(e,i))&&s.push(r)}global.state.papersList=s},searchMemoryByTags=e=>{const t=e.replace("t:","").toLowerCase().split(" ");let a=[];for(const s of global.state.sortedPapers){const o=s.tags.map(e=>e.toLowerCase());!t.every(t=>o.some(e=>0<=e.indexOf(t)))||global.state.showFavorites&&!s.favorite||a.push(s)}global.state.papersList=a},searchMemoryByCode=e=>{const a=e.replace("c:","").toLowerCase().split(" ");let s=[];for(const o of global.state.sortedPapers){let t=o.codeLink||"";t=t.toLowerCase(),!a.every(e=>t.includes(e))||global.state.showFavorites&&!o.favorite||s.push(o)}global.state.papersList=s},updatePaperTagsHTML=e=>{setHTML(findEl(e,"tag-list"),global.state.papers[e].tags.map(e=>`${e}`).join(""))},updateTagOptions=e=>{updateAllMemoryPaperTagOptions();var t=getTagsOptions(global.state.papers[e]);setHTML("popup-item-tags--"+e,t)},updatePaperTags=(t,e)=>{let a;a=e.startsWith("#")?findEl(e.replace("#","")):findEl(t,e);e=parseTags(a);let s=!1;new Set;arraysIdentical(global.state.papers[t].tags,e)||(s=!0),global.state.papers[t].tags=e,s&&chrome.storage.local.set({papers:global.state.papers},()=>{makeTags(),updateTagOptions(t),updatePaperTagsHTML(t);for(const e of queryAll(findEl(t,"tag-list"),".memory-tag"))addListener(e,"click",handleTagClick)})},displayOnScroll=s=>delay(()=>{var e=findEl("memory-table").getBoundingClientRect()["bottom"],t=s?findEl("memory-container").getBoundingClientRect().height:window.innerHeight,a=global.state.currentMemoryPagination*global.state.memoryItemsPerPage;Math.abs(e-t){var t=Date.now(),a=findEl("memory-table"),s=(0===e&&(setHTML(a,""),global.state.currentMemoryPagination=0),{edit:"Edit paper details",copyMd:"Copy Markdown-formatted link",copyBibtext:"Copy Bibtex citation",visits:"Number of times you have opened this paper",openLocal:"Open downloaded pdf",copyLink:"Copy paper url",copyHypeLink:"Copy url as hyperlink"});let o=[];for(const r of global.state.papersList.slice(e*global.state.memoryItemsPerPage,(e+1)*global.state.memoryItemsPerPage))try{o.push(getMemoryItemHTML(r,s))}catch(e){log("displayMemoryTable error:"),log(e),log(r)}0===e?setHTML(a,o.join("")):a.insertAdjacentHTML("beforeend",o.join("")),addEventToClass(".back-to-focus","click",handleBackToFocus),addEventToClass(".memory-delete","click",handleDeleteItem),addEventToClass(".memory-item-link","click",handleOpenItemLink),addEventToClass(".memory-item-scirate","click",handleOpenItemScirate),addEventToClass(".memory-item-vanity","click",handleOpenItemVanity),addEventToClass(".memory-item-ar5iv","click",handleOpenItemAr5iv),addEventToClass(".memory-item-huggingface","click",handleOpenItemHuggingface),addEventToClass(".memory-code-link","click",handleOpenItemCodeLink),addEventToClass(".memory-website-url","click",handleOpenItemWebsiteURL),addEventToClass(".memory-item-md","click",handleCopyMarkdownLink),addEventToClass(".memory-item-bibtex","click",handleCopyBibtex),addEventToClass(".memory-item-copy-link","click",handleCopyPDFLink),addEventToClass(".memory-item-copy-hyperlink","click",handleCopyHyperLink),addEventToClass(".memory-item-openLocal","click",handleMemoryOpenLocal),addEventToClass(".memory-item-favorite","click",handleAddItemToFavorites),addEventToClass(".cancel-note-form","click",handleCancelPaperEdit),addEventToClass(".memory-item-edit","click",handleTogglePaperEdit),addEventToClass(".memory-tag","click",handleTagClick),setFormChangeListener(void 0,!1),addEventToClass(".form-note-textarea","focus",handleTextareaFocus);e=Date.now();info("Display duration (s): "+(e-t)/1e3)},makeMemoryHTML=async()=>{setPlaceholder("memory-search",`Search ${global.state.papersList.length} entries ...`),displayMemoryTable();let e=300;global.state.papersList.length<20?e=0:global.state.papersList.length<100&&(e=150),addListener("memory-search","keypress",delay(handleMemorySearchKeyPress(),e)),addListener("memory-search","clear-search",handleMemorySearchKeyPress(!0)),addListener("memory-search","keyup",handleMemorySearchKeyUp),addListener("delete-paper-modal-cancel-button","click",handleCancelModalClick),addListener("delete-paper-modal-confirm-button","click",handleConfirmDeleteModalClick),addListener("filter-favorites","click",handleFilterFavorites),addListener("memory-select","change",handleMemorySelectChange),addListener("memory-sort-arrow","click",handleMemorySortArrow),addListener("memory-container","scroll",displayOnScroll(!0))},openMemory=()=>{global.state.prefsIsOpen&&closeMenu(),global.state.memoryIsOpen=!0,hideId("memory-switch-open"),showId("memory-switch-close"),hideId("menu-switch"),dispatch("memory-switch","blur"),slideDown("memory-container",200,()=>{setTimeout(()=>{dispatch("memory-search","focus")},100)}),setTimeout(()=>{addListener("memory-search-clear-icon","click",handleClearSearch),val("memory-select","lastOpenDate"),setMemorySortArrow("down")},200)},closeMemory=()=>{dispatch("memory-switch","blur"),hideId("memory-switch-close"),showId("memory-switch-open"),slideUp("memory-container",200,()=>{val("memory-search",""),dispatch("memory-search","clear-search"),global.state.memoryIsOpen=!1,global.state.showFavorites&&dispatch("filter-favorites","click"),showId("menu-switch","flex")})},closeMenu=()=>{slideUp("menu-container",300),setHTML("menu-switch",tablerSvg("settings","menu-switch-svg",["pm-tabler-icon","menu-svg"])),dispatch("menu-switch","blur"),global.state.prefsIsOpen=!1},openMenu=()=>{slideDown("menu-container",300),dispatch("menu-switch","blur"),setHTML("menu-switch",tablerSvg("circle-x","close-menu-btn",["pm-tabler-icon","menu-svg"])),global.state.prefsIsOpen=!0},getAndTrackPopupMenuChecks=(e,t)=>{let a={};for(const s of t){a[s]=e.hasOwnProperty(s)?e[s]:!(0<=global.prefsCheckDefaultFalse.indexOf(s));const o=findEl(s);o&&(o.checked=a[s])}setStorage("prefs",a);for(const r of t)addListener(r,"change",handlePrefsCheckChange)},showPopupModal=e=>{document.querySelectorAll(".popup-modal-content").forEach(hideId),showId(`modal-${e}-content`,"contents"),style("popup-modal-wrapper","display","flex"),[...document.getElementsByTagName("a")].forEach(e=>{addListener(e,"click",()=>{chrome.tabs.create({url:e.getAttribute("href")})})})},closePopupModal=()=>{style("popup-modal-wrapper","display","none")},setStandardPopupClicks=()=>{addListener("helpGithubLink","click",()=>{chrome.tabs.create({url:"https://github.com/vict0rsch/PaperMemory"})}),addListener("whats-new-container","click",()=>{chrome.storage.local.get("whatsnew",({whatsnew:e})=>{var t=chrome.runtime.getManifest().version;(e=void 0===e?{}:e).hasOwnProperty(t)||hideId("whats-new-marker"),chrome.storage.local.set({whatsnew:{...e,[t]:!0}}),showPopupModal("whatsnew")})}),addListener("keyboardShortcuts","click",()=>{showPopupModal("keyboard")}),addListener("keyboardShortcutsMenu","click",()=>{showPopupModal("keyboard")}),shouldWarn("pdf-title",e=>{e&&(showId("warning-button"),addListener("warning-button","click",async()=>{showPopupModal("warning-pdf-title");let e=await getStorage("userWarnings")??{};e["pdf-title"]=!0,setStorage("userWarnings",e),hideId("warning-button")}))}),addListener("close-popup-modal","click",closePopupModal),addListener(window,"click",e=>{e.target===findEl("popup-modal-wrapper")&&closePopupModal()}),addListener("menu-switch","click",()=>{(global.state.prefsIsOpen?closeMenu:openMenu)()}),addListener("memory-switch","click",handleMemorySwitchClick)},editManualWebsite=(p,c)=>{hideId("manual-website-validation"),showPopupModal("manual-website"),showId("website-trigger-btn");for(const e of["author","title","year","url","note","pdfLink"])findEl("manual-website-"+e).value=p[e]??"";setHTML("manual-website-url",p.codeLink),addListener("manual-website-form","submit",async e=>{e.preventDefault(),hideId("manual-website-validation");e=val("manual-website-title");let t=val("manual-website-author");var a=val("manual-website-year"),s=val("manual-website-note"),o=val("manual-website-pdfLink");t.includes(",")&&(t=t.split(",").map(e=>e.trim()).join(" and "));let r={...p,title:e,author:t,year:a,note:s,pdfLink:o};var s=""+miniHash(t.split(" and ")[0].split(" ").last())+a+firstNonStopLowercase(e),{warnings:i,paper:a}=(r.bibtex=bibtexToString({...bibtexToObject(r.bibtex),author:t,year:a,title:e,citationKey:s,url:o}),validatePaper(r));let l="";for(const n of Object.keys(i))for(const d of i[n])l+=`
  • ${d}
  • `;return 0${l}`,setHTML("manual-website-validation",l),showId("manual-website-validation")):(global.state.papers[a.id]=a,await setStorage("papers",global.state.papers),await pushToRemote(),popupMain(c,await isPaper(c),!0,null),hideId("website-trigger-btn"),hideId("notArxiv"),closePopupModal()),!1})},popupMain=async(a,t,s=!1,o=null)=>{console.log(navigator.userAgent),"PuppeteerAgent"===navigator.userAgent&&info("Is puppet"),addListener(document,"keydown",handlePopupKeydown),chrome.storage.local.get("whatsnew",({whatsnew:e})=>{var t=chrome.runtime.getManifest().version;e&&e.hasOwnProperty(t)||showId("whats-new-marker")}),console.log("manualTrigger: ",s),s?(hideId("memory-switch"),showId("memory-spinner"),await initSyncAndState({forceInit:!0}),hideId("memory-spinner"),showId("memory-switch"),makeMemoryHTML()):setStandardPopupClicks();const r=await getPrefs();if(getAndTrackPopupMenuChecks(r,global.prefsCheckNames),addListener("advanced-configuration","click",()=>{chrome.runtime.openOptionsPage()}),addListener("full-memory","click",()=>{chrome.tabs.create({url:chrome.extension.getURL("src/fullMemory/fullMemory.html")})}),Object.values(t).some(e=>e)){setTimeout(()=>{document.body.style.height="auto",document.body.style.minHeight="450px"},0),showId("isArxiv","flex");const i=await parseIdFromUrl(a);if(!(global.state.currentId=i)||!global.state.papers.hasOwnProperty(i))return log("Unknown id "+i),await updatePopupPaperNoMemory(a),void(r.checkDirectOpen&&!r.checkNoAuto&&dispatch("memory-switch","click"));const l=global.state.papers[i];s=l.id.replaceAll(".","\\.");setTextId("popup-paper-title",l.title.replaceAll("\n","")),setTextId("popup-authors",cutAuthors(l.author,350).replace(/({|})/g,"")),l.codeLink&&(setTextId("popup-code-link",l.codeLink.replace(/^https?:\/\//,"")),showId("popup-code-link")),"website"===l.source&&(setTextId("popup-website-url",l.pdfLink.replace(/^https?:\/\//,"")),showId("popup-website-url")),log("Popup paper:",l),setHTML("popup-memory-edit",getPopupEditFormHTML(l)),setHTML("popup-copy-icons",getPopupPaperIconsHTML(l,a,t)),findEl("checkFavorite--"+i).checked=l.favorite;let e=0;for(const n of["checkScirate","checkVanity","checkAr5iv","checkHugginface"])r[n]&&(e+=5);style("popup-icons-container","width",75+e+"%"),$("#popup-item-tags--"+s).select2({...global.select2Options,width:"87%"}),addListener("popup-form-note-textarea--"+i,"focus",()=>{textareaFocusEnd(this)}),setFormChangeListener(i,!0),addListener("popup-delete-paper","click",handlePopupDeletePaper(i)),addListener("popup-memory-item-scirate--"+i,"click",()=>{var e=arxivIdFromPaperID(l.id);chrome.tabs.update({url:"https://scirate.com/arxiv/"+e}),window.close()}),addListener("popup-memory-item-vanity--"+i,"click",()=>{var e=arxivIdFromPaperID(l.id);chrome.tabs.update({url:"https://www.arxiv-vanity.com/papers/"+e}),window.close()}),addListener("popup-memory-item-ar5iv--"+i,"click",()=>{var e=arxivIdFromPaperID(l.id);chrome.tabs.update({url:"https://ar5iv.labs.arxiv.org/html/"+e}),window.close()}),addListener("popup-memory-item-huggingface--"+i,"click",()=>{var e=arxivIdFromPaperID(l.id);chrome.tabs.update({url:"https://huggingface.co/papers/"+e}),window.close()}),addListener("popup-memory-item-link--"+i,"click",()=>{var e=paperToPDF(l),t=paperToAbs(l);chrome.tabs.update({url:isPdfUrl(a)?t:e}),window.close()}),addListener("popup-code-link","click",async()=>{var e=findEl("popup-code-link").textContent;e&&(await focusExistingOrCreateNewCodeTab(e),global.close&&global.close())}),addListener("popup-website-url","click",async e=>{var t=findEl("popup-website-url").textContent;t&&await focusExistingOrCreateNewCodeTab(t)}),addListener("popup-memory-item-copy-link--"+i,"click",()=>{var e=(r.checkPreferPdf?paperToPDF:paperToAbs)(l),t=r.checkPreferPdf?"PDF":"Abstract";copyAndConfirmMemoryItem(i,e,t+" link copied!",!0)}),addListener("popup-memory-item-copy-hyperlink--"+i,"click",()=>{var e=(r.checkPreferPdf?paperToPDF:paperToAbs)(l),t=r.checkPreferPdf?"PDF":"Abstract";copyAndConfirmMemoryItem(i,e,t+" hyperlink copied!",!0,l.title)}),addListener("popup-memory-item-md--"+i,"click",()=>{var e=makeMdLink(l,r),t=r.checkPreferPdf?"PDF":"Abstract";copyAndConfirmMemoryItem(i,e,`Markdown link to ${t} copied!`,!0)}),addListener("popup-memory-item-bibtex--"+i,"click",()=>{var e=global.state.papers[i].bibtex;let t=bibtexToObject(e);t.hasOwnProperty("url")||(t.url=paperToAbs(global.state.papers[i])),t.hasOwnProperty("pdf")||(t.pdf=paperToPDF(global.state.papers[i])),e=bibtexToString(t),copyAndConfirmMemoryItem(i,e,"Bibtex citation copied!",!0)}),addListener("popup-memory-item-openLocal--"+i,"click",async()=>{var e=await findLocalFile(l)||global.state.files[l.id];e?chrome.downloads.open(e.id):chrome.tabs.create({url:l.pdfLink})}),addListener("popup-memory-item-download--"+i,"click",async()=>{downloadPaperPdf(l)})}else r.checkDirectOpen&&dispatch("memory-switch","click"),o&&global.state.prefs.checkWebsiteParsing&&(setHTML("webite-parsing-root",'
    Parse current website
    '),showId("webite-parsing-root"),addListener("website-trigger-btn","click",async()=>{hideId("website-trigger-btn"),showId("website-loader-container"),hideId("website-parsing-error");let e;try{e=await addOrUpdatePaper({tab:o,url:o.url,store:!1})}catch(e){console.log("error: ",e),hideId("website-loader-container"),showId("website-parsing-error"),setHTML("website-parsing-error",`

    Error

    ${e}
    `)}hideId("website-loader-container"),e?.paper&&editManualWebsite(e.paper,a)}))},query={active:!0,lastFocusedWindow:!0};window.location.href.includes("popup")&&chrome.tabs.query(query,async e=>{chrome.runtime.connect({name:"PaperMemoryPopupSync"});var t=e[0].url;let a,s;s=new Promise(t=>{a=new Promise(e=>{initSyncAndState({stateIsReady:e,remoteIsReady:t})})}),await a;var o=await isPaper(t);Object.values(o).some(e=>e)||showId("notArxiv"),hideId("memory-spinner"),showId("memory-switch"),makeMemoryHTML(),popupMain(t,o,!1,e[0]),-1
    ${o}
    `},getPopupPaperIconsHTML=(e,t,a)=>{var s=e.id,t=isPdfUrl(t)?"HTML":"PDF";let o="",r=(global.state.prefs.checkScirate&&"arxiv"===e.source&&(o=``),""),i=(global.state.prefs.checkVanity&&"arxiv"===e.source&&(r=``),""),l=(global.state.prefs.checkAr5iv&&"arxiv"===e.source&&(i=``),"");global.state.prefs.checkHuggingface&&"arxiv"===e.source&&(l=``);a=global.state.prefs.checkStore&&(a.localFile||a.stored||global.state.files.hasOwnProperty(e.id))?``:``;return("website"===e.source?"":``)+` ${l} ${o} ${r} ${i}`+a},getTagsOptions=e=>{const s=new Set(e.tags);return[...global.state.paperTags].sort().map((e,t)=>{let a='