forked from NITDgpOS/Fearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
148 lines (139 loc) · 4.74 KB
/
popup.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
// Styling content
// Place suggestion in query box
function suggestionAsValue() {
var sLabel;
sLabel = document.getElementById("suggest-label");
sLabel.addEventListener("click", function () {
document.getElementById("query").value = sLabel.innerHTML;
});
}
// Method to keyboard shortcut
function keyboardShortCutListener(e) {
e.preventDefault();
if (e.ctrlKey && e.altKey && e.keyCode === 77) {
if (document.getElementById("music").checked === true) {
document.getElementById("music").checked = false;
} else {
document.getElementById("music").checked = true;
}
} else if (e.ctrlKey && e.altKey && e.keyCode === 86) {
if (document.getElementById("video").checked === true) {
document.getElementById("video").checked = false;
} else {
document.getElementById("video").checked = true;
}
} else if (e.ctrlKey && e.altKey && e.keyCode === 66) {
if (document.getElementById("books").checked === true) {
document.getElementById("books").checked = false;
} else {
document.getElementById("books").checked = true;
}
} else if (e.ctrlKey && e.altKey && e.keyCode === 65) {
if ((document.getElementById("music").checked === true) && (document.getElementById("video").checked === true) && (document.getElementById("books").checked === true)) {
document.getElementById("music").checked = false;
document.getElementById("video").checked = false;
document.getElementById("books").checked = false;
} else {
document.getElementById("music").checked = true;
document.getElementById("video").checked = true;
document.getElementById("books").checked = true;
}
}
}
function register(event) {
var set1;
var set2;
var set3;
var check1;
var check2;
var check3;
var query;
var formats;
var querySplit;
var suggestedFormat;
var dotCheck;
var uuid;
query = document.getElementById("query").value;
query = encodeURIComponent(query);
// Note :- avoid hardcoded uuid.
uuid = "8fd531a3ba79466f8a80e5c71dea9723";
check1 = document.getElementById("music").checked;
check2 = document.getElementById("video").checked;
check3 = document.getElementById("books").checked;
querySplit = query.split(".");
dotCheck = querySplit.length > 1;
// Warning messages
if (query === "") {
document.getElementById("searchWarning").style.display = "block";
document.getElementById("checkboxWarning").style.display = "none";
event.preventDefault();
} else if (check1 || check2 || check3 || dotCheck) {
// query logic
if (document.getElementById("music").checked === true) {
set1 = "mp3|wav|m4a|ogg|wma|flac";
} else {
set1 = "";
}
if (document.getElementById("video").checked === true) {
set2 = "|mkv|mp4|avi|webm|flv|mov|mpg|mpeg";
} else {
set2 = "";
}
if (document.getElementById("books").checked === true) {
set3 = "|epub|pdf";
} else {
set3 = "";
}
formats = set1 + set2 + set3;
if (dotCheck) {
suggestedFormat = querySplit[1];
query = querySplit[0];
formats = formats + "|" + suggestedFormat;
}
/* eslint-disable */
window.open("http://www.google.com/search?q="+query+" -"+uuid+" -inurl:(htm|html|php|pls|txt) intitle:index.of \"last modified\" ("+formats+")");
/* eslint-enable */
} else {
document.getElementById("searchWarning").style.display = "none";
document.getElementById("checkboxWarning").style.display = "block";
event.preventDefault();
}
}
function suggestion() {
var suggestions;
var random;
suggestions = ["Anime",
"Manga",
"TV-Series",
"Pokemon",
"Big Bang",
"Blues",
"Rock",
"Metal",
"AC/DC",
"Pop",
"Soft Rock",
"MJ",
"Pink Floyd",
"The Wall",
"Shakira",
"JeLo",
"Hard Rock",
"Old Blues",
"Fiction",
"Thriller",
"Learning",
"Eminem",
"Green Day",
"Metaliica",
"Taylor Swift",
"Drake"];
random = Math.floor(Math.random() * suggestions.length);
document.getElementById("suggest-label").innerHTML = suggestions[random];
}
document.addEventListener("DOMContentLoaded", function () {
document.querySelector("button").addEventListener("click", register);
document.addEventListener("keyup", keyboardShortCutListener, false);
suggestion();
suggestionAsValue();
});