1 function get_query_params(url
) {
2 var search
= (new URL(url
)).search
;
7 var params
= search
.substring(1).split('&');
8 params
.forEach(function(param
) {
9 var element
= param
.split('=');
10 ret
[decodeURIComponent(element
[0])] = decodeURIComponent(element
[1]);
15 function get_request_init(params
) {
17 if (params
['method']) {
18 init
['method'] = params
['method'];
21 init
['mode'] = params
['mode'];
23 if (params
['credentials']) {
24 init
['credentials'] = params
['credentials'];
26 if (params
['redirect-mode']) {
27 init
['redirect'] = params
['redirect-mode'];
32 self
.addEventListener('fetch', function(event
) {
33 var params
= get_query_params(event
.request
.url
);
34 var init
= get_request_init(params
);
35 var url
= params
['url'];
36 if (params
['ignore']) {
39 if (params
['reject']) {
40 event
.respondWith(new Promise(function(resolve
, reject
) {
45 if (params
['resolve-null']) {
46 event
.respondWith(new Promise(function(resolve
) {
51 if (params
['generate-png']) {
53 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAA' +
54 'RnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAhSURBVDhPY3wro/Kf' +
55 'gQLABKXJBqMGjBoAAqMGDLwBDAwAEsoCTFWunmQAAAAASUVORK5CYII=');
56 var array
= new Uint8Array(binary
.length
);
57 for(var i
= 0; i
< binary
.length
; i
++) {
58 array
[i
] = binary
.charCodeAt(i
)
60 event
.respondWith(new Response(new Blob([array
], {type
: 'image/png'})));
63 event
.respondWith(new Promise(function(resolve
, reject
) {
64 var request
= event
.request
;
66 request
= new Request(url
, init
);
68 fetch(request
).then(resolve
, reject
);