From 3f8f79c144970e990975b5d8aa109703eacf50ff Mon Sep 17 00:00:00 2001 From: vict0rsch Date: Tue, 17 Oct 2023 13:10:32 -0400 Subject: [PATCH] add bibmatcher to the popup menu --- src/popup/js/popup.js | 6 ++++++ src/popup/min/popup.min.html | 2 +- src/popup/min/popup.min.js | 2 +- src/popup/popup.html | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/popup/js/popup.js b/src/popup/js/popup.js index 12ebcc57..c17d1ab7 100644 --- a/src/popup/js/popup.js +++ b/src/popup/js/popup.js @@ -263,6 +263,12 @@ const popupMain = async (url, is, manualTrigger = false, tab = null) => { url: chrome.extension.getURL("src/fullMemory/fullMemory.html"), }); }); + // Set BibMatcher page link + addListener("bib-matcher", "click", () => { + chrome.tabs.create({ + url: chrome.extension.getURL("src/fullMemory/bibMatcher.html"), + }); + }); // Set PDF title function // setAndHandleCustomPDFFunction(menu); diff --git a/src/popup/min/popup.min.html b/src/popup/min/popup.min.html index 6f740ddd..3953f941 100755 --- a/src/popup/min/popup.min.html +++ b/src/popup/min/popup.min.html @@ -1,3 +1,3 @@
\ 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='