-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.js
74 lines (68 loc) · 2.12 KB
/
repo.js
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
'use strict';
function repo_init(){
core_repo_init({
'events': {
'file-to-uri': {
'onclick': function(){
const files = core_elements['file'].files;
if(files.length === 0){
return;
}
core_file({
'file': files[0],
'todo': function(event){
core_elements['uri'].value = event.target.result;
},
});
},
},
'open': {
'onclick': function(){
globalThis.open(
core_elements['uri'].value,
'_blank',
'noreferrer'
);
},
},
'parse': {
'onclick': function(){
if(core_elements['parsed'].textContent.length > 0){
core_elements['parsed'].textContent = '';
return;
}
let result = '';
const uri = new URL(core_elements['uri'].value);
const components = {
'hash': uri['hash'],
'host': uri['host'],
'origin': uri['origin'],
'pathname': '<textarea readonly>' + uri['pathname'] + '</textarea>',
'port': uri['port'],
'protocol': uri['protocol'],
'search': uri['search'],
};
for(const component in components){
result += '<tr><td>' + component + '<td>' + components[component];
}
core_elements['parsed'].innerHTML = result;
},
},
},
'info': '<textarea id=uri></textarea><br>'
+ '<button id=open type=button>Open URI</button>'
+ '<button id=parse type=button>Toggle Parse</button>'
+ '<table id=parsed></table>'
+ '<input id=file type=file><button id=file-to-uri type=button>Convert File to URI</button>',
'menu-lock': true,
'storage': {
'uri': 'data:,',
},
'title': 'URI.htm',
'ui-elements': [
'file',
'parsed',
'uri',
],
});
}