main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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("songs", function(){
  52. return Songs.find({});
  53. });
  54. Handlebars.registerHelper('active', function(path) {
  55. return curPath() == path ? 'active' : '';
  56. });
  57. UI.registerHelper("formatTime", function(seconds) {
  58. var d = moment.duration(parseInt(seconds), 'seconds');
  59. return d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  60. });
  61. Template.registerHelper("rtime", function(date) {
  62. Session.get("time");
  63. if (date) {
  64. return moment(date).fromNow();
  65. }
  66. });
  67. var allAlertSub = undefined;
  68. var YTPlayer = undefined;
  69. var previewEndSongTimeout = undefined;
  70. var hpSound = undefined;
  71. var songsArr = [];
  72. var parts = location.href.split('/');
  73. var id = parts.pop();
  74. var type = id.toLowerCase();
  75. 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}}};
  76. function gup( name, url ) {
  77. if (!url) url = location.href;
  78. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  79. var regexS = "[\\?&]"+name+"=([^&#]*)";
  80. var regex = new RegExp( regexS );
  81. var results = regex.exec( url );
  82. return results == null ? null : results[1];
  83. }
  84. var ban_interval = Meteor.setInterval(function() {
  85. var userId = Meteor.userId();
  86. if (userId !== undefined) {
  87. var userData = Meteor.user();
  88. if (localStorage.getItem("banned") === "true") {
  89. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  90. var ban = userData.punishments.ban;
  91. if (new Date(ban.bannedUntil).getTime() <= new Date().getTime()) {
  92. Meteor.call("isBanned", function(err, res) {
  93. if (res === false) {
  94. localStorage.setItem("banned", false);
  95. Meteor._reload.reload();
  96. }
  97. });
  98. }
  99. } else {
  100. localStorage.setItem("banned", false);
  101. Meteor._reload.reload();
  102. }
  103. } else {
  104. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  105. localStorage.setItem("banned", true);
  106. Meteor._reload.reload();
  107. }
  108. }
  109. }
  110. }, 1000);