-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
154 lines (140 loc) · 4.69 KB
/
app.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const app = Vue.createApp({
data() {
return {
name: "Tags Input",
tags_name: [],
bar: null,
}
},
methods: {
load_progress() {
this.bar = new ProgressBar.Circle('#cont', {
color: '#aaa',
strokeWidth: 4,
trailWidth: 2,
easing: 'easeInOut',
duration: 200,
text: {
autoStyleContainer: false
},
from: {
color: '#FFEA82',
a: 0
},
to: {
color: '#ED6A5A',
a: 1
},
step: function (state, circle) {
circle.path.setAttribute('stroke', state.color);
var value = Math.round(circle.value() * 30);
if (value === 0) {
circle.setText('');
} else {
circle.setText(value);
}
}
});
this.bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif';
this.bar.text.style.fontSize = '2rem';
},
convert() {
const tags = document.getElementById('tags').value;
let output = "";
const english = /^[A-Za-z0-9]*$/;
tags.split('\n').forEach(function (item) {
if (item.length > 0) {
if (english.test(item[0])) {
output += '#' + item.trim().replace(/ /g, '') + ' ';
} else {
output += '#' + item.trim().replace(/ /g, '_') + ' ';
}
}
});
this.tagcount();
outarea = document.getElementById('output');
outarea.value = output;
outarea.scrollTo(0, outarea.scrollHeight);
},
select() {
const dots = document.getElementById('dotcheck').checked;
const tags = document.getElementById('output');
if (dots == true) {
output = ".\n";
output = output.repeat(5);
tags.value = output + tags.value;
} else {
this.convert();
tags.value = tags.value;
}
tags.scrollTo(0, tags.scrollHeight);
// console.log(tags);
tags.select();
document.execCommand('copy');
},
tagcount() {
const tags = document.getElementById('tags').value;
const out = document.getElementById('outcount');
const counts = tags.split('\n').length;
this.bar.animate(counts / 30);
},
cleartext() {
document.getElementById('tags').value = ''
document.getElementById('output').value = ''
this.bar.animate(0)
},
save_tags() {
const value = this.$refs.tags.value
if (!value){return}
console.log('val', value)
const name = prompt('please enter a name for these tags:')
if (!name){return}
if (this.tags_name.includes(name)){
const overwrite = confirm('this name already exists, do you want to overwrite it?')
if (!overwrite){return}
}
set_item(`tags_${name}`, value)
this.load_tags_name()
},
load_tags_name() {
console.log('names', Object.entries(localStorage))
this.tags_name = []
for (const [key, value] of Object.entries(localStorage)) {
if (key.startsWith('tags_')) {
this.tags_name.push(key.replace('tags_', ''))
}
}
},
load_tags(name) {
const tags = get_item(`tags_${name}`)
this.$refs.tags.value = tags
this.tagcount()
this.convert()
},
remove_tags(name) {
const remove = confirm('are you sure you want to remove these tags?')
if (!remove){return}
localStorage.removeItem(`tags_${name}`)
this.load_tags_name()
}
},
mounted: function () {
this.load_tags_name()
this.load_progress()
}
})
app.mount('#app')
function set_item(key, value, encode = false) {
if (encode) {
localStorage.setItem(key, JSON.stringify(value))
} else {
localStorage.setItem(key, value)
}
}
function get_item(key, encoded = false) {
if (encoded) {
return JSON.parse(localStorage.getItem(key))
} else {
return localStorage.getItem(key)
}
}