home.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. $(document).ready(function() {
  27. $("#Password").on("keydown",function(e){
  28. key = e.which;
  29. //alert(key);
  30. $("#userHint").val("");
  31. if (key===13) {
  32. e.preventDefault();
  33. frmHC.submit();
  34. } else {
  35. //e.preventDefault();
  36. }
  37. });
  38. $("#MessageLine").on("keydown",function(e){
  39. key = e.which;
  40. //alert(key);
  41. if (key===13) {
  42. //e.preventDefault();
  43. //sendMessage()
  44. } else {
  45. //e.preventDefault();
  46. }
  47. });
  48. });
  49. function changeChat(user) {
  50. $("#userHint").val(user);
  51. frmHC.submit();
  52. }
  53. function closeSplash() {
  54. $("#hideSplash").val("1");
  55. $("#splash").hide();
  56. }
  57. /**
  58. * Encrypt the given string
  59. *
  60. * @param {string} string - The string to encrypt
  61. * @returns {string} the encrypted string
  62. */
  63. function encryptSha2(string) {
  64. var jsSHAo = new jsSHA("SHA-256", "TEXT", 1);
  65. jsSHAo.update(string);
  66. return jsSHAo.getHash("HEX");
  67. }
  68. function refresh() {
  69. $("#CommandLine").val("refreshbrd");
  70. frmHC.submit();
  71. }
  72. function sendMessage() {
  73. //if ($("#MessageLine").val()==="") {
  74. // alert("First, write your message!");
  75. // return;
  76. //}
  77. $("#CommandLine").val("sendmsg");
  78. frmHC.submit();
  79. }
  80. function setContentPos() {
  81. if (window.innerWidth<900) {
  82. $("#MessageL").css("width","97%");
  83. $("#MessageK").css("width","89%");
  84. $("#del-attach").css("top","-42px");
  85. } else {
  86. $("#MessageL").css("width","100%");
  87. $("#MessageK").css("width","93%");
  88. $("#del-attach").css("top","-34px");
  89. }
  90. msgKrect=document.getElementById("MessageK").getBoundingClientRect();
  91. $("#MessageS").css("height",parseInt(msgKrect.height));
  92. }
  93. function setFooterPos() {
  94. if (document.getElementById("footerCont")) {
  95. if ($("#Password").val() === "") {
  96. tollerance = 48;
  97. } else {
  98. tollerance = 15;
  99. }
  100. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  101. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  102. }
  103. }
  104. function showEncodedPassword() {
  105. if ($("#Password").val() === "") {
  106. $("#Password").addClass("emptyfield");
  107. return;
  108. }
  109. if ($("#Salt").val() === "") {
  110. $("#Salt").addClass("emptyfield");
  111. return;
  112. }
  113. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  114. msg = "Please set your hash in the config file with this value:";
  115. alert(msg + "\n\n" + passw);
  116. }
  117. $("input#files").on("change", function(e) {
  118. if (!document.getElementById("files").files) {
  119. $("#del-attach").css("display", "none");
  120. } else {
  121. $("#del-attach").css("display", "inline");
  122. }
  123. //frmHC.submit();
  124. });
  125. function clearUpload() {
  126. $("#upload-cont").html("<input id='files' name='files[]' type='file' accept='.gif,.png,.jpg,.jpeg' style='visibility: hidden;'>");
  127. $("#del-attach").css("display", "none");
  128. }
  129. $("#Password").on("keydown", function(e){
  130. $("#Password").removeClass("emptyfield");
  131. });
  132. $("#Salt").on("keydown", function(e){
  133. $("#Salt").removeClass("emptyfield");
  134. });
  135. window.addEventListener("load", function() {
  136. if ($("#frmHC").css("display")==="none") {
  137. setTimeout("setContentPos()", 6000);
  138. } else {
  139. setTimeout("setContentPos()", 1000);
  140. }
  141. setTimeout("setFooterPos()", 3000);
  142. }, true);
  143. window.addEventListener("resize", function() {
  144. if ($("#frmHC").css("display")==="none") {
  145. setTimeout("setContentPos()", 6000);
  146. } else {
  147. setTimeout("setContentPos()", 1000);
  148. }
  149. setTimeout("setFooterPos()", 3000);
  150. }, true);