From fe114dd8de3f98cd5f2f866982df760fcf5c3534 Mon Sep 17 00:00:00 2001 From: Martin Scavnicky Date: Sun, 6 Mar 2016 12:09:30 +0000 Subject: [PATCH] Load list of unsplash images when starting background page. --- background.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/background.js b/background.js index 066719c..f8fa0d0 100644 --- a/background.js +++ b/background.js @@ -2,6 +2,19 @@ var options = defaultOptions; // Hash of times in milliseconds when particular domain was blocked. var unblockTimes = {}; +// The list of preloaded unsplash image links +var imageList = []; + +function loadImageList() { + var request = new XMLHttpRequest(); + request.onreadystatechange = function() { + if (request.readyState == 4 && request.status == 200) { + imageList = JSON.parse(request.response); + } + }; + request.open("GET", "https://unsplash.it/list", true); + request.send(); +} // Determine whether specific hostname is currently blocked. Domain is blocked // if it is in the blocklist and was not recently unblocked. @@ -42,6 +55,8 @@ function parsedBlocklist(blocklist) { }); } +loadImageList(); + // Load the options from storage. chrome.storage.sync.get(options, function(items) { _.mapObject(items, function (value, key) {