From 59de86fb255deee37bd8120f8b4a9bd585b7c7b3 Mon Sep 17 00:00:00 2001 From: nikhiltri Date: Wed, 29 May 2019 15:48:10 -0500 Subject: [PATCH] First step at saving a user's artwork history. Saving artwork IDs to a cookie [#14] --- manifest.json | 4 +++- script.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 61d0a40..193d2fa 100644 --- a/manifest.json +++ b/manifest.json @@ -12,6 +12,8 @@ "newtab": "newtab.html" }, "permissions": [ - "activeTab" + "cookies", + "activeTab", + "*://newtab.artic.edu/" ] } diff --git a/script.js b/script.js index a8739f8..2828021 100644 --- a/script.js +++ b/script.js @@ -40,6 +40,25 @@ function getArtworkData() { var downloadUrl = 'https://www.artic.edu/iiif/2/' + imageID + '/full/3000,/0/default.jpg' document.getElementById("download-link").setAttribute('href', downloadUrl); document.getElementById("download-link").setAttribute('download', titlePrint + '.jpg'); + + if (chrome) { + cookie = chrome.cookies.get({ + url: "http://newtab.artic.edu", + name: "tabHistory" + }, function (cookie) { + ids = cookie ? JSON.parse(cookie.value) : []; + console.log(ids); + ids.push("" + myObj.data[0].id); + chrome.cookies.set({ + url: "http://newtab.artic.edu", + name: "tabHistory", + value: JSON.stringify(ids), + }); + }); + } + else { + // Support for other browsers + } } };