home.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. var bIconsVisible = false;
  28. $(document).ready(function() {
  29. $("#Password").on("keydown",function(e){
  30. key = e.which;
  31. //alert(key);
  32. $("#userHint").val("");
  33. if (key===13) {
  34. e.preventDefault();
  35. frmHC.submit();
  36. } else {
  37. //e.preventDefault();
  38. }
  39. });
  40. $("#Password2").on("keydown",function(e){
  41. key = e.which;
  42. //alert(key);
  43. $("#userHint").val("");
  44. if (key===13) {
  45. e.preventDefault();
  46. $("#Password").val("");
  47. frmHC.submit();
  48. } else {
  49. //e.preventDefault();
  50. }
  51. });
  52. $("#MessageLine").on("keydown",function(e){
  53. key = e.which;
  54. //alert(key);
  55. if (key===13) {
  56. //e.preventDefault();
  57. //sendMessage()
  58. } else {
  59. //e.preventDefault();
  60. }
  61. });
  62. });
  63. $("#burger-menu").on("click",function(){
  64. if (!bBurgerMenuVisible) {
  65. $(".friend-header").css("display", "table");
  66. } else {
  67. $(".friend-header").css("display", "none");
  68. }
  69. bBurgerMenuVisible=!bBurgerMenuVisible;
  70. });
  71. function hideBurgerMenu() {
  72. $(".friend-header").css("display", "none");
  73. bBurgerMenuVisible=false;
  74. }
  75. function changeChat(user) {
  76. $("#userHint").val(user);
  77. frmHC.submit();
  78. }
  79. $("#pop-icons").on("click", function() {
  80. if (!bIconsVisible) {
  81. tollerance = 450 / window.scrollY;
  82. msgLineRect = document.getElementById("MessageLine").getBoundingClientRect();
  83. //mytop = parseInt(msgLineRect.top - window.scrollY - 350 - tollerance) + "px";
  84. left = parseInt(msgLineRect.left + msgLineRect.width - 260) + "px";
  85. if (window.innerWidth < 650) {
  86. left = parseInt(msgLineRect.left + msgLineRect.width - 0) + "px";
  87. }
  88. //$("#emoticons").css("top", mytop);
  89. $("#emoticons").css("left", left);
  90. $("#emoticons").css("display", "inline");
  91. $("#emoticons").css("z-index", "99999");
  92. } else {
  93. $("#emoticons").css("display", "none");
  94. }
  95. bIconsVisible = !bIconsVisible;
  96. });
  97. function hideIcons() {
  98. $("#emoticons").css("display", "none");
  99. IconsVisible = false;
  100. }
  101. function insertEmotIcon(icon) {
  102. $("#MessageLine").val($("#MessageLine").val() + icon);
  103. }
  104. function closeSplash() {
  105. $("#hideSplash").val("1");
  106. $("#splash").hide();
  107. }
  108. /**
  109. * Encrypt the given string
  110. *
  111. * @param {string} string - The string to encrypt
  112. * @returns {string} the encrypted string
  113. */
  114. function encryptSha2(string) {
  115. var jsSHAo = new jsSHA("SHA-256", "TEXT", 1);
  116. jsSHAo.update(string);
  117. return jsSHAo.getHash("HEX");
  118. }
  119. function refresh() {
  120. $("#CommandLine").val("refreshbrd");
  121. frmHC.submit();
  122. }
  123. function sendMessage() {
  124. //if ($("#MessageLine").val()==="") {
  125. // alert("First, write your message!");
  126. // return;
  127. //}
  128. $("#CommandLine").val("sendmsg");
  129. frmHC.submit();
  130. }
  131. function setContentPos() {
  132. if (window.innerWidth<650) {
  133. $("#ahome").attr("href","/");
  134. $("#agithub").css("display","none");
  135. $("#afeedback").css("display","none");
  136. $("#asupport").css("display","none");
  137. $("#pwd2").css("display","inline");
  138. $("#sidebar").css("display","none");
  139. $("#burger-menu").css("display","inline");
  140. $("#messagebar").css("width","100%");
  141. $("#logo-hmm").css("display","none");
  142. } else {
  143. $("#ahome").attr("href","http://homomm.org");
  144. $("#agithub").css("display","inline");
  145. $("#afeedback").css("display","inline");
  146. $("#asupport").css("display","inline");
  147. $("#pwd2").css("display","none");
  148. $("#sidebar").css("display","inline");
  149. $("#burger-menu").css("display","none");
  150. $("#messagebar").css("width","75%");
  151. $("#logo-hmm").css("display","inline");
  152. }
  153. hideBurgerMenu();
  154. hideIcons();
  155. if (window.innerWidth<900) {
  156. $("#MessageL").css("width","97%");
  157. $("#MessageK").css("width","89%");
  158. $("#del-attach").css("top","-42px");
  159. } else {
  160. $("#MessageL").css("width","100%");
  161. $("#MessageK").css("width","93%");
  162. $("#del-attach").css("top","-34px");
  163. }
  164. newConsoleHeight = parseInt(window.innerHeight-250);
  165. $("#Console").css("height", newConsoleHeight + "px");
  166. //$("#Messagep").css("top", (newConsoleHeight - 433) + "px");
  167. msgKrect=document.getElementById("MessageK").getBoundingClientRect();
  168. msgLineRect=document.getElementById("MessageLine").getBoundingClientRect();
  169. $("#MessageS").css("height",parseInt(msgLineRect.height));
  170. $("#MessageS").css("max-height",parseInt(msgLineRect.height));
  171. $("#MessageLine").css("width", parseInt(msgKrect.width - 115) + "px");
  172. window.scroll(0, 0);
  173. $(document.body).css("overflow-y", "hidden");
  174. }
  175. function setFooterPos() {
  176. //if (document.getElementById("footerCont")) {
  177. //if ($("#Password").val() === "") {
  178. // tollerance = 48;
  179. //} else {
  180. tollerance = 15;
  181. //}
  182. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  183. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  184. //}
  185. }
  186. function showEncodedPassword() {
  187. if ($("#Password").val() === "") {
  188. $("#Password").addClass("emptyfield");
  189. return;
  190. }
  191. if ($("#Salt").val() === "") {
  192. $("#Salt").addClass("emptyfield");
  193. return;
  194. }
  195. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  196. msg = "Please set your hash in the config file with this value:";
  197. alert(msg + "\n\n" + passw);
  198. }
  199. $("input#files").on("change", function(e) {
  200. if (!document.getElementById("files").files) {
  201. $("#del-attach").css("display", "none");
  202. } else {
  203. $("#del-attach").css("display", "inline");
  204. }
  205. //frmHC.submit();
  206. });
  207. function clearUpload() {
  208. $("#upload-cont").html("<input id='files' name='files[]' type='file' accept='.gif,.png,.jpg,.jpeg' style='visibility: hidden;'>");
  209. $("#del-attach").css("display", "none");
  210. }
  211. $("#Password").on("keydown", function(e){
  212. $("#Password").removeClass("emptyfield");
  213. });
  214. $("#Salt").on("keydown", function(e){
  215. $("#Salt").removeClass("emptyfield");
  216. });
  217. window.addEventListener("load", function() {
  218. if ($("#frmHC").css("display")==="none") {
  219. setTimeout("setContentPos()", 5200);
  220. setTimeout("setFooterPos()", 5300);
  221. } else {
  222. setTimeout("setContentPos()", 100);
  223. setTimeout("setFooterPos()", 3000);
  224. }
  225. }, true);
  226. window.addEventListener("resize", function() {
  227. if ($("#frmHC").css("display")==="none") {
  228. setTimeout("setContentPos()", 5200);
  229. setTimeout("setFooterPos()", 5300);
  230. } else {
  231. setTimeout("setContentPos()", 100);
  232. setTimeout("setFooterPos()", 3000);
  233. }
  234. }, true);