home.js 7.9 KB

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