-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·60 lines (37 loc) · 1.48 KB
/
index.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
window.onload = loadTimeFunction;
var defaultInput = "url";
var defaultProtocol = "http://";
var objectiveTextAreaSize = 250;
var textAreaOffset = objectiveTextAreaSize / 2;
var textAreaInterval = new Array();
function loadTimeFunction() {
intervalBarIncrease("url");
intervalBarIncrease("query");
var selectedInput = document.getElementById(defaultInput);
selectedInput.focus();
selectedInput.select();
}
function intervalBarIncrease(selectedTextArea) {
var objectiveTextArea = document.getElementById(selectedTextArea);
var textAreaRect = objectiveTextArea.getBoundingClientRect();
textAreaInterval[selectedTextArea] = window.setInterval(function() { barIncrease(selectedTextArea, objectiveTextArea, textAreaRect) }, 5);
}
function barIncrease(selectedTextArea, objectiveTextArea, textAreaRect) {
var elementWidth = parseInt(objectiveTextArea.style.width);
elementWidth = elementWidth + 1;
objectiveTextArea.style.width = elementWidth + "px";
objectiveTextArea.style.left = textAreaRect.left + (textAreaOffset - (elementWidth / 2)) + "px";
if (parseInt(objectiveTextArea.style.width) >= objectiveTextAreaSize) {
window.clearInterval(textAreaInterval[selectedTextArea]);
}
}
function submitURL() {
var protocolPattern = /http[s]*:/i
var destinationURL = document.getElementById("url").value;
if (document.getElementById("url").value.match(protocolPattern)) {
window.location.assign(destinationURL);
}
else {
window.location.assign(defaultProtocol + destinationURL);
}
}