-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
106 lines (97 loc) · 3.59 KB
/
script.js
File metadata and controls
106 lines (97 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function storageKey() {
return document.querySelector("meta[name=manifest-storage-key]").content;
}
function setDefaultManifest() {
var defaultManifest = {
"name": "Custom Profile PWA",
"short_name": "Custom Profile PWA",
"description": "Test app for exercising PWA functionality",
"categories": ["utilities", "productivity"],
"start_url": "https://mhochk.github.io/custom-manifest-pwa/?custom_param=start_url_value",
"scope":"https://mhochk.github.io/custom-manifest-pwa/",
"display": "minimal-ui",
"orientation": "portrait",
"icons": [
{
"src": "https://mhochk.github.io/custom-manifest-pwa/CustomBlack.png",
"sizes": "150x150",
"type": "image/png"
}
],
"share_target": {
"action": "https://mhochk.github.io/custom-manifest-pwa/?custom_param=share_target_value",
"method": "POST",
"enctype": "multipart/form-data",
"params": {
"title": "mapped_title",
"text": "mapped_text",
"url": "mapped_url",
"files": [
{
"name": "mapped_files",
"accept": ["image/jpeg"]
}
]
}
},
"file_handlers": [
{
"action": "https://mhochk.github.io/custom-manifest-pwa/?custom_param=csv_file_handler",
"accept": {
"text/csv": ".csv"
}
},
{
"action": "https://mhochk.github.io/custom-manifest-pwa/?custom_param=jpeg_file_handler",
"accept": {
"image/jpeg": [ ".jpg", ".jpeg" ]
}
},
{
"action": "https://mhochk.github.io/custom-manifest-pwa/?custom_param=graph_file_handler",
"accept": {
"application/vnd.grafr.graph": [ ".grafr", ".graf" ],
"application/vnd.alternative-graph-app.graph": ".graph"
}
}
],
"related_applications": [
{
"platform": "browser",
"id": "Microsoft.MicrosoftEdge.Stable_8wekyb3d8bbwe"
},
{
"platform": "browser",
"id": "Microsoft.MicrosoftEdge.Canary_8wekyb3d8bbwe"
}
]
};
localStorage.setItem(storageKey(), JSON.stringify(defaultManifest, null, " "));
}
document.addEventListener('DOMContentLoaded', ()=> {
// Hook up the buttons
document.getElementById("update").addEventListener("click", () => {
localStorage.setItem(storageKey(), document.getElementById("manifestText").value);
location.reload();
});
document.getElementById("reset").addEventListener("click", () => {
setDefaultManifest();
location.reload();
});
// Add the manifest early so it is noticed automatically
document.head.innerHTML += "<link rel='manifest' href='data:application/manifest+json," + localStorage.getItem(storageKey()).replaceAll("'", "'") + "'>";
document.getElementById("manifestText").value = localStorage.getItem(storageKey());
// Register the service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then ((reg) => {
console.log('serviceWorker.register successfully returned: ', reg);
}).catch((e) => {
console.error('serviceWorker.register returned failure: ', e);
});
}
})
// Establish the default manifest value to use, if not already defined
if (!localStorage.getItem(storageKey())) {
setDefaultManifest();
}