Added manifest.json and serviceworker for more functioning webapps

This commit is contained in:
Kasper Rynning-Tønnesen
2016-04-27 00:25:48 +02:00
parent 503e2057ba
commit b76b56ba7a
8 changed files with 216 additions and 20 deletions

103
static/dist/lib/cache-polyfill.js vendored Normal file
View File

@@ -0,0 +1,103 @@
/**
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
(function() {
var nativeAddAll = Cache.prototype.addAll;
var userAgent = navigator.userAgent.match(/(Firefox|Chrome)\/(\d+\.)/);
// Has nice behavior of `var` which everyone hates
if (userAgent) {
var agent = userAgent[1];
var version = parseInt(userAgent[2]);
}
if (
nativeAddAll && (!userAgent ||
(agent === 'Firefox' && version >= 46) ||
(agent === 'Chrome' && version >= 50)
)
) {
return;
}
Cache.prototype.addAll = function addAll(requests) {
var cache = this;
// Since DOMExceptions are not constructable:
function NetworkError(message) {
this.name = 'NetworkError';
this.code = 19;
this.message = message;
}
NetworkError.prototype = Object.create(Error.prototype);
return Promise.resolve().then(function() {
if (arguments.length < 1) throw new TypeError();
// Simulate sequence<(Request or USVString)> binding:
var sequence = [];
requests = requests.map(function(request) {
if (request instanceof Request) {
return request;
}
else {
return String(request); // may throw TypeError
}
});
return Promise.all(
requests.map(function(request) {
if (typeof request === 'string') {
request = new Request(request);
}
var scheme = new URL(request.url).protocol;
if (scheme !== 'http:' && scheme !== 'https:') {
throw new NetworkError("Invalid scheme");
}
return fetch(request.clone());
})
);
}).then(function(responses) {
// If some of the responses has not OK-eish status,
// then whole operation should reject
if (responses.some(function(response) {
return !response.ok;
})) {
throw new NetworkError('Incorrect response status');
}
// TODO: check that requests don't overwrite one another
// (don't think this is possible to polyfill due to opaque responses)
return Promise.all(
responses.map(function(response, i) {
return cache.put(requests[i], response);
})
);
}).then(function() {
return undefined;
});
};
Cache.prototype.add = function add(request) {
return this.addAll([request]);
};
}());

File diff suppressed because one or more lines are too long

BIN
static/images/144x144.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@@ -1,4 +1,4 @@
var chan = $("#chan").html();
var chan = window.chan == undefined ? $("#chan").html() : window.chan;
var w_p = true;
var hasadmin = 0;
var showToggle = true;
@@ -54,6 +54,18 @@ var connection_options = {
'force new connection': true
};
if (navigator.serviceWorker) {
navigator.serviceWorker.register('/service-worker.js')
.then(function (registration) {
console.log(registration);
})
.catch(function (e) {
console.error(e);
})
} else {
console.log('Service Worker is not supported in this browser.');
}
$().ready(function(){
if(!window.fromFront && window.location.pathname != "/") init();
});
@@ -61,7 +73,8 @@ $().ready(function(){
function init(){
chan = $("#chan").html();
chan = window.chan == undefined ? $("#chan").html() : window.chan;
console.log(chan);
mobile_beginning = window.mobilecheck();
window.onpopstate = function(e){
@@ -71,7 +84,7 @@ function init(){
share_link_modifier_channel();
if(window.location.hostname == "zoff.no") add = "https://zoff.no";
else add = "localhost";
else add = window.location.hostname;
//setTimeout(function(){
@@ -80,12 +93,6 @@ function init(){
//window.submit = Search.submit;
//window.submitAndClose = Search.submitAndClose;
if(!localStorage["list_update"] || localStorage["list_update"] != "13.06.15")
{
localStorage.setItem("list_update", "13.06.15");
window.location.reload(true);
}
$('ul.playlist-tabs').tabs();
$('ul.playlist-tabs-loggedIn').tabs();
$('.chatTabs').tabs();
@@ -502,7 +509,6 @@ function onepage_load(){
url: "php/nochan.php",
success: function(e){
socket.disconnect();
document.getElementById("volume-button").removeEventListener("click", Playercontrols.mute_video);
@@ -521,10 +527,10 @@ function onepage_load(){
$("main").attr("class", "center-align container");
$("body").attr("id", "");
$("body").attr("style", "");
$("header").html($($(e)[57]).html());
$($(e)[59]).insertAfter("header");
$($(e)[61]).insertAfter(".mega");
$("main").html($($(e)[65]).html());
$("header").html($($(e)[59]).html());
$($(e)[61]).insertAfter("header");
$($(e)[63]).insertAfter(".mega");
$("main").html($($(e)[67]).html());
$(".page-footer").removeClass("padding-bottom-extra");
$(".page-footer").removeClass("padding-bottom-novideo");
$("#favicon").attr("href", "static/images/favicon.png");

View File

@@ -235,14 +235,17 @@ var Nochan = {
$("body").css("background-color", "#2d2d2d");
socket.disconnect();
if(!popstate) window.history.pushState("to the channel!", "Title", "/" + chan + "/");
if(!popstate){
window.history.pushState("to the channel!", "Title", "/" + chan);
window.chan = chan;
}
$(".mega").remove();
$(".mobile-search").remove();
$("main").attr("class", "container center-align main");
$("body").attr("id", "channelpage");
$("header").html($($(e)[57]).html());
$("main").html($($(e)[61]).html());
$("header").html($($(e)[59]).html());
$("main").html($($(e)[63]).html());
$("#search").attr("placeholder", "Find song on YouTube...");
$(".page-footer").addClass("padding-bottom-novideo");
if($("#alreadychannel").length == 1){
@@ -252,6 +255,7 @@ var Nochan = {
window.init();
}
if($("#alreadyfp").length == 0) $("head").append("<div id='alreadyfp'></div>");
}
});
}
@@ -304,7 +308,7 @@ function initfp(){
};
if(window.location.hostname == "zoff.no") add = "https://zoff.no";
else add = "localhost";
else add = window.location.hostname;
socket = io.connect(''+add+':8880', connection_options);
socket.on('playlists', function(msg){
$("#channels").empty();