another chunk lol, it is functional already
[hotformathCLI/.git] / menu.js
1 /////////////////////////////////////////////////\r
2 //                Variables                    //\r
3 /////////////////////////////////////////////////\r
4     var button = $('#dropdown-button')\r
5         var subMenu = $('#dropdown-menu')\r
6     var subMenuItem = $("#dropdown-menu li")\r
7     var searchButton = $('#search-button')\r
8     var searchBox = $('#search-box')\r
9     \r
10     \r
11 $(window).resize(function(){\r
12         if ($(window).width() <= 750){  \r
13                 searchButton.text("Search")\r
14         searchButton.append(' <i class="fal fa-search">'); \r
15         } else {\r
16         searchButton.text("")\r
17         searchButton.append(' <i class="fal fa-search">');\r
18     }\r
19 });\r
20 \r
21 \r
22 /////////////////////////////////////////////////\r
23 //             Show Menu Toggle                //\r
24 /////////////////////////////////////////////////\r
25 $(function() {\r
26     button.click(function() {\r
27         subMenu.slideToggle(250, 'easeInOutQuint');\r
28     });\r
29 });\r
30 \r
31 /////////////////////////////////////////////////\r
32 //              Menu Selection                 //\r
33 /////////////////////////////////////////////////\r
34 $(function() {\r
35     // Check which sub menu item was clicked\r
36     subMenuItem.click(function() {\r
37         console.log($(this).text() + " clicked");                                       // Tell me which item was clicked.\r
38         button.text($(this).text());                                                    // Copy the text of the selected menu item to the button.\r
39         button.append(' <i class="fal fa-' + $(this).attr("value") + '">');             // Set the icon to match the text.\r
40         button.val($(this).text());                                                     // Set the value of the button to that of the text selected.\r
41         subMenu.slideToggle(250, 'easeInOutQuint');                                     // Hide menu after selection is made.\r
42     });\r
43 });\r
44 \r
45 /////////////////////////////////////////////////\r
46 //       Controls Enter Key for TextBox        //\r
47 /////////////////////////////////////////////////\r
48 $(document).ready(function() {\r
49   $('body').keypress(function(e) {\r
50     if (e.which == 13) {\r
51       searchButton.trigger('click');\r
52       console.log("search button clicked");\r
53     }\r
54   });\r
55 });\r
56 \r
57 /////////////////////////////////////////////////\r
58 //         Generates the search string         //\r
59 /////////////////////////////////////////////////\r
60 $(document).ready(function() {\r
61   searchBox.val("");\r
62   searchBox.focus();\r
63     \r
64   searchButton.click(function() {\r
65     var type = button.val();                                                            // Set the type valriable to the value of the button.\r
66     var query = searchBox.val();                                                        // Set the Query variable to the value of the text box.\r
67     var arr = new Array();                                                              // Create a new blank array.\r
68     var commonToAll = " -inurl:(jsp|pl|php|html|aspx|htm|cf|shtml) " +                  // This string is common to all searches.\r
69         "-inurl:(index_of|listen77|mp3raid|mp3toss|mp3drug|index_of|wall" +\r
70         "ywashis) intitle:\"index.of./\" ";\r
71     if (query[query.length - 1] == ',') {                                               // Check the length of the search term to see if there were\r
72       query = query.slice(0, -1)                                                            // multiple search terms used, then slice the string at\r
73     }                                                                                       // every comma.\r
74     arr = query.split(',');                                                                         \r
75     arr.push(',');\r
76     switch (type) {                                                                     // Compare the type that was set earlier with the cases below\r
77       case ("Video"):\r
78         {\r
79           var extensions = " (avi|mkv|mov|mp4|mpg|wmv)";\r
80           break;\r
81         }\r
82       case ("Audio"):\r
83         {\r
84           var extensions = " (ac3|flac|m4a|mp3|ogg|wav|wma) ";\r
85           break;\r
86         }\r
87       case ("Ebook"):\r
88         {\r
89           var extensions = " (CBZ|CBR|CHM|DOC|DOCX|EPUB|MOBI|ODT|PDF|RTF|txt)";\r
90           break;\r
91         }\r
92       case ("Pictures"):\r
93         {\r
94           var extensions = " (bmp|gif|jpg|png|psd|tif|tiff) ";\r
95           break;\r
96         }\r
97       case ("Software/Games"):\r
98         {\r
99           var extensions = " (apk|exe|iso|rar|tar|zip) ";\r
100           break;\r
101         }\r
102       case ("Compressed"):\r
103         {\r
104           var extensions = " (7z|bz2|gz|iso|rar|zip) ";\r
105           break;\r
106         }\r
107       default:\r
108         {\r
109           var extensions = " (avi|mkv|mov|mp4|mpg|wmv)";\r
110           break;\r
111         }\r
112     }\r
113     for (var i = 0; i < arr.length - 1; i++) {\r
114       if (arr[i] != "") {\r
115         var temp = arr[i];\r
116         var last;\r
117         temp = temp.replace(/[^\w\s]/gi, '');\r
118         if (temp != 0) {\r
119           last = temp.replace(/ /g, ".");\r
120         }\r
121         var goodinput = "intext:\"" + last + "\"";\r
122         var finalquery = goodinput + extensions + commonToAll;\r
123 \r
124         var url = "https://www.google.com/search?q=" + encodeURIComponent(finalquery);\r
125         //alert(goodinput);\r
126         window.open(url, '_blank');\r
127       }\r
128 \r
129     }\r
130   });\r
131 });\r