home.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 deletePic(pic) {
  132. $("#CommandLine").val("delpic " + pic);
  133. frmHC.submit();
  134. }
  135. function deleteMsg(msg) {
  136. $("#CommandLine").val("delmsg " + msg);
  137. frmHC.submit();
  138. }
  139. function setContentPos() {
  140. if (window.innerWidth<650) {
  141. $("#ahome").attr("href","/");
  142. $("#agithub").css("display","none");
  143. $("#afeedback").css("display","none");
  144. $("#asupport").css("display","none");
  145. $("#pwd2").css("display","inline");
  146. $("#sidebar").css("display","none");
  147. $("#burger-menu").css("display","inline");
  148. $("#messagebar").css("width","100%");
  149. $("#logo-hmm").css("display","none");
  150. } else {
  151. $("#ahome").attr("href","http://homomm.org");
  152. $("#agithub").css("display","inline");
  153. $("#afeedback").css("display","inline");
  154. $("#asupport").css("display","inline");
  155. $("#pwd2").css("display","none");
  156. $("#sidebar").css("display","inline");
  157. $("#burger-menu").css("display","none");
  158. $("#messagebar").css("width","75%");
  159. $("#logo-hmm").css("display","inline");
  160. }
  161. hideBurgerMenu();
  162. hideIcons();
  163. if (window.innerWidth<900) {
  164. $("#MessageL").css("width","97%");
  165. $("#MessageK").css("width","89%");
  166. $("#del-attach").css("top","-42px");
  167. } else {
  168. $("#MessageL").css("width","100%");
  169. $("#MessageK").css("width","93%");
  170. $("#del-attach").css("top","-34px");
  171. }
  172. newConsoleHeight = parseInt(window.innerHeight-250);
  173. $("#Console").css("height", newConsoleHeight + "px");
  174. //$("#Messagep").css("top", (newConsoleHeight - 433) + "px");
  175. msgKrect=document.getElementById("MessageK").getBoundingClientRect();
  176. msgLineRect=document.getElementById("MessageLine").getBoundingClientRect();
  177. $("#MessageS").css("height",parseInt(msgLineRect.height));
  178. $("#MessageS").css("max-height",parseInt(msgLineRect.height));
  179. $("#MessageLine").css("width", parseInt(msgKrect.width - 115) + "px");
  180. window.scroll(0, 0);
  181. $(document.body).css("overflow-y", "hidden");
  182. }
  183. function setFooterPos() {
  184. //if (document.getElementById("footerCont")) {
  185. //if ($("#Password").val() === "") {
  186. // tollerance = 48;
  187. //} else {
  188. tollerance = 15;
  189. //}
  190. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  191. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  192. //}
  193. }
  194. function showEncodedPassword() {
  195. if ($("#Password").val() === "") {
  196. $("#Password").addClass("emptyfield");
  197. return;
  198. }
  199. if ($("#Salt").val() === "") {
  200. $("#Salt").addClass("emptyfield");
  201. return;
  202. }
  203. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  204. msg = "Please set your hash in the config file with this value:";
  205. alert(msg + "\n\n" + passw);
  206. }
  207. $("input#files").on("change", function(e) {
  208. if (!document.getElementById("files").files) {
  209. $("#del-attach").css("display", "none");
  210. } else {
  211. $("#del-attach").css("display", "inline");
  212. }
  213. //frmHC.submit();
  214. });
  215. function clearUpload() {
  216. $("#upload-cont").html("<input id='files' name='files[]' type='file' accept='.gif,.png,.jpg,.jpeg' style='visibility: hidden;'>");
  217. $("#del-attach").css("display", "none");
  218. }
  219. $("#Password").on("keydown", function(e){
  220. $("#Password").removeClass("emptyfield");
  221. });
  222. $("#Salt").on("keydown", function(e){
  223. $("#Salt").removeClass("emptyfield");
  224. });
  225. window.addEventListener("load", function() {
  226. if ($("#frmHC").css("display")==="none") {
  227. setTimeout("setContentPos()", 5200);
  228. setTimeout("setFooterPos()", 5300);
  229. } else {
  230. setTimeout("setContentPos()", 100);
  231. setTimeout("setFooterPos()", 3000);
  232. }
  233. }, true);
  234. window.addEventListener("resize", function() {
  235. if ($("#frmHC").css("display")==="none") {
  236. setTimeout("setContentPos()", 5200);
  237. setTimeout("setFooterPos()", 5300);
  238. } else {
  239. setTimeout("setContentPos()", 100);
  240. setTimeout("setFooterPos()", 3000);
  241. }
  242. }, true);