diff --git a/js/background.js b/js/background.js
index 47b29a7..87a75d3 100644
--- a/js/background.js
+++ b/js/background.js
@@ -5,6 +5,7 @@ var unblockTimes = {};
// Default URL for the background image. Should always load.
DEFAULT_IMAGE_URL = 'https://source.unsplash.com/collection/323879/1440x900/daily';
+
// Cached URL or the last displayed image.
var imageUrl = DEFAULT_IMAGE_URL;
@@ -73,18 +74,33 @@ function blockingHtml() {
return request.responseText.replace(/{{imageUrl}}/g, imageUrl);
}
+function hasCustomBackground() {
+ var userBackgrounds = window.options.background.split(',');
+ return userBackgrounds.length > 0 && userBackgrounds[0] != "";
+}
+
+function randomUserBackground() {
+ var userBackgrounds = window.options.background.split(',');
+ var randomUserBackground = userBackgrounds[Math.floor(Math.random()*userBackgrounds.length)]
+ return randomUserBackground;
+}
+
// The default image URL we are currently using, redirects to the actual URL
// of the actual image. This is slow and destroys user experience. Therefore we
// do cache the URL of the actual image in a global variable.
function refreshImageUrl() {
- var request = new XMLHttpRequest();
- request.onreadystatechange = function() {
- if (request.status === 200) {
- imageUrl = request.responseURL;
- }
- };
- request.open('GET', DEFAULT_IMAGE_URL)
- request.send();
+ if (hasCustomBackground()) {
+ imageUrl = randomUserBackground();
+ } else {
+ var request = new XMLHttpRequest();
+ request.onreadystatechange = function() {
+ if (request.readyState === XMLHttpRequest.DONE && request.status === 200) {
+ imageUrl = request.responseURL;
+ }
+ };
+ request.open('GET', imageUrl)
+ request.send();
+ }
}
// Fetch image URL on startup to speed up the first image load.
diff --git a/js/options.js b/js/options.js
index 814fe1d..501217e 100644
--- a/js/options.js
+++ b/js/options.js
@@ -3,7 +3,8 @@ function saveOptions() {
waitTime: $('waitTime').value,
blockTime: $('blockTime').value,
blocklist: $('blocklist').value,
- whitelist: $('whitelist').value
+ whitelist: $('whitelist').value,
+ background: $('background').value
};
chrome.storage.sync.set(options, function() {
@@ -18,6 +19,7 @@ function restoreOptions() {
$('blockTime').value = items.blockTime;
$('blocklist').value = items.blocklist;
$('whitelist').value = items.whitelist;
+ $('background').value = items.background;
// Setting value does not trigger click oninput event.
$('waitTimeOutput').value = humanizeTime(items.waitTime);
diff --git a/js/waitblock.js b/js/waitblock.js
index cb79ddd..cf7c2cc 100644
--- a/js/waitblock.js
+++ b/js/waitblock.js
@@ -7,5 +7,7 @@ var defaultOptions = {
// The list of domains to block. Covers subdomains as well.
blocklist: 'facebook.com',
// The list of subdomains to allow.
- whitelist: 'l.facebook.com'
+ whitelist: 'l.facebook.com',
+ // The list of background URLs to randomize from.
+ background: ''
};
diff --git a/options.html b/options.html
index 43c071f..2db4b99 100644
--- a/options.html
+++ b/options.html
@@ -91,6 +91,20 @@
+
+
+
+
+ Comma separated list of background URLs to randomize from (e.g.
+ https://i.imgur.com/zu5Nno5.jpg)
+
+
+
+
+
+
+
+