another chunk lol, it is functional already
[hotformathCLI/.git] / menu.js
diff --git a/menu.js b/menu.js
new file mode 100644 (file)
index 0000000..85aecce
--- /dev/null
+++ b/menu.js
@@ -0,0 +1,131 @@
+/////////////////////////////////////////////////\r
+//                Variables                    //\r
+/////////////////////////////////////////////////\r
+    var button = $('#dropdown-button')\r
+       var subMenu = $('#dropdown-menu')\r
+    var subMenuItem = $("#dropdown-menu li")\r
+    var searchButton = $('#search-button')\r
+    var searchBox = $('#search-box')\r
+    \r
+    \r
+$(window).resize(function(){\r
+       if ($(window).width() <= 750){  \r
+               searchButton.text("Search")\r
+        searchButton.append(' <i class="fal fa-search">'); \r
+       } else {\r
+        searchButton.text("")\r
+        searchButton.append(' <i class="fal fa-search">');\r
+    }\r
+});\r
+\r
+\r
+/////////////////////////////////////////////////\r
+//             Show Menu Toggle                //\r
+/////////////////////////////////////////////////\r
+$(function() {\r
+    button.click(function() {\r
+        subMenu.slideToggle(250, 'easeInOutQuint');\r
+    });\r
+});\r
+\r
+/////////////////////////////////////////////////\r
+//              Menu Selection                 //\r
+/////////////////////////////////////////////////\r
+$(function() {\r
+    // Check which sub menu item was clicked\r
+    subMenuItem.click(function() {\r
+        console.log($(this).text() + " clicked");                                       // Tell me which item was clicked.\r
+        button.text($(this).text());                                                    // Copy the text of the selected menu item to the button.\r
+        button.append(' <i class="fal fa-' + $(this).attr("value") + '">');             // Set the icon to match the text.\r
+        button.val($(this).text());                                                     // Set the value of the button to that of the text selected.\r
+        subMenu.slideToggle(250, 'easeInOutQuint');                                     // Hide menu after selection is made.\r
+    });\r
+});\r
+\r
+/////////////////////////////////////////////////\r
+//       Controls Enter Key for TextBox        //\r
+/////////////////////////////////////////////////\r
+$(document).ready(function() {\r
+  $('body').keypress(function(e) {\r
+    if (e.which == 13) {\r
+      searchButton.trigger('click');\r
+      console.log("search button clicked");\r
+    }\r
+  });\r
+});\r
+\r
+/////////////////////////////////////////////////\r
+//         Generates the search string         //\r
+/////////////////////////////////////////////////\r
+$(document).ready(function() {\r
+  searchBox.val("");\r
+  searchBox.focus();\r
+    \r
+  searchButton.click(function() {\r
+    var type = button.val();                                                            // Set the type valriable to the value of the button.\r
+    var query = searchBox.val();                                                        // Set the Query variable to the value of the text box.\r
+    var arr = new Array();                                                              // Create a new blank array.\r
+    var commonToAll = " -inurl:(jsp|pl|php|html|aspx|htm|cf|shtml) " +                  // This string is common to all searches.\r
+        "-inurl:(index_of|listen77|mp3raid|mp3toss|mp3drug|index_of|wall" +\r
+        "ywashis) intitle:\"index.of./\" ";\r
+    if (query[query.length - 1] == ',') {                                               // Check the length of the search term to see if there were\r
+      query = query.slice(0, -1)                                                            // multiple search terms used, then slice the string at\r
+    }                                                                                       // every comma.\r
+    arr = query.split(',');                                                                         \r
+    arr.push(',');\r
+    switch (type) {                                                                     // Compare the type that was set earlier with the cases below\r
+      case ("Video"):\r
+        {\r
+          var extensions = " (avi|mkv|mov|mp4|mpg|wmv)";\r
+          break;\r
+        }\r
+      case ("Audio"):\r
+        {\r
+          var extensions = " (ac3|flac|m4a|mp3|ogg|wav|wma) ";\r
+          break;\r
+        }\r
+      case ("Ebook"):\r
+        {\r
+          var extensions = " (CBZ|CBR|CHM|DOC|DOCX|EPUB|MOBI|ODT|PDF|RTF|txt)";\r
+          break;\r
+        }\r
+      case ("Pictures"):\r
+        {\r
+          var extensions = " (bmp|gif|jpg|png|psd|tif|tiff) ";\r
+          break;\r
+        }\r
+      case ("Software/Games"):\r
+        {\r
+          var extensions = " (apk|exe|iso|rar|tar|zip) ";\r
+          break;\r
+        }\r
+      case ("Compressed"):\r
+        {\r
+          var extensions = " (7z|bz2|gz|iso|rar|zip) ";\r
+          break;\r
+        }\r
+      default:\r
+        {\r
+          var extensions = " (avi|mkv|mov|mp4|mpg|wmv)";\r
+          break;\r
+        }\r
+    }\r
+    for (var i = 0; i < arr.length - 1; i++) {\r
+      if (arr[i] != "") {\r
+        var temp = arr[i];\r
+        var last;\r
+        temp = temp.replace(/[^\w\s]/gi, '');\r
+        if (temp != 0) {\r
+          last = temp.replace(/ /g, ".");\r
+        }\r
+        var goodinput = "intext:\"" + last + "\"";\r
+        var finalquery = goodinput + extensions + commonToAll;\r
+\r
+        var url = "https://www.google.com/search?q=" + encodeURIComponent(finalquery);\r
+        //alert(goodinput);\r
+        window.open(url, '_blank');\r
+      }\r
+\r
+    }\r
+  });\r
+});\r