forked from meibenny/countletters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
60 lines (45 loc) · 1.37 KB
/
scripts.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
/* get input from query string */
function findParameters (parameter) {
// cut out the question mark at the beginning of the query string
var queryString = window.location.search.substring(1)
var variables = queryString.split('&')
var pair = []
for (var i = 0; i < variables.length; i++) {
pair = variables[i].split('=')
if (pair[0] === parameter) {
return pair[1]
}
}
return false
}
function countLetters () { // eslint-disable-line no-unused-vars
var textIn = ''
var charCount = {}
var textInLength = 0
// get input from query string
textIn = findParameters('data') || ''
document.getElementById('inputbox').innerHTML = textIn
textIn = textIn.replace(/\+/g, '')
if (window.location.href.indexOf('caps=1') === -1) {
textIn = textIn.toLowerCase()
} else {
document.getElementById('caps-checkbox').checked = true
}
textIn = decodeURIComponent(textIn)
textInLength = textIn.length
for (var i = 0; i < textInLength; i++) {
charCount[textIn.charAt(i)] = 0
}
for (var i = 0; i < textInLength; i++) { // eslint-disable-line no-redeclare
charCount[textIn.charAt(i)] += 1
}
textIn = ''
for (var eachProperty in charCount) {
textIn +=
eachProperty +
"<span class='multiplier'>(" +
charCount[eachProperty] +
'x)</span><br>'
}
document.getElementById('results').innerHTML += textIn
}