-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
93 lines (81 loc) · 3.35 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Cookie Converter</title>
</head>
<body class="pt-5">
<div class="container" id="app">
<div class="row">
<div class="col-5">
<textarea class="form-control" rows="15" v-model="netscape"></textarea>
</div>
<div class="col-2 text-center">
<div>
<button class="btn btn-primary" @click="NetscapeToJson">Netscape →</button>
</div>
<div class="mt-1">
<button class="btn btn-primary" @click="JsonToNetscape">← JSON</button>
</div>
</div>
<div class="col-5">
<textarea class="form-control" rows="15" v-model="json"></textarea>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
var app = new Vue({
el: '#app',
data: {
netscape: '',
json: '',
},
methods: {
JsonToNetscape() {
const data = JSON.parse(this.json);
if (data) {
this.netscape = '';
data.forEach((row) => {
if (typeof row.value === 'undefined') return;
this.netscape +=
`${row.domain}\t${row.httpOnly.toString().toUpperCase()}\t${row.path}\t${row.secure.toString().toUpperCase()}\t${row.expirationDate}\t${row.name}\t${row.value}\n`;
});
}
},
NetscapeToJson() {
const data = this.netscape;
const lines = data.split('\n');
let result = [];
lines.forEach(line => {
const parts = line.split('\t');
let row = {};
row.domain = typeof parts[0] === 'undefined' ? null : parts[0];
row.httpOnly = typeof parts[1] === 'undefined' ? null : parts[1] === 'TRUE' ?
true : false;
row.path = typeof parts[2] === 'undefined' ? null : parts[2];
row.secure = typeof parts[3] === 'undefined' ? null : parts[3] === 'TRUE' ?
true : false;
row.expirationDate = typeof parts[4] === 'undefined' ?
null : parseInt(parts[4]);
row.name = typeof parts[5] === 'undefined' ? null : parts[5];
row.value = typeof parts[6] === 'undefined' ? null : parts[6];
result.push(row);
});
this.json = JSON.stringify(result);
}
}
})
</script>
<style>
textarea {
width: 100%;
}
</style>
</body>
</html>