home.js 3.4 KB

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