text: var app = angular.module("weebIrc", ["ngRoute", "ngSanitize", "ui.materialize", "angular.filter"]);
  $().ready(function() {
    $(".sidenav-activator").sideNav({closeOnClick:!0});
    $(".collapsible").collapsible({accordion:!1});
  });
  app.config(["$routeProvider", function(d) {
    d.when("/settings", {templateUrl:"/Partials/settings.html", controller:"settingsCtrl"}).when("/video", {templateUrl:"/Partials/video.html", controller:"videoCtrl"}).when("/player", {templateUrl:"/Partials/player.html", controller:"playerCtrl"}).when("/download", {templateUrl:"/Partials/download.html", controller:"downloadCtrl"}).when("/chat", {templateUrl:"/Partials/chat.html", controller:"chatCtrl"}).when("/history", {templateUrl:"/Partials/history.html", controller:"historyCtrl"}).when("/anime", 
    {templateUrl:"/Partials/anime.html", controller:"animeCtrl"}).when("/seasons", {templateUrl:"/Partials/seasons.html", controller:"seasonsCtrl"}).when("/home", {templateUrl:"/Partials/home.html", controller:"homeCtrl"}).when("/serverdownload", {templateUrl:"/Partials/serverdownload.html", controller:"serverDownloadCtrl"}).when("/about", {templateUrl:"/Partials/about.html", controller:"aboutCtrl"}).otherwise({redirectTo:"/home"});
  }]);
  app.config(function(d) {
    d.resourceUrlWhitelist(["self", "http://cdn*.myanimelist.net/images/anime/**", "https://myanimelist.cdn-dena.com/images/anime/**"]);
  });
  app.config(function(d) {
    d.defaults.transformRequest = function(a) {
      return void 0 === a ? a : $.param(a);
    };
  });
  app.directive("dynamic", function(d) {
    return {restrict:"A", replace:!0, link:function(a, e, f) {
      a.$watch(f.dynamic, function(c) {
        e.html(c);
        d(e.contents())(a);
      });
    }};
  });
  app.directive("focusMe", function(d, a) {
    return {link:function(e, f, c) {
      var h = a(c.focusMe);
      e.$watch(h, function(a) {
        !0 === a && d(function() {
          f[0].focus();
        });
      });
      f.bind("blur", function() {
        e.$apply(h.assign(e, !1));
      });
    }};
  });
  app.run(function(d) {
    d.insertLoader = function(a, d, f) {
      $(f).append('<div id="loader_' + d + '"><img src="Image/loading.svg" width="' + a + '" /></div>');
      console.log("INSERTING LOADER");
    };
    d.removeLoader = function(a) {
      $("#loader_" + a).remove();
    };
  });
  app.controller("rootCtrl", ["$rootScope", "$scope", "$http", "$location", "$sce", "comServer", "storage", "serverDetection", "status", function(d, a, e, f, c, h, b, l, g) {
    a.config = {pageTitle:"WeebIRC", navbarTitle:"WeebIRC", navbarColor:"indigo"};
    a.runServerDetection = function() {
      l.detectServers();
      d.insertLoader(64, "waitingforzeservers", "waitingforzeservers");
    };
    d.$on("FoundServers", function(b, h) {
      console.log("Foundservers event fired!");
      var g = [];
      $.each(h, function(a, b) {
        g.push(b.version != currentVersion ? {name:b.name + " Old Version (" + b.version + ")", ip:b.ip, color:"red"} : {name:b.name, ip:b.ip, color:"text-blue"});
      });
      -1 < JSON.stringify(g).indexOf('"color":"red"') && (a.newVersion = c.trustAsHtml('Your running an older version of WeebIRC! <br> Please download the newer version <a href="/FileDownload/WeebIRCServer.exe">here</a> for the best experience!'));
      d.removeLoader("waitingforzeservers");
      a.servers = g;
      a.$apply();
      console.log(g);
    });
    d.$on("LocalFiles", function(a, c) {
      console.log(c);
      b.resetStorage("local_files", c);
    });
    d.$on("downloaddirreceived", function() {
      a.Directory = b.retreiveFromStorage("download_directory");
      a.$apply();
    });
    var m = "";
    a.setAsDefaultServer = function(b, c) {
      $.each(a.servers, function(a, c) {
        b == a ? $("#server_" + b).addClass("blue") : $("#server_" + b).removeClass("blue");
      });
      m = c;
      a.customIp = c;
    };
    a.customIp = b.retreiveFromStorage("weebirc_server_address");
    a.checkIfCustomIpIsSet = function() {
      -1 < a.customIp.length ? /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(a.customIp) ? (b.resetStorage("weebirc_server_address", "http://" + a.customIp), $(".slider").slider("next"), Materialize.toast("Server address " + a.customIp + " is valid!", 4E3)) : /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/.test(a.customIp) ? (-1 < a.customIp.indexOf("http") ? 
      b.resetStorage("weebirc_server_address", a.customIp) : b.resetStorage("weebirc_server_address", "http://" + a.customIp), $(".slider").slider("next"), Materialize.toast("Server address " + a.customIp + " is valid!", 4E3)) : Materialize.toast("Server address " + a.customIp + " is not valid!", 4E3) : /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(m) ? (b.resetStorage("weebirc_server_address", 
      "http://" + m), $(".slider").slider("next"), Materialize.toast("Server address " + m + " is valid!", 4E3)) : m.match(/http\:\/\/www\.mydomain\.com\/version\.php/i) ? (b.resetStorage("weebirc_server_address", "http://" + m), $(".slider").slider("next"), Materialize.toast("Server address " + m + " is valid!", 4E3)) : Materialize.toast("Server address " + m + " is not valid!", 4E3);
      h.startComServer();
      localServer.startLocalServer();
    };
    e = b.retreiveFromStorage("settings")[0];
    a.server = e.server;
    a.channels = e.channels;
    a.username = e.username;
    a.autoConnect = e.autoConnect;
    a.Directory = e.download_directory;
    a.saveAndConnectIRC = function() {
      $("#firstLaunch").closeModal();
      b.createStorage("firstlaunch", {firstlaunch:!1});
      a.$emit("ShowLoading", '<span class="white><h5> Waiting for irc connection! </h5></span>');
      var c = a.server, g = a.channels, d = a.username;
      b.resetStorage("settings", {autoConnect:a.autoConnect, server:c, channels:g, username:d});
      h.setupIrcClient(c, g, d);
      h.getCurrentSeason();
      b.retreiveFromStorage("firstlaunch")[0].firstlaunch && b.resetStorage("firstlaunch", {firstlaunch:!1});
      h.getCurrentSeason();
      $("#connectToIrc").closeModal();
    };
    a.setDownloadDirectory = function() {
      void 0 !== a.Directory && "" !== a.Directory ? (b.doesStorageExist("download_directory") ? b.resetStorage("download_directory", a.Directory) : b.createStorage("download_directory", a.Directory), console.log("Custom dir: " + a.Directory), Materialize.toast("Download Directory: " + a.Directory + " succesfully saved!"), h.setDownloadDirectory(a.Directory)) : Materialize.toast("Download Directory set to default!");
    };
    a.$on("changeConfig", function(b, c) {
      a.config = c;
    });
    a.$on("changePageTitle", function(b, c) {
      a.config.pageTitle = c;
    });
    a.$on("changeNavbarColor", function(b, c) {
      a.config.navbarColor = c;
    });
    a.$on("changeNavbarTitle", function(b, c) {
      a.config.navbarTitle = c;
    });
    a.menuItems = [{url:"/#/home", icon:"home", text:"Home"}, {url:"/#/anime", icon:"remove_red_eye", text:"Current Anime"}, {url:"/#/history", icon:"history", text:"History"}, {url:"/#/seasons", icon:"date_range", text:"Seasons"}, {url:"/#/settings", icon:"local_movies", text:"Settings"}, {url:"/#/chat", icon:"chat", text:"Chat"}, {url:"/#/download", icon:"file_download", text:"Downloads"}, {url:"/#/serverdownload", icon:"computer", text:"WeebIRC Download"}, {url:"/#/about", icon:"info", text:"About"}];
    a.searchButtonClicked = function() {
      a.searching ? a.searching = !1 : (a.searching = !0, angular.element("#searchField").focus());
    };
    a.startSearch = function(c) {
      13 === c.which && (c = a.searchinput.text, h.searchAnime(c), a.$emit("changeConfig", {pageTitle:"Search | " + c, navbarTitle:"Search | " + c, navbarColor:"red"}), d.$emit("searching"), b.doesStorageExist("isSearched") ? b.resetStorage("isSearched", {isSearched:!0, pageTitle:"Search | " + c, navbarTitle:"Search | " + c, navbarColor:"red"}) : b.createStorage("isSearched", {isSearched:!0, pageTitle:"Search | " + c, navbarTitle:"Search | " + c, navbarColor:"red"}));
    };
  }]);
  app.service("serverDetection", ["$rootScope", "$http", "$interval", "$location", "storage", function(d, a, e, f, c) {
    var h = new ClientSideServerDetection;
    h.setPorts(["8080"]);
    h.setPartials(["/?message=ISCONNECTED"]);
    this.detectServers = function() {
      console.log("RUNNING SERVER DETECTIOn");
      Materialize.toast("Running server detection!", 2E3);
      var a = [];
      h.runDetection(function(c) {
        console.log("DATA OF FOUND SERVER: ");
        console.log(c);
        $.each(c, function(c, b) {
          try {
            var h = "unknown";
            -1 < b.data.messages[1].indexOf("~~") && (h = b.data.messages[1].split("~~")[1]);
            var d = {name:b.data.messages[2].split(":")[1], ip:b.ip, version:h};
            a.push(d);
          } catch (p) {
          }
        });
        console.log(a);
        d.$broadcast("FoundServers", a);
      });
    };
    this.getLocalIp = function() {
      h.getLocalIp();
      return h.getFullLocalIp();
    };
  }]);
  app.service("storage", ["$rootScope", "$http", "$interval", "$location", function(d, a, e, f) {
    var c;
    try {
      c = window.localStorage, c.setItem("__storage_test__", "__storage_test__"), c.removeItem("__storage_test__");
    } catch (h) {
      c = !1;
    }
    if (0 != c) {
      try {
        null == c.getItem("CurrentSubStorages") && c.setItem("CurrentSubStorages", "~~");
      } catch (h) {
      }
    }
    this.doesStorageExist = function(a) {
      return 0 != c ? null != c.getItem(a) ? !0 : !1 : !1;
    };
    this.createStorage = function(a, b) {
      var d = c.getItem("CurrentSubStorages");
      return 0 != c && 0 > d.indexOf(a) ? ("object" === typeof b ? c.setItem(a, "[" + JSON.stringify(b) + "]") : c.setItem(a, b), c.setItem("CurrentSubStorages", d + "~~" + a), !0) : !1;
    };
    this.deleteStorage = function(a) {
      var b = c.getItem("CurrentSubStorages");
      if (0 != c) {
        if (0 < b.indexOf(a)) {
          b = b.replace("~~" + a, ""), c.removeItem(a), c.setItem("CurrentSubStorages", b);
        } else {
          return !1;
        }
        return !0;
      }
      return !1;
    };
    this.resetStorage = function(a, b) {
      return 0 != c ? (c.removeItem(a), "object" === typeof b ? c.setItem(a, "[" + JSON.stringify(b) + "]") : c.setItem(a, b), !0) : !1;
    };
    this.retreiveFromStorage = function(a) {
      if (0 != c) {
        try {
          return JSON.parse(c.getItem(a));
        } catch (b) {
          return c.getItem(a);
        }
      } else {
        return !1;
      }
    };
    this.appendToStorage = function(a, b) {
      if (0 != c) {
        if ("object" === typeof b) {
          var d = c.getItem(a);
          try {
            JSON.parse(d);
          } catch (g) {
            return !1;
          }
          d = d.substr(0, d.length - 1) + "," + JSON.stringify(b) + "]";
          c.setItem(a, d);
        } else {
          d = c.getItem(a), c.setItem(a, d + b);
        }
        return !0;
      }
      return !1;
    };
    this.removeFromStorage = function(a, b) {
      if (0 != c) {
        if ("object" === typeof b) {
          var d = c.getItem(a);
          try {
            JSON.parse(d);
          } catch (g) {
            return !1;
          }
          d = d.substr(0, d.length - 1).replace(JSON.stringify(b)) + "]";
        } else {
          d = c.getItem(a), d = d.replace(b, "");
        }
        c.setItem(a, d);
        return !0;
      }
      return !1;
    };
    this.getCurrentAvailableStorages = function() {
      return c.getItem("CurrentSubStorages").split("~~");
    };
  }]);
  app.service("comServer", ["$rootScope", "$http", "$interval", "$location", "storage", "serverDetection", function(d, a, e, f, c, h) {
    function b(a) {
      function b(a) {
        d.$emit("comserver_connected");
        if (!c.retreiveFromStorage("weebirc_server_connected")[0].isconnected || l) {
          c.resetStorage("weebirc_server_connected", {isconnected:!0}), Materialize.toast("Connected to WeebIRC Server!", 4E3), l = !1;
        }
        console.log(a);
        angular.forEach(a.messages, function(a) {
          d.$broadcast("ServerMessageReceived", a);
          if (-1 < a.indexOf("WEEB HERE")) {
            var b = a.split("~~")[1];
            b != currentVersion && (b = $('<div style="min-width: 100%; min-height: 100%; color: red;"> You are currently running a outdated server(' + b + ')! New version available <a href="/#/serverdownload"> here (' + currentVersion + ")!</a></div>"), Materialize.toast(b, 5E3));
          }
          -1 < a.indexOf("clientisnotrunning") ? d.$emit("ircclientisnotconnected") : -1 < a.indexOf("clientisrunning") && d.$emit("ircclientisconnected");
          -1 < a.indexOf("ABORTED") && d.$emit("downloadaborted");
          -1 < a.indexOf("CURRENTDLDIR") && (console.log("Cur dir: " + decodeURIComponent(a)), c.resetStorage("download_directory", decodeURIComponent(a.split("~")[1])), d.$emit("downloaddirreceived"));
        });
        a.hasOwnProperty("rawjson") && (a.rawjson[0].hasOwnProperty("Anime") ? d.$broadcast("AnimeSeasonReceived", a.rawjson[0].Anime) : a.rawjson[0].hasOwnProperty("allSeasons") ? d.$broadcast("AllSeasonsReceived", a.rawjson[0].allSeasons) : a.rawjson[0].hasOwnProperty("currentDownload") ? d.$broadcast("CurrentDownloadUpdated", a.rawjson[0].currentDownload) : a.rawjson[0].hasOwnProperty("LocalFiles") ? (console.log(a), console.log("FOUND LOCAL FILES UPDATE!"), d.$broadcast("LocalFiles", a.rawjson[0].LocalFiles)) : 
        a.rawjson[0].hasOwnProperty("NIBL") && d.$broadcast("NiblSearchResults", a.rawjson[0].NIBL));
      }
      var g = c.retreiveFromStorage("weebirc_server_address") + ":8080";
      console.log(a);
      null !== c.retreiveFromStorage("weebirc_server_address") && $.get(g + "/?message=" + encodeURIComponent(a)).done(function(a) {
        b(a);
      }).fail(function(a) {
        c.retreiveFromStorage("weebirc_server_connected")[0].isconnected && "OK" != a.statusText && (Materialize.toast("Lost Connection To WeebIRC Server", 4E3), c.resetStorage("weebirc_server_connected", {isconnected:!1}));
        d.$emit("comserver_notconnected");
      });
    }
    var l = !0;
    b("ISIRCCLIENTRUNNING");
    b("GETLOCALFILES");
    b("GETDLDIR");
    this.sendMessage = function(a) {
      b(a);
    };
    this.startComServer = function() {
      b("ISIRCCLIENTRUNNING");
      b("GETLOCALFILES");
      b("GETDLDIR");
      b("GETCURRENTSEASON");
    };
    this.isConnected = function() {
      b("ISCONNECTED");
    };
    this.abortDownload = function() {
      b("ABORTDOWNLOAD");
    };
    this.getCurrentSeason = function() {
      console.log("I ASKED FOR THE MOFO CURRENT SEASON, NIGGA");
      b("GETCURRENTSEASON");
    };
    this.getAllSeasons = function() {
      b("GETALLSEASONS");
    };
    this.getSeason = function(a) {
      b("GETSEASON~" + a);
    };
    this.searchAnime = function(a) {
      a = "http://myanimelist.net/anime.php?q=" + encodeURI(a);
      b("SEARCHANIME~" + a);
    };
    this.getLocalFiles = function() {
      b("GETLOCALFILES");
    };
    this.setDownloadDirectory = function(a) {
      b("SETDLDIR~" + a);
    };
    this.isIrcClientRunning = function() {
      b("ISIRCCLIENTRUNNING");
    };
    this.closeIrcClient = function() {
      b("CLOSEIRC");
    };
    this.setupIrcClient = function(a, c, d) {
      b("server: " + a + " channel: " + c + ",#weebirc username: " + d + " junk: this is junk");
    };
    this.sendIrcMessage = function(a) {
      b("irc:" + a);
    };
    this.setDownloadDirectoryPerDownload = function(a) {
      b("SETCURDLDLDIR~" + a);
    };
    this.getDownloadDir = function() {
      b("GETDLDIR");
    };
  }]);
  app.service("localServer", ["$rootScope", "$http", "$interval", "$location", "storage", "serverDetection", function(d, a, e, f, c, h) {
    function b(a) {
      var b = c.retreiveFromStorage("weebirc_local_server_address") + ":8080";
      0 > b.indexOf("http://") && (b = "http://" + b);
      null === c.retreiveFromStorage("weebirc_local_server_address") && "0.0.0.0" == c.retreiveFromStorage("weebirc_local_server_address") || $.get(b + "/?message=" + encodeURIComponent(a)).done(function(a) {
        d.$emit("localserver_connected");
        c.retreiveFromStorage("weebirc_local_server_connected")[0].isconnected && 1 != g || (c.resetStorage("weebirc_local_server_connected", {isconnected:!0}), Materialize.toast("Connected to Local WeebIRC Server!", 4E3), g = !1);
      }).fail(function(a) {
        c.retreiveFromStorage("weebirc_local_server_connected")[0].isconnected && "OK" != a.statusText && (Materialize.toast("Lost Connection To Local Weeb Server", 4E3), c.resetStorage("weebirc_local_server_connected", {isconnected:!1}), c.doesStorageExist("firstlaunch") && (c.retreiveFromStorage("firstlaunch")[0].firstlaunch || $("#norunninglocalserver").openModal()), d.$emit("localserver_notconnected"));
      });
    }
    var l = navigator.userAgent || navigator.vendor || window.opera, g = !0;
    this.sendMessage = function(a) {
      /android/i.test(l) || b(a);
    };
    this.startLocalServer = function() {
      if (!/android/i.test(l)) {
        var a = e(function() {
          var d = h.getLocalIp();
          console.log(d);
          "0.0.0.0" != d && (c.resetStorage("weebirc_local_server_address", d), e(function() {
            b("ISCONNECTED");
          }, 5E3), e.cancel(a));
        }, 100);
      }
    };
    this.play = function(a) {
      b("PLAY~" + a);
    };
  }]);
  app.service("status", ["$rootScope", "$http", "$interval", "$location", "comServer", "localServer", "storage", function(d, a, e, f, c, h, b) {
    b.doesStorageExist("debug_messages") ? (a = {view:"ROOT", message:"Debug message storage resetted!"}, b.resetStorage("debug_messages", a)) : (a = {view:"ROOT", message:"Debug message storage created!"}, b.createStorage("debug_messages", a));
    b.doesStorageExist("server_ip") || b.createStorage("server_ip", {});
    b.doesStorageExist("irc_messages") ? b.resetStorage("irc_messages", "~~") : b.createStorage("irc_messages", "~~");
    b.doesStorageExist("history") || b.createStorage("history", {});
    b.doesStorageExist("local_files") || b.createStorage("local_files", {});
    b.doesStorageExist("weebirc_server_connected") || b.createStorage("weebirc_server_connected", {isconnected:!1});
    b.doesStorageExist("weebirc_server_address") || b.createStorage("weebirc_server_address", "noserverset");
    b.doesStorageExist("weebirc_local_server_address") || b.createStorage("weebirc_local_server_address", "noserverset");
    b.doesStorageExist("weebirc_local_server_connected") || b.createStorage("weebirc_local_server_connected", {isconnected:!1});
    b.doesStorageExist("default_resolution") || b.createStorage("default_resolution", "720");
    b.doesStorageExist("irc_connection") || b.createStorage("irc_connection", {connected:!1});
    if (!b.doesStorageExist("settings")) {
      a = "";
      for (e = 0;5 > e;e++) {
        a += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62 * Math.random()));
      }
      b.createStorage("settings", {autoConnect:!1, server:"irc.rizon.net", channels:"#horriblesubs,#news,#nibl,#intel,#Ginpachi-Sensei", username:"WeebIRC_" + a, download_directory:""});
    }
    b.doesStorageExist("firstlaunch") ? b.retreiveFromStorage("firstlaunch")[0].firstlaunch ? $("#firstLaunch").openModal() : b.retreiveFromStorage("firstlaunch")[0].firstlaunch || (c.startComServer(), h.startLocalServer()) : (b.createStorage("firstlaunch", {firstlaunch:!0}), $("#firstLaunch").openModal());
    b.doesStorageExist("current_season") || b.createStorage("current_season", "Currently Airing");
    b.doesStorageExist("current_season_url") || b.createStorage("current_season_url", "");
    b.doesStorageExist("anime_of_current_season") || b.createStorage("anime_of_current_season", {});
    b.doesStorageExist("previous_season") || b.createStorage("previous_season", "");
    b.doesStorageExist("all_seasons") || b.createStorage("all_seasons", {});
    b.doesStorageExist("anime_info") || b.createStorage("anime_info", {animeId:"", animeCover:"", animeTitle:"", animeSynopsis:"", animeGenres:""});
    b.doesStorageExist("download_directory") || b.createStorage("download_directory", "default");
    b.doesStorageExist("isSearched") || b.createStorage("isSearched", {isSearched:!1});
    b.doesStorageExist("anime_info") || b.createStorage("anime_info", {});
    setInterval(function() {
      c.isConnected();
      c.isIrcClientRunning();
    }, 1E3);
    var l = b.retreiveFromStorage("settings")[0], g = !1;
    $("#connectToIrc").css("opacity", 0);
    d.$on("ircclientisnotconnected", function() {
      l.autoConnect ? c.setupIrcClient(l.server, l.channels, l.username) : b.retreiveFromStorage("firstlaunch")[0].firstlaunch || 1 != $("#connectToIrc").css("opacity") && $("#connectToIrc").openModal();
      g && (Materialize.toast("Not connected to IRC Server!", 4E3), g = !1);
    });
    d.$on("ircclientisconnected", function() {
      g || (Materialize.toast("Connected to IRC Server!", 4E3), g = !0);
    });
  }]);
  app.controller("homeCtrl", ["$rootScope", "$scope", "$location", "comServer", "storage", function(d, a, e, f, c) {
    d.insertLoader(128, "home", "#placeForLoader");
    var h = c.retreiveFromStorage("current_season"), b = c.retreiveFromStorage("current_season_url"), l = c.retreiveFromStorage("anime_of_current_season")[0], g = c.retreiveFromStorage("previous_season");
    a.animeOfThisSeason = "";
    d.$on("AnimeSeasonReceived", function(f, e) {
      console.log(e);
      h = c.retreiveFromStorage("current_season");
      b = c.retreiveFromStorage("current_season_url");
      l = c.retreiveFromStorage("anime_of_current_season")[0];
      g = c.retreiveFromStorage("previous_season");
      a.$emit("changeConfig", {pageTitle:"WeebIRC | Home", navbarTitle:"Home | " + h, navbarColor:"pink"});
      l = a.animeOfThisSeason = e;
      c.resetStorage("anime_of_current_season", e);
      d.removeLoader("home");
    });
    d.$on("searching", function() {
      a.animeOfThisSeason = "";
      a.$apply();
      d.insertLoader(128, "home", "#placeForLoader");
    });
    c.doesStorageExist("isSearched") ? (e = c.retreiveFromStorage("isSearched")[0], e.isSearched ? (c.resetStorage("previous_season", e.navbarTitle), a.$emit("changeConfig", {pageTitle:e.pageTitle, navbarTitle:e.navbarTitle, navbarColor:e.navbarColor})) : a.$emit("changeConfig", {pageTitle:"WeebIRC | Home", navbarTitle:"Home | " + h, navbarColor:"blue"})) : (c.createStorage("isSearched", {isSearched:!1}), a.$emit("changeConfig", {pageTitle:"WeebIRC | Home", navbarTitle:"Home | " + h, navbarColor:"indigo"}));
    g != h ? ("Currently Airing" == h ? f.getCurrentSeason() : f.getSeason(b + "~" + h), c.resetStorage("previous_season", h)) : 10 < l.length ? (a.animeOfThisSeason = l, d.removeLoader("home")) : "Currently Airing" == h ? f.getCurrentSeason() : f.getSeason(b + "~" + h);
    a.animeClicked = function(a, b, d, g, h) {
      c.resetStorage("anime_info", {animeId:a, animeCover:b, animeTitle:d, animeSynopsis:g, animeGenres:h});
      window.location = "/#/anime";
    };
  }]);
  app.controller("chatCtrl", ["$rootScope", "$scope", "comServer", "storage", function(d, a, e, f) {
    a.$emit("changeConfig", {pageTitle:"WeebIRC | Chat", navbarTitle:"Chat", navbarColor:"blue"});
    a.ircMessages = f.retreiveFromStorage("irc_messages").split("~~");
    d.$on("ServerMessageReceived", function(c, d) {
      -1 < d.indexOf("irc:") && -1 == a.ircMessages.indexOf(d.replace("irc:", "")) && (a.ircMessages.push(d.replace("irc:", "")), 0 > f.retreiveFromStorage("irc_messages").split("~~").indexOf(d.replace("irc:", "")) && f.appendToStorage("irc_messages", d.replace("irc:", "~~")));
    });
    $("#ircMessageInput").keyup(function(a) {
      if (13 == a.which) {
        a = $("#ircMessageInput").val();
        console.log(a);
        if (-1 < a.indexOf("/connect")) {
          var c = a.split(" ");
          a = c[1];
          var b = c[2], c = c[3];
          "" != a && "" != b && "" != c && e.sendMessage("server: " + a + " channel: " + b + " username: " + c + " junk: this is junk");
        } else {
          a = "irc: " + a, 5 < a.length && e.sendMessage(a);
        }
        $("#ircMessageInput").val("");
      }
    });
  }]);
  app.controller("downloadCtrl", ["$rootScope", "$scope", "$location", "localServer", "comServer", "storage", function(d, a, e, f, c, h) {
    a.$emit("changeConfig", {pageTitle:"WeebIRC | Downloads", navbarTitle:"Downloads", navbarColor:"purple"});
    d.$on("CurrentDownloadUpdated", function(d, g) {
      100 > g.downloadProgress && "COMPLETED" != g.downloadStatus ? a.dlVisible = "visible" : (b = !1, a.dlVisible = "hidden", c.getLocalFiles());
      a.download = g;
      b || (Materialize.toast("Started Download"), c.getLocalFiles(), b = !0);
    });
    d.$on("downloadaborted", function(a, d) {
      c.getLocalFiles();
      b = !1;
    });
    d.$on("LocalFiles", function(b, c) {
      console.log(c);
      h.resetStorage("local_files", c);
      a.localFiles = c;
      a.$apply();
    });
    c.getLocalFiles();
    var b = !1;
    a.localFiles = h.retreiveFromStorage("local_files")[0];
    a.baseUrl = h.retreiveFromStorage("weebirc_server_address");
    a.dlVisible = "hidden";
    a.sendPlayRequest = function(a) {
      f.sendMessage("PLAY~" + a);
    };
    a.abortDownload = function() {
      c.abortDownload();
      a.dlVisible = "hidden";
    };
  }]);
  app.controller("seasonsCtrl", ["$rootScope", "$scope", "comServer", "storage", function(d, a, e, f) {
    a.$emit("changeConfig", {pageTitle:"WeebIRC | Seasons", navbarTitle:"Seasons", navbarColor:"blue"});
    d.$on("AllSeasonsReceived", function(d, b) {
      console.log(b);
      c = b;
      a.seasons = b;
      f.resetStorage("all_seasons", b);
    });
    var c = f.retreiveFromStorage("all_seasons")[0];
    void 0 === c[0] ? e.getAllSeasons() : 10 < c.length ? a.seasons = c : e.getAllSeasons();
    a.loadSeason = function(a, b) {
      console.log("URL FOR SEASiON " + b + " IS " + a);
      f.resetStorage("isSearched", {isSearched:!1});
      console.log("request to load season");
      f.resetStorage("current_season_url", a);
      f.resetStorage("current_season", b);
      e.getSeason(currentSeasonUrl + "~" + currentSeason);
      window.location = "/#/home";
    };
  }]);
  app.controller("animeCtrl", ["$rootScope", "$scope", "$http", "$location", "$sce", "$compile", "$filter", "comServer", "storage", "localServer", function(d, a, e, f, c, h, b, l, g, m) {
    d.insertLoader(128, "anime", "#placeForLoader");
    d.$on("CurrentDownloadUpdated", function(b, c) {
      console.log(c);
      (1 < parseInt(c.downloadProgress) || "COMPLETED" == c.downloadStatus) && q && (d.removeLoader("waitingforstream"), m.play(a.baseUrl + ":8081/" + k.animeTitle.replace(/[^\w\s]/gi, "") + "_" + k.animeId + "/" + c.fileName), q = !1);
    });
    d.$on("ircclientisconnected", function(b, c) {
      $(".collapsible").collapsible();
      a.ircNotConnected = "";
    });
    d.$on("ircclientisnotconnected", function(b, c) {
      a.ircNotConnected = "Please connect to a IRC server by reloading the page or going to the settings page!";
    });
    var q = !1, k = g.retreiveFromStorage("anime_info")[0];
    a.$emit("changeConfig", {pageTitle:"WeebIRC | " + k.animeTitle, navbarTitle:k.animeTitle, navbarColor:"blue"});
    "" == k.animeId && window.location.replace("#/home");
    f = g.retreiveFromStorage("history");
    g.retreiveFromStorage("history")[f.length - 1].animeId != k.animeId && g.appendToStorage("history", k);
    var p;
    g.doesStorageExist("nibl_botlist") ? p = g.retreiveFromStorage("nibl_botlist")[0] : e({method:"GET", url:"http://api.nibl.co.uk:8080/getallbots"}).then(function(a) {
      g.createStorage("nibl_botlist", a.data);
      p = g.retreiveFromStorage("nibl_botlist")[0];
    }, function(a) {
      console.log(a.data || "Request failed");
    });
    a.addSynonym = function(b) {
      13 === b.which && (g.doesStorageExist(k.animeId) ? (b = g.retreiveFromStorage(k.animeId), b = b + "~~" + a.synonyminput.text, g.resetStorage(k.animeId, b)) : g.createStorage(k.animeId, a.synonyminput.text + "~~"), a.animeSynonyms = g.retreiveFromStorage(k.animeId).split("~~"));
    };
    f = document.createElement("textarea");
    f.innerHTML = k.animeSynopsis;
    f = $("<p>" + f.value + "</p>").text();
    a.animeId = k.animeId;
    a.animeCover = k.animeCover;
    a.animeTitle = k.animeTitle;
    a.animeSynopsis = f;
    a.animeGenres = k.animeGenres;
    a.animeUrl = "http://myanimelist.net/search/all?q=" + k.animeTitle;
    a.localFiles = g.retreiveFromStorage("local_files")[0];
    var r;
    f = g.retreiveFromStorage(k.animeId);
    var n = g.retreiveFromStorage("default_resolution");
    a.baseUrl = g.retreiveFromStorage("weebirc_server_address");
    "1080" == n ? (a.resB1 = "green", a.resB2 = "blue", a.resB3 = "blue", a.resB4 = "blue") : "720" == n ? (a.resB1 = "blue", a.resB2 = "green", a.resB3 = "blue", a.resB4 = "blue") : "480" == n ? (a.resB1 = "blue", a.resB2 = "blue", a.resB3 = "green", a.resB4 = "blue") : "unknown" == n && (a.resB1 = "blue", a.resB2 = "blue", a.resB3 = "blue", a.resB4 = "green");
    e({method:"GET", url:"http://api.nibl.co.uk:8080/search?s=" + k.animeTitle}).then(function(c) {
      console.log("nibl api:");
      c = c.data;
      console.log(c);
      var g = c.data, f = "None";
      $.each(c.data, function(a, c) {
        var d = c[0], d = b("filter")(p, {id:d})[0];
        f = void 0 !== d ? d.name : "Unknown";
        g[a][0] = f;
      });
      a.currentBot = {name:f, amountoffiles:0};
      var e = [];
      $.each(g, function(a, b) {
        -1 < e.indexOf(b[0]) || e.push(b[0]);
      });
      c = b("filter")(g, function(a, b, c) {
        return -1 < a[2].indexOf(n) || "unknown" == n ? !0 : !1;
      });
      a.niblSearchResults = c;
      a.animebotsandpacks = e;
      r = g;
      d.removeLoader("anime");
    }, function(a) {
      console.log(a.data || "Request failed");
    });
    null != f && (a.animeSynonyms = f.split("~~"), f = f.split("~~"), $.each(f, function(a, b) {
      e({method:"GET", url:"http://api.nibl.co.uk:8080/search?s=" + b}).then(function(a) {
        console.log(a.data);
      }, function(a) {
        console.log(a.data || "Request failed");
      });
    }));
    a.updateFileList = function(c) {
      try {
        $("#botsclick").click();
        a.currentBot = {name:c, amountoffiles:0};
        var d = b("filter")(r, function(a, b, d) {
          return a[0] == c && (-1 < a[2].indexOf(n) || "unknown" == n) ? !0 : !1;
        });
        a.niblSearchResults = d;
      } catch (t) {
        console.log("Error on updating filelist:"), console.log(t);
      }
    };
    a.changeResolution = function(c) {
      $.each(["unknown", "480", "720", "1080"], function(a, b) {
        $("#" + b).removeClass("blue");
        b == c && $("#" + b).addClass("blue");
      });
      "1080" == c ? (a.resB1 = "green", a.resB2 = "blue", a.resB3 = "blue", a.resB4 = "blue") : "720" == c ? (a.resB1 = "blue", a.resB2 = "green", a.resB3 = "blue", a.resB4 = "blue") : "480" == c ? (a.resB1 = "blue", a.resB2 = "blue", a.resB3 = "green", a.resB4 = "blue") : "unknown" == c && (a.resB1 = "blue", a.resB2 = "blue", a.resB3 = "blue", a.resB4 = "green");
      try {
        var d = b("filter")(r, function(b, d, g) {
          return b[0] == a.currentBot.name && (-1 < b[2].indexOf(c) || "unknown" == c) ? !0 : !1;
        });
        a.niblSearchResults = d;
      } catch (t) {
      }
      a.resolution = c;
    };
    a.sendDownloadRequest = function(a, b) {
      var c = g.retreiveFromStorage("download_directory") + "/";
      l.setDownloadDirectoryPerDownload(c + k.animeTitle.replace(/[^\w\s]/gi, "").trim() + "_" + k.animeId.trim());
      l.sendIrcMessage("/msg " + a + " XDCC SEND #" + b);
      console.log("Download request send: irc: /msg " + a + " xdcc send #" + b);
      window.location = "/#/download";
    };
    a.sendPlayRequest = function(a, b, c) {
      q = !0;
      c = g.retreiveFromStorage("download_directory") + "/";
      l.setDownloadDirectoryPerDownload(c + k.animeTitle.replace(/[^\w\s]/gi, "").trim() + "_" + k.animeId.trim());
      l.sendIrcMessage("/msg " + a + " XDCC SEND #" + b);
      $("#" + b).hide();
      d.insertLoader(64, "waitingforstream", "#placeForLoaderStream_" + b);
    };
    a.startPlayStream = function(a) {
      console.log("START STREAM FROM ANIME PAGE WITH URL: " + a);
      m.play(a);
    };
  }]);
  app.controller("historyCtrl", ["$rootScope", "$scope", "comServer", "storage", function(d, a, e, f) {
    a.$emit("changeConfig", {pageTitle:"WeebIRC | History", navbarTitle:"History", navbarColor:"blue"});
    var c = f.retreiveFromStorage("history").reverse();
    a.animeHistory = c;
    a.animeClicked = function(a, b, c, d, e) {
      f.resetStorage("anime_info", {animeId:a, animeCover:b, animeTitle:c, animeSynopsis:d, animeGenres:e});
      window.location = "/#/anime";
    };
    a.deleteHistory = function() {
      f.resetStorage("history", {});
      c = f.retreiveFromStorage("history").reverse();
      a.animeHistory = c;
      Materialize.toast("History succesfully deleted!", 4E3);
    };
  }]);
  app.controller("playerCtrl", ["$rootScope", "$scope", "localServer", "comServer", "storage", function(d, a, e, f, c) {
    a.$emit("changeConfig", {pageTitle:"WeebIRC | Media Player", navbarTitle:"Media Player", navbarColor:"black"});
    a.baseUrl = c.retreiveFromStorage("weebirc_server_address");
    f.getLocalFiles();
    d.$on("LocalFiles", function(d, b) {
      console.log(b);
      c.resetStorage("local_files", b);
      a.localFiles = b;
    });
    a.sendPlayRequest = function(a) {
      e.play(a);
    };
  }]);
  app.controller("settingsCtrl", ["$rootScope", "$scope", "$location", "comServer", "storage", "serverDetection", function(d, a, e, f, c, h) {
    function b() {
      var b = [];
      try {
        $.each(a.allStorages, function(a, d) {
          if ("" != d) {
            var g = {storage:d, storagevalue:c.retreiveFromStorage(d)};
            b.push(g);
          }
        }), a.allDataPerStorageValues = b, a.allStorages = c.getCurrentAvailableStorages();
      } catch (g) {
        console.log("apparantly not today");
      }
    }
    a.$emit("changeConfig", {pageTitle:"WeebIRC | Settings", navbarTitle:"Settings", navbarColor:"green"});
    b();
    h.detectServers();
    f.getDownload;
    d.$on("ircclientisconnected", function() {
      a.ircClientConnectionStatus = "Connected";
      a.connectOrReconnect = "Reconnect";
      c.resetStorage("irc_connection", {connected:!0});
    });
    d.$on("ircclientisnotconnected", function() {
      a.ircClientConnectionStatus = "Not Connected";
      a.connectOrReconnect = "Connect";
      c.resetStorage("irc_connection", {connected:!1});
    });
    d.$on("comserver_connected", function() {
      a.serverConnectionStatus = "Connected";
    });
    d.$on("comserver_notconnected", function() {
      a.serverConnectionStatus = "Not Connected";
    });
    d.$on("FoundServers", function() {
      a.servers = c.retreiveFromStorage("server_ip");
    });
    d = c.retreiveFromStorage("settings")[0];
    a.server = d.server;
    a.channels = d.channels;
    a.username = d.username;
    a.autoConnect = d.autoConnect;
    a.Directory = c.retreiveFromStorage("download_directory");
    a.generateUsername = function() {
      for (var b = "", c = 0;5 > c;c++) {
        b += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62 * Math.random()));
      }
      a.username = "WeebIRC_" + b;
    };
    a.saveAndReConnectIRC = function() {
      f.closeIrcClient();
      var b = a.server, d = a.channels, e = a.username;
      c.resetStorage("settings", {autoConnect:a.autoConnect, server:b, channels:d, username:e});
      f.setupIrcClient(b, d, e);
      a.connectOrReconnect = "Reconnecting";
      setTimeout(f.isIrcClientRunning, 500);
    };
    a.disconnectIRC = function() {
      f.closeIrcClient();
    };
    a.setAsDefaultServer = function(b, d) {
      $.each(a.servers, function(a, c) {
        b == a ? $("#server_" + b).addClass("blue") : $("#server_" + b).removeClass("blue");
      });
      /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(d) ? (c.resetStorage("weebirc_server_address", "http://" + d), Materialize.toast("Server address " + d + " is valid!", 4E3)) : d.match(/http\:\/\/www\.mydomain\.com\/version\.php/i) ? (c.resetStorage("weebirc_server_address", "http://" + d), Materialize.toast("Server address " + d + " is valid!", 4E3)) : Materialize.toast("Server address " + 
      d + " is not valid!", 4E3);
      a.weebserveraddress = c.retreiveFromStorage("weebirc_server_address");
    };
    a.weebserveraddress = c.retreiveFromStorage("weebirc_server_address");
    a.saveAddressKey = function(b) {
      13 === b.which && (c.resetStorage("weebirc_server_address", a.weebserveraddress), a.$apply());
    };
    a.saveAddressButton = function() {
      c.resetStorage("weebirc_server_address", a.weebserveraddress);
      a.$apply();
    };
    a.resetAddress = function() {
      c.resetStorage("weebirc_server_address", "http://" + e.host());
      a.weebserveraddress = "http://" + e.host();
      a.$apply();
    };
    a.setCustomDlDir = function() {
      console.log("Custom dir: " + a.Directory);
      f.setDownloadDirectory(a.Directory);
      c.resetStorage("download_directory", a.Directory);
      Materialize.toast("Download Directory: " + a.Directory + " succesfully saved!");
    };
    a.allStorages = c.getCurrentAvailableStorages();
    a.deleteCertainStorage = function(b) {
      c.deleteStorage(b);
      a.allStorages = c.getCurrentAvailableStorages();
      a.$apply();
    };
    a.deleteEverything = function() {
      $.each(a.allStorages, function(a, b) {
        c.deleteStorage(b);
      });
      a.allStorages = c.getCurrentAvailableStorages();
      a.$apply();
    };
    d = c.retreiveFromStorage("default_resolution");
    "1080" == d ? (a.resB1 = "blue", a.resB2 = "", a.resB3 = "", a.resB4 = "") : "720" == d ? (a.resB1 = "", a.resB2 = "blue", a.resB3 = "", a.resB4 = "") : "480" == d ? (a.resB1 = "", a.resB2 = "", a.resB3 = "blue", a.resB4 = "") : "" == d && (a.resB1 = "", a.resB2 = "", a.resB3 = "", a.resB4 = "blue");
    a.changeResolution = function(b) {
      $.each(["unknown", "480", "720", "1080"], function(a, c) {
        $("#" + c).removeClass("blue");
        c == b && $("#" + c).addClass("blue");
      });
      c.resetStorage("default_resolution", b);
      a.$apply();
    };
    a.debugmessages = c.retreiveFromStorage("debug_messages").reverse();
    setInterval(function() {
      b();
      a.debugmessages = c.retreiveFromStorage("debug_messages").reverse();
    }, 2E3);
  }]);
  app.controller("serverDownloadCtrl", ["$rootScope", "$scope", "storage", function(d, a, e) {
    $("#firstLaunch").closeModal();
    a.choose = !0;
    a.windows = !1;
    a.linux = !1;
    a.showWindowsTutorial = function() {
      a.windows = !0;
      a.linux = !1;
      a.choose = !1;
    };
    a.showLinuxTutorial = function() {
      a.windows = !1;
      a.linux = !0;
      a.choose = !1;
    };
  }]);
  app.controller("aboutCtrl", ["$rootScope", "$scope", "storage", function(d, a, e) {
    a.$emit("changeConfig", {pageTitle:"WeebIRC | About", navbarTitle:"About", navbarColor:"yellow"});
  }]);