forked from ryanlyrl/CUHacking2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.js
More file actions
110 lines (95 loc) · 2.51 KB
/
actions.js
File metadata and controls
110 lines (95 loc) · 2.51 KB
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
function clickButton(buttonText, index){
var matches = [];
$("a").each(function() {
if($(this).text().toLowerCase().includes(buttonText.toLowerCase())){
//console.log($(this).text() + " clicked.");
matches.push($(this));
//$(this)["0"].click();
//return;
}
});
$("button").each(function(){
if($(this).text().toLowerCase().includes(buttonText.toLowerCase())){
//$(this)["0"].click();
matches.push($(this));
}
});
matches[index]["0"].click();
//}
// for(i = 0;i < matches.length;i++){
// matches[i]["0"].click();
// }
}
function lengthButton (buttonText){
var matches = [];
$("a").each(function() {
if($(this).text().toLowerCase().includes(buttonText.toLowerCase())){
//console.log($(this).text() + " clicked.");
matches.push($(this));
//$(this)["0"].click();
//return;
}
});
$("button").each(function(){
if($(this).text().toLowerCase().includes(buttonText.toLowerCase())){
//$(this)["0"].click();
matches.push($(this));
}
});
return matches.length;
}
function buttonPress(num){
console.log(num + " adsa pressed!");
}
function scroll(direction="down"){ //1 down, -1 up
dirInt = direction == "down" ? 1 : -1;
console.log(dirInt);
window.scrollBy(0, window.innerHeight * dirInt);
}
function goTo(text){
if(text.includes(".")){
window.location.href = "http://" + text;
} else {
text += "";
text = text.replace(/,/g, " ");
window.location.href = "https://www.google.com/search?q=" + text;
}
}
function prevPage(){
window.history.back();
}
function nextPage(){
window.history.forward();
}
function enterText(field, text){
console.log("Inputting");
$("input").each(function(){
//console.log("asdadwaf");
$.each(this.attributes, function(i, attribute){
//console.log("hello");
//console.log(attribute.value);
if(attribute.value.toLowerCase().includes(field.toLowerCase())){
console.log($("input[name="+attribute.value+"]"));
$("input["+attribute.name+"="+attribute.value+"]")["0"].value = text;
}
});
});
}
function openTab(){
chrome.tabs.create();
}
function closeTab(){
chrome.tabs.remove(chrome.tabs.getCurrent().index);
}
function switchTab(){
chrome.tabs.query({currentWindow: true, active: true}, function(tabsArray) {
if( tabsArray.length < 2 ) return;
chrome.tabs.query({index: (tabsArray[0].index+1)}, function(nextTabsArray){
if( nextTabsArray.length < 1 ) return;
chrome.tabs.update(nextTabsArray[0].id, {active: true})
});
});
}
function maximize(){
window.resizeTo(screen.width, screen.height);
}