From 4221bf6e7a4303c2b91bfd5391c383449e0aa060 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Thu, 2 Feb 2023 16:30:14 -0500 Subject: [PATCH 1/4] use "_" in older arxiv ids not to use / which breaks JQuery --- src/background/background.js | 2 +- src/shared/js/utils/paper.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/background/background.js b/src/background/background.js index 316c10fd..44690589 100755 --- a/src/background/background.js +++ b/src/background/background.js @@ -167,7 +167,7 @@ const fetchPWCData = async (arxivId, title) => { const findCodesForPaper = async (request) => { let arxivId, title, code; if (request.paper.source === "arxiv") { - arxivId = request.paper.id.split("-").last(); + arxivId = request.paper.id.split("-").last().replace("_", "/"); } else { title = request.paper.title; } diff --git a/src/shared/js/utils/paper.js b/src/shared/js/utils/paper.js index dd6fd2c4..5737af51 100644 --- a/src/shared/js/utils/paper.js +++ b/src/shared/js/utils/paper.js @@ -696,7 +696,8 @@ const parseIdFromUrl = async (url) => { .replace("/abs/", "/pdf/") .split("/pdf/")[1] .replace(".pdf", "") - .split("v")[0]; + .split("v")[0] + .replace("/", "_"); idForUrl = `Arxiv-${arxivId}`; const existingIds = Object.values(global.state.titleHashToIds).find((ids) => From 9b71d0cbefe4e7478fd540ec6cb9918f5b7c7230 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Thu, 2 Feb 2023 16:30:23 -0500 Subject: [PATCH 2/4] use new arxiv id --- src/shared/js/utils/parsers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/js/utils/parsers.js b/src/shared/js/utils/parsers.js index 222b581c..27a4921e 100644 --- a/src/shared/js/utils/parsers.js +++ b/src/shared/js/utils/parsers.js @@ -18,7 +18,7 @@ const flipAndAuthors = (authors) => // ------------------- const fetchArxivXML = async (paperId) => { - const arxivId = paperId.replace("Arxiv-", ""); + const arxivId = paperId.replace("Arxiv-", "").replace("_", "/"); return fetch( "https://export.arxiv.org/api/query?" + new URLSearchParams({ id_list: arxivId }) @@ -304,14 +304,14 @@ const makeArxivPaper = async (url) => { year + firstNonStopLowercase(title); - const id = `Arxiv-${arxivId}`; + const id = `Arxiv-${arxivId.replace("/", "_")}`; let bibtex = ""; bibtex += `@article{${key},\n`; bibtex += ` title={${title} },\n`; bibtex += ` author={${author} },\n`; bibtex += ` year={${year}},\n`; - bibtex += ` journal={arXiv preprint arXiv: ${id}}\n`; + bibtex += ` journal={arXiv preprint arXiv: ${arxivId}}\n`; bibtex += `}`; const venue = ""; From 4284d7f2c6fff881bbf28ac4f74b5e2abe7d87bf Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Thu, 2 Feb 2023 16:30:40 -0500 Subject: [PATCH 3/4] parse true ID from id with _ --- src/popup/js/popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup/js/popup.js b/src/popup/js/popup.js index 4db44dd6..fbff674a 100644 --- a/src/popup/js/popup.js +++ b/src/popup/js/popup.js @@ -239,7 +239,7 @@ const popupMain = async (url, is, manualTrigger = false) => { // ----- SVG clicks ----- // ------------------------ addListener(`popup-memory-item-scirate--${id}`, "click", () => { - const arxivId = paper.id.split("-").last(); + const arxivId = paper.id.split("-").last().replace("_", "/"); const scirateURL = `https://scirate.com/arxiv/${arxivId}`; chrome.tabs.update({ url: scirateURL }); window.close(); From 2d4750acf0dc33d34608579f7637f7ca0b813a61 Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Thu, 2 Feb 2023 16:30:42 -0500 Subject: [PATCH 4/4] build --- src/popup/min/popup.min.js | 2 +- src/shared/min/utils.min.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/popup/min/popup.min.js b/src/popup/min/popup.min.js index ea7b9c66..e85e6d0d 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)},handleOpenItemCodeLink=e=>{e=eventId(e),e=global.state.papers[e].codeLink;focusExistingOrCreateNewCodeTab(e)},handleCopyMarkdownLink=async e=>{var e=eventId(e),t=global.state.prefs,a=t.checkPreferPdf?"PDF":"Abstract",o=global.state.papers[e],o=makeMdLink(o,t);copyAndConfirmMemoryItem(e,o,`Markdown ${a} link copied!`)},handleCopyBibtex=e=>{var e=eventId(e),t=global.state.papers[e].bibtex;copyAndConfirmMemoryItem(e,bibtexToString(t),"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!")},handleAddItemToFavorites=e=>{var e=eventId(e),t=hasClass("memory-container--"+e,"favorite");saveFavoriteItem(e,!t)},handleMemoryOpenLocal=e=>{e=eventId(e),e=global.state.files[e];e&&(e.id||0===e.id)&&chrome.downloads.open(e.id)},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"),o=findEl(e,"extended-item"),s=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(s,150),slideDown(l,150),slideDown(r,150),slideUp(o,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(s,150),slideUp(l,150),slideUp(r,150),slideDown(o,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,o=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(o),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=t.key;if(!(["Backspace","Enter","Escape","a","e"].indexOf(a)<0))if(global.state.prefsIsOpen)"Escape"===a?(t.preventDefault(),closeMenu()):"Enter"===a&&document.querySelector("#menu-switch:focus")&&closeMenu();else if(global.state.memoryIsOpen){if("Enter"===a){if(document.querySelector("#filter-favorites:focus"))return void dispatch("filter-favorites","click");if(document.querySelector("#memory-sort-arrow:focus")&&"Enter"===a)return void dispatch("memory-sort-arrow","click")}let e;const o=document.querySelector(".memory-container:focus");if("Escape"!==a){if(!o)return;e=o.id.split("--")[1]}"Backspace"===a?dispatch(findEl(e,"memory-delete"),"click"):"Enter"===a?dispatch(findEl(e,"memory-item-link"),"click"):"Escape"===a?(t.preventDefault(),o&&hasClass(o,"expand-open")?handleTogglePaperEdit(t):closeMemory()):"e"===a&&dispatch(findEl(e,"memory-item-edit"),"click")}else if("a"===a){const e=queryAll(document,":focus");if(e&&e.length&&e.some(e=>hasClass(e,"noMemoryOnA")))return;global.state.papers&&dispatch("memory-switch","click")}else"Enter"===a&&("memory-switch-open"===(t=document.querySelector(":focus")).id?dispatch("memory-switch","click"):"menu-switch"===t.id?(dispatch("menu-switch","click"),dispatch("menu-switch","blur")):hasClass(t,"memory-item-svg-div")&&dispatch(t,"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 o=await getStorage("prefs")??{};o[t]=a,setStorage("prefs",o,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:o}=getPaperEdits(e,!0);updatePaperTags(e,"#popup-item-tags--"+e),saveNote(e,t),saveCodeLink(e,a),saveFavoriteItem(e,o)},handlePopupDeletePaper=e=>()=>{showConfirmDeleteModal(e)},getMemoryItemHTML=(e,t)=>{var a=new Date(e.addDate).toLocaleString().replace(",",""),o=new Date(e.lastOpenDate).toLocaleString().replace(",",""),s=getDisplayId(e.id),r=e.note||"",i=e.id,l=new Set(e.tags),n=getTagsOptions(e),d=e.favorite?"favorite":"",c=(t.pdfLink="Open link to "+e.title,t.copyLink="Open link to the paper's "+(global.state.prefs.checkPreferPdf?"PDF":"abstract"),`${e.codeLink||""}`);let p='
';e.note&&(p=`
Note: ${r}
`);var m=global.state.files.hasOwnProperty(e.id)?`
${tablerSvg("vocabulary","",["memory-icon-svg"])}
`:"";return`

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

${[...l].map(e=>`${e}`).join("")}
${cutAuthors(e.author)}
${c} ${p}
${tablerSvg("writing","",["memory-icon-svg"])}
${s}
${m}
${tablerSvg("markdown","",["memory-icon-svg"])}
${tablerSvg("math-function","",["memory-icon-svg"])}
Visits: ${e.count}
-
`},getPopupEditFormHTML=e=>{var t=e.id,a=getTagsOptions(e),o=e.note||"",s=getDisplayId(e.id);return`
Tags:
${s}
`},getPopupPaperIconsHTML=(e,t,a)=>{var o=e.id,t=isPdfUrl(t)?"HTML":"PDF";let s="";global.state.prefs.checkScirate&&"arxiv"===e.source&&(s=``);e=global.state.prefs.checkStore&&(a.localFile||a.stored)?``:``;return`${s}`+e},getTagsOptions=e=>{const o=new Set(e.tags);return[...global.state.paperTags].sort().map((e,t)=>{let a='