2
0

main.js 4.0 KB

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