From 77163e047b85d4ad6751b5740a64f56cf719baaa Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Mon, 8 Oct 2018 14:48:51 -0400 Subject: [PATCH] Add art homepage assets --- index.html | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 37 +++++++++++ 2 files changed, 222 insertions(+) create mode 100644 index.html create mode 100644 index.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..267b0f0 --- /dev/null +++ b/index.html @@ -0,0 +1,185 @@ + + +New Tab + + + + + +
+ +
+ + + diff --git a/index.js b/index.js new file mode 100644 index 0000000..e4836c1 --- /dev/null +++ b/index.js @@ -0,0 +1,37 @@ +function ajax_get(url, callback) { + var xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { + try { + var data = JSON.parse(xmlhttp.responseText); + } catch(err) { + return callback(err); + } + return callback(null, data); + } + }; + + xmlhttp.open('GET', url, true); + xmlhttp.send(); +} + +function setBG() { + var url = 'https://www.gstatic.com/culturalinstitute/tabext/imax.json'; + ajax_get(url, function(err, data) { + if (err) { + console.log('We\'ve had a problem'); + } + var photoID = Math.floor((Math.random() * data.length)); + var item = data[photoID]; + if (item.title) document.getElementById('title').text = item.title; + if (item.creator) document.getElementById('creator').text = item.creator; + if (item.attribution) document.getElementById('partner').text = item.attribution; + document.body.style.background = 'url('+item.image+'=s1200) no-repeat center center fixed'; + document.body.style['-webkit-background-size'] = 'cover'; + document.body.style['-moz-background-size'] = 'cover'; + document.body.style['-o-background-size'] = 'cover'; + document.body.style['background-size'] = 'cover'; + }); +} + +setBG();