Going offline at Indie Web Camp Düsseldorf

IndieWebCamp Düsseldorf 2017
IndieWebCamp Düsseldorf 2017
IndieWebCamp Düsseldorf 2017
IndieWebCamp Düsseldorf 2017
IndieWebCamp Düsseldorf 2017
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
window.addEventListener('load', function() {
var data = {
"title": "A minority report on artificial intelligence",
"description": "Revisiting Spielberg’s films after a decade and a half.",
"published": "May 7th, 2017",
"timestamp": "1494171049"
};
localStorage.setItem(
window.location.href,
JSON.stringify(data)
);
});
}
var data = {
"title": document.querySelector("title").innerText,
"description": document.querySelector("meta[name='description']").getAttribute("contents")
}
const browsingHistory = [];
caches.open('pages')
.then( cache => {
cache.keys()
.then(keys => {
keys.forEach( request => {
let data = JSON.parse(localStorage.getItem(request.url));
if (data) {
data['url'] = request.url;
browsingHistory.push(data);
}
});
browsingHistory.sort( (a,b) => {
return b.timestamp - a.timestamp;
});
let markup = '';
browsingHistory.forEach( data => {
markup += `
<h2><a href="${ data.url }">${ data.title }</a></h2>
<p>${ data.description }</p>
<p class="meta">${ data.published }</p>
`;
});
let container = document.getElementById('history');
container.insertAdjacentHTML('beforeend', markup);

--

--

--

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to clean your local branch

How to Quickly Create a Beautiful Custom Button Using Touchables in React Native

Voting results of proposal to stop DMD/EOS-LP and HUB/EOS-LP

The New Web: Part 1 — Tools and Resources For A Heavyweight JavaScript Experience

//platform.twitter.com/widgets.js from Twitter https://twitter.com/RAHLawFirm

How to upgrade to exact-by-default object type syntax

Day02 of #100DaysOfCode

8 JavaScript Guidelines To Help You Write Better Codes

A laptop with codes written in it

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jeremy Keith

Jeremy Keith

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com

More from Medium

Project Lamora

Project Lamora

Headless components in React and why I stopped using a UI library for our design system

Figma to Webflow.

Create Material UI TextField variants

material ui textfield variants