home.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. * Copyright 2021, 2024 5 Mode
  3. *
  4. * This file is part of Homomm.
  5. *
  6. * Homomm is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Homomm is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Homomm. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * home.js
  20. *
  21. * JS file for Home page
  22. *
  23. * @author Daniele Bonini <my25mb@aol.com>
  24. * @copyrights (c) 2021, 2024, the Open Gallery's contributors
  25. */
  26. var bBurgerMenuVisible = false;
  27. $(document).ready(function() {
  28. $("#Password").on("keydown",function(e){
  29. key = e.which;
  30. //alert(key);
  31. $("#userHint").val("");
  32. if (key===13) {
  33. e.preventDefault();
  34. frmHC.submit();
  35. } else {
  36. //e.preventDefault();
  37. }
  38. });
  39. $("#Password2").on("keydown",function(e){
  40. key = e.which;
  41. //alert(key);
  42. $("#userHint").val("");
  43. if (key===13) {
  44. e.preventDefault();
  45. $("#Password").val("");
  46. frmHC.submit();
  47. } else {
  48. //e.preventDefault();
  49. }
  50. });
  51. $("#MessageLine").on("keydown",function(e){
  52. key = e.which;
  53. //alert(key);
  54. if (key===13) {
  55. //e.preventDefault();
  56. //sendMessage()
  57. } else {
  58. //e.preventDefault();
  59. }
  60. });
  61. });
  62. $("#burger-menu").on("click",function(){
  63. if (!bBurgerMenuVisible) {
  64. $(".friend-header").css("display", "table");
  65. } else {
  66. $(".friend-header").css("display", "none");
  67. }
  68. bBurgerMenuVisible=!bBurgerMenuVisible;
  69. });
  70. function changeChat(user) {
  71. $("#userHint").val(user);
  72. frmHC.submit();
  73. }
  74. function closeSplash() {
  75. $("#hideSplash").val("1");
  76. $("#splash").hide();
  77. }
  78. /**
  79. * Encrypt the given string
  80. *
  81. * @param {string} string - The string to encrypt
  82. * @returns {string} the encrypted string
  83. */
  84. function encryptSha2(string) {
  85. var jsSHAo = new jsSHA("SHA-256", "TEXT", 1);
  86. jsSHAo.update(string);
  87. return jsSHAo.getHash("HEX");
  88. }
  89. function refresh() {
  90. $("#CommandLine").val("refreshbrd");
  91. frmHC.submit();
  92. }
  93. function sendMessage() {
  94. //if ($("#MessageLine").val()==="") {
  95. // alert("First, write your message!");
  96. // return;
  97. //}
  98. $("#CommandLine").val("sendmsg");
  99. frmHC.submit();
  100. }
  101. function setContentPos() {
  102. if (window.innerWidth<650) {
  103. $("#ahome").attr("href","/");
  104. $("#agithub").css("display","none");
  105. $("#afeedback").css("display","none");
  106. $("#asupport").css("display","none");
  107. $("#pwd2").css("display","inline");
  108. $("#sidebar").css("display","none");
  109. $("#burger-menu").css("display","inline");
  110. $("#messagebar").css("width","100%");
  111. $("#logo-hmm").css("display","none");
  112. } else {
  113. $("#ahome").attr("href","http://homomm.org");
  114. $("#agithub").css("display","inline");
  115. $("#afeedback").css("display","inline");
  116. $("#asupport").css("display","inline");
  117. $("#pwd2").css("display","none");
  118. $("#sidebar").css("display","inline");
  119. $("#burger-menu").css("display","none");
  120. $("#messagebar").css("width","75%");
  121. $("#logo-hmm").css("display","inline");
  122. $(".friend-header").css("display", "none");
  123. bBurgerMenuVisible=false;
  124. }
  125. if (window.innerWidth<900) {
  126. $("#MessageL").css("width","97%");
  127. $("#MessageK").css("width","89%");
  128. $("#del-attach").css("top","-42px");
  129. } else {
  130. $("#MessageL").css("width","100%");
  131. $("#MessageK").css("width","93%");
  132. $("#del-attach").css("top","-34px");
  133. }
  134. newConsoleHeight = parseInt(window.innerHeight-250);
  135. $("#Console").css("height", newConsoleHeight + "px");
  136. //$("#Messagep").css("top", (newConsoleHeight - 433) + "px");
  137. msgKrect=document.getElementById("MessageK").getBoundingClientRect();
  138. $("#MessageS").css("height",parseInt(msgKrect.height));
  139. window.scroll(0, 0);
  140. $(document.body).css("overflow-y", "hidden");
  141. }
  142. function setFooterPos() {
  143. //if (document.getElementById("footerCont")) {
  144. //if ($("#Password").val() === "") {
  145. // tollerance = 48;
  146. //} else {
  147. tollerance = 15;
  148. //}
  149. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  150. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  151. //}
  152. }
  153. function showEncodedPassword() {
  154. if ($("#Password").val() === "") {
  155. $("#Password").addClass("emptyfield");
  156. return;
  157. }
  158. if ($("#Salt").val() === "") {
  159. $("#Salt").addClass("emptyfield");
  160. return;
  161. }
  162. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  163. msg = "Please set your hash in the config file with this value:";
  164. alert(msg + "\n\n" + passw);
  165. }
  166. $("input#files").on("change", function(e) {
  167. if (!document.getElementById("files").files) {
  168. $("#del-attach").css("display", "none");
  169. } else {
  170. $("#del-attach").css("display", "inline");
  171. }
  172. //frmHC.submit();
  173. });
  174. function clearUpload() {
  175. $("#upload-cont").html("<input id='files' name='files[]' type='file' accept='.gif,.png,.jpg,.jpeg' style='visibility: hidden;'>");
  176. $("#del-attach").css("display", "none");
  177. }
  178. $("#Password").on("keydown", function(e){
  179. $("#Password").removeClass("emptyfield");
  180. });
  181. $("#Salt").on("keydown", function(e){
  182. $("#Salt").removeClass("emptyfield");
  183. });
  184. window.addEventListener("load", function() {
  185. if ($("#frmHC").css("display")==="none") {
  186. setTimeout("setContentPos()", 5200);
  187. } else {
  188. setTimeout("setContentPos()", 200);
  189. }
  190. setTimeout("setFooterPos()", 3000);
  191. }, true);
  192. window.addEventListener("resize", function() {
  193. if ($("#frmHC").css("display")==="none") {
  194. setTimeout("setContentPos()", 5200);
  195. } else {
  196. setTimeout("setContentPos()", 200);
  197. }
  198. setTimeout("setFooterPos()", 3000);
  199. }, true);