main.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. Meteor.startup(function() {
  2. reCAPTCHA.config({
  3. publickey: '6LcVxg0TAAAAAE18vBiH00UAyaJggsmLm890SjZl'
  4. });
  5. Avatar.setOptions({
  6. fallbackType: "initials",
  7. defaultImageUrl: "http://static.boredpanda.com/blog/wp-content/uploads/2014/04/amazing-fox-photos-182.jpg",
  8. generateCSS: true,
  9. imageSizes: {
  10. 'header': 40
  11. }
  12. });
  13. });
  14. Deps.autorun(function() {
  15. Meteor.subscribe("queues");
  16. Meteor.subscribe("reports");
  17. Meteor.subscribe("chat");
  18. Meteor.subscribe("playlists");
  19. Meteor.subscribe("songs");
  20. Meteor.subscribe("alerts");
  21. Meteor.subscribe("rooms");
  22. Meteor.subscribe("userData", Meteor.userId());
  23. });
  24. Handlebars.registerHelper("isAdmin", function(argument){
  25. if (Meteor.user() && Meteor.user().profile) {
  26. return Meteor.user().profile.rank === "admin";
  27. } else {
  28. return false;
  29. }
  30. });
  31. Handlebars.registerHelper("isModerator", function(argument){
  32. if (Meteor.user() && Meteor.user().profile && (Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator")) {
  33. return true;
  34. } else {
  35. return false;
  36. }
  37. });
  38. Handlebars.registerHelper("initials", function(argument){
  39. var user = Meteor.user();
  40. if (user !== undefined) {
  41. return user.profile.username[0].toUpperCase();
  42. } else {
  43. return "";
  44. }
  45. });
  46. /* Global collection helpers */
  47. Handlebars.registerHelper("rooms", function(){
  48. return Rooms.find({});
  49. });
  50. Handlebars.registerHelper('active', function(path) {
  51. return curPath() == path ? 'active' : '';
  52. });
  53. UI.registerHelper("formatTime", function(seconds) {
  54. var d = moment.duration(parseInt(seconds), 'seconds');
  55. return d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  56. });
  57. Template.registerHelper("rtime", function(date) {
  58. Session.get("time");
  59. if (date) {
  60. return moment(date).fromNow();
  61. }
  62. });
  63. var allAlertSub = undefined;
  64. var YTPlayer = undefined;
  65. var previewEndSongTimeout = undefined;
  66. var hpSound = undefined;
  67. var songsArr = [];
  68. var parts = location.href.split('/');
  69. var id = parts.pop();
  70. var type = id.toLowerCase();
  71. curPath=function(){var c=window.location.pathname;var b=c.slice(0,-1);var a=c.slice(-1);if(b==""){return"/"}else{if(a=="/"){return b}else{return c}}};
  72. function gup( name, url ) {
  73. if (!url) url = location.href;
  74. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  75. var regexS = "[\\?&]"+name+"=([^&#]*)";
  76. var regex = new RegExp( regexS );
  77. var results = regex.exec( url );
  78. return results == null ? null : results[1];
  79. }
  80. var ban_interval = Meteor.setInterval(function() {
  81. var userId = Meteor.userId();
  82. if (userId !== undefined) {
  83. var userData = Meteor.user();
  84. if (localStorage.getItem("banned") === "true") {
  85. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  86. var ban = userData.punishments.ban;
  87. if (new Date(ban.bannedUntil).getTime() <= new Date().getTime()) {
  88. Meteor.call("isBanned", function(err, res) {
  89. if (res === false) {
  90. localStorage.setItem("banned", false);
  91. Meteor._reload.reload();
  92. }
  93. });
  94. }
  95. } else {
  96. localStorage.setItem("banned", false);
  97. Meteor._reload.reload();
  98. }
  99. } else {
  100. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  101. localStorage.setItem("banned", true);
  102. Meteor._reload.reload();
  103. }
  104. }
  105. }
  106. }, 1000);