main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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("news");
  23. Meteor.subscribe("userData", Meteor.userId());
  24. });
  25. Handlebars.registerHelper("isAdmin", function(argument){
  26. if (Meteor.user() && Meteor.user().profile) {
  27. return Meteor.user().profile.rank === "admin";
  28. } else {
  29. return false;
  30. }
  31. });
  32. Handlebars.registerHelper("isModerator", function(argument){
  33. if (Meteor.user() && Meteor.user().profile && (Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator")) {
  34. return true;
  35. } else {
  36. return false;
  37. }
  38. });
  39. Handlebars.registerHelper("initials", function(argument){
  40. var user = Meteor.user();
  41. if (user !== undefined) {
  42. return user.profile.username[0].toUpperCase();
  43. } else {
  44. return "";
  45. }
  46. });
  47. /* Global collection helpers */
  48. Handlebars.registerHelper("rooms", function(){
  49. return Rooms.find({});
  50. });
  51. Handlebars.registerHelper('active', function(path) {
  52. return curPath() == path ? 'active' : '';
  53. });
  54. UI.registerHelper("formatTime", function(seconds) {
  55. var d = moment.duration(parseInt(seconds), 'seconds');
  56. return d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  57. });
  58. Template.registerHelper("rtime", function(date) {
  59. Session.get("time");
  60. if (date) {
  61. return moment(date).fromNow();
  62. }
  63. });
  64. var allAlertSub = undefined;
  65. var YTPlayer = undefined;
  66. var previewEndSongTimeout = undefined;
  67. var hpSound = undefined;
  68. var songsArr = [];
  69. var parts = location.href.split('/');
  70. var id = parts.pop();
  71. var type = id.toLowerCase();
  72. 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}}};
  73. function gup( name, url ) {
  74. if (!url) url = location.href;
  75. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  76. var regexS = "[\\?&]"+name+"=([^&#]*)";
  77. var regex = new RegExp( regexS );
  78. var results = regex.exec( url );
  79. return results == null ? null : results[1];
  80. }
  81. var ban_interval = Meteor.setInterval(function() {
  82. var userId = Meteor.userId();
  83. if (userId !== undefined) {
  84. var userData = Meteor.user();
  85. if (localStorage.getItem("banned") === "true") {
  86. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  87. var ban = userData.punishments.ban;
  88. if (new Date(ban.bannedUntil).getTime() <= new Date().getTime()) {
  89. Meteor.call("isBanned", function(err, res) {
  90. if (res === false) {
  91. localStorage.setItem("banned", false);
  92. Meteor._reload.reload();
  93. }
  94. });
  95. }
  96. } else {
  97. localStorage.setItem("banned", false);
  98. Meteor._reload.reload();
  99. }
  100. } else {
  101. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  102. localStorage.setItem("banned", true);
  103. Meteor._reload.reload();
  104. }
  105. }
  106. }
  107. }, 1000);