home.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 sendMessage() {
  69. if ($("#MessageLine").val()==="") {
  70. alert("First, write your message!");
  71. return;
  72. }
  73. $("#CommandLine").val("sendmsg");
  74. frmHC.submit();
  75. }
  76. function setContentPos() {
  77. if (window.innerWidth<900) {
  78. $("#MessageL").css("width","97%");
  79. $("#MessageK").css("width","89%");
  80. } else {
  81. $("#MessageL").css("width","100%");
  82. $("#MessageK").css("width","93%");
  83. }
  84. }
  85. function setFooterPos() {
  86. if (document.getElementById("footerCont")) {
  87. if ($("#Password").val() === "") {
  88. tollerance = 48;
  89. } else {
  90. tollerance = 15;
  91. }
  92. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  93. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  94. }
  95. }
  96. function showEncodedPassword() {
  97. if ($("#Password").val() === "") {
  98. $("#Password").addClass("emptyfield");
  99. return;
  100. }
  101. if ($("#Salt").val() === "") {
  102. $("#Salt").addClass("emptyfield");
  103. return;
  104. }
  105. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  106. msg = "Please set your hash in the config file with this value:";
  107. alert(msg + "\n\n" + passw);
  108. }
  109. $("input#files").on("change", function(e) {
  110. if (!document.getElementById("files").files) {
  111. $("#del-attach").css("display", "none");
  112. } else {
  113. $("#del-attach").css("display", "inline");
  114. }
  115. //frmHC.submit();
  116. });
  117. function clearUpload() {
  118. $("#upload-cont").html("<input id='files' name='files[]' type='file' accept='.gif,.png,.jpg,.jpeg' style='visibility: hidden;'>");
  119. $("#del-attach").css("display", "none");
  120. }
  121. $("#Password").on("keydown", function(e){
  122. $("#Password").removeClass("emptyfield");
  123. });
  124. $("#Salt").on("keydown", function(e){
  125. $("#Salt").removeClass("emptyfield");
  126. });
  127. window.addEventListener("load", function() {
  128. setTimeout("setContentPos()", 1000);
  129. setTimeout("setFooterPos()", 3000);
  130. }, true);
  131. window.addEventListener("resize", function() {
  132. setTimeout("setContentPos()", 1000);
  133. setTimeout("setFooterPos()", 3000);
  134. }, true);