diff --git a/manifest.json b/manifest.json index 109dd632..c132480d 100755 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Paper Memory", - "version": "0.6.0", + "version": "0.6.1", "manifest_version": 2, "description": "Automatically record papers and their codes from Arxiv, OpenReview & more! Organize your library with tags, links and quick notes.", "homepage_url": "https://papermemory.org", diff --git a/src/background/background.js b/src/background/background.js index 44690589..5e766110 100755 --- a/src/background/background.js +++ b/src/background/background.js @@ -90,17 +90,29 @@ const urlIsAKnownPdfSource = (url) => { const fetchOpenReviewNoteJSON = async (url) => { const id = url.match(/id=([\w-])+/)[0].replace("id=", ""); const api = `https://api.openreview.net/notes?id=${id}`; - return fetch(api).then((response) => { - return response.json(); - }); + let response = await fetch(api); + let json = await response.json(); + if (json["status"] === 404) { + warn("Note not found in api.openreview.net, trying api2.openreview.net..."); + const api2 = `https://api2.openreview.net/notes?id=${id}`; + response = await fetch(api2); + json = await response.json(); + } + return json; }; const fetchOpenReviewForumJSON = async (url) => { const id = url.match(/id=([\w-])+/)[0].replace("id=", ""); const api = `https://api.openreview.net/notes?forum=${id}`; - return fetch(api).then((response) => { - return response.json(); - }); + let response = await fetch(api); + let json = await response.json(); + if (json["status"] === 404 || json["notes"].length === 0) { + warn("Forum not found in api.openreview.net, trying api2.openreview.net..."); + const api2 = `https://api2.openreview.net/notes?forum=${id}`; + response = await fetch(api2); + json = await response.json(); + } + return json; }; const fetchGSData = async (paper) => { @@ -108,7 +120,7 @@ const fetchGSData = async (paper) => { var resultsDom = await fetchDom( `https://scholar.google.com/scholar?q=${encodeURI(paper.title)}&hl=en` ); - const result = queryAll(resultsDom, "#gs_res_ccl_mid h3.gs_rt") + const result = queryAll("#gs_res_ccl_mid h3.gs_rt", resultsDom) .map((h3, idx) => [ miniHash(h3.innerText.toLowerCase().replace("[pdf]", "")), idx, @@ -122,7 +134,7 @@ const fetchGSData = async (paper) => { const citeDom = await fetchDom( `https://scholar.google.fr/scholar?q=info:${dataId}:scholar.google.com/&output=cite&scirp=0&hl=en` ); - const bibURL = queryAll(citeDom, "a.gs_citi") + const bibURL = queryAll("a.gs_citi", citeDom) .find((a) => a.innerText.toLowerCase() === "bibtex") ?.getAttribute("href"); if (bibURL) { diff --git a/src/content_scripts/content_script.js b/src/content_scripts/content_script.js index 784db53e..922063e0 100644 --- a/src/content_scripts/content_script.js +++ b/src/content_scripts/content_script.js @@ -327,6 +327,12 @@ const svg = (name) => { } }; +/** Whether or not to ignore the current paper based on its `is` object + * and the dictionary of sources to ignore + * @param {object} is The `is` object of the current paper + * @param {object} ignoreSources The dictionary of sources to ignore + * @returns {boolean} Whether or not to ignore the current paper + * */ const ignorePaper = (is, ignoreSources) => { const sources = Object.entries(ignoreSources) .filter(([name, ignore]) => ignore) @@ -431,6 +437,7 @@ const contentScriptMain = async ({ * Slides a div in then out, bottom right, with some text to give the user * a feedback on some action performed * @param {string} text the text to display in the slider div + * @returns {void} */ const feedback = (text, paper = null) => { if (document.readyState === "loading") { @@ -505,6 +512,11 @@ const feedback = (text, paper = null) => { }); }; +/** + * Changes the width of the arxiv columns: left is smaller, right is bigger + * @param {string} newColWidth the new width of the left column + * @returns {void} + */ const adjustArxivColWidth = (newColWidth = "33%") => { document .querySelector(".leftcolumn") @@ -514,6 +526,10 @@ const adjustArxivColWidth = (newColWidth = "33%") => { ?.setAttribute("style", `width: ${newColWidth} !important`); }; +/** Adds a paper's venue html element to the arxiv page + * @param {object} paper The paper object + * @returns {void} + * */ const displayPaperVenue = (paper) => { if (!paper.venue) { return; @@ -529,6 +545,10 @@ const displayPaperVenue = (paper) => { findEl("pm-header-content")?.insertAdjacentHTML("afterbegin", venueDiv); }; +/** Adds a paper's code html element to the arxiv page + * @param {object} paper The paper object + * @returns {void} + * */ const displayPaperCode = (paper) => { if (!paper.codeLink) { return; @@ -542,6 +562,11 @@ const displayPaperCode = (paper) => { findEl("pm-extras")?.insertAdjacentHTML("afterbegin", code); }; +/** + * Adds the venue badge to HuggingFace paper pages + * @param {object} paper The paper object + * @param {string} url The current url + */ const huggingfacePapers = (paper, url) => { if (!paper || !paper.venue) return; if (!url || !url.includes("huggingface.co/papers/")) return; @@ -557,7 +582,6 @@ const huggingfacePapers = (paper, url) => { abstractH2 = [...document.querySelectorAll("h2")].find( (h) => h.innerText.trim() === "Abstract" ); - console.log("abstractH2: ", abstractH2); if (!abstractH2) { log("Missing 'Abstract' h2 title on HuggingFace paper page."); } @@ -568,6 +592,11 @@ const huggingfacePapers = (paper, url) => { }, 100); }; +/** + * Handle the ArXiv UI enhancements + * @param {object} checks The user's stored preferences regarding menu options + * @returns {void} + * */ const arxiv = async (checks) => { const { checkMd, checkBib, checkDownload, checkStore } = checks; diff --git a/src/options/options.html b/src/options/options.html index c975459d..b1b7ae3a 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -21,7 +21,7 @@