home.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * Copyright 2021, 2024 5 Mode
  3. *
  4. * This file is part of Http Console.
  5. *
  6. * Http Console 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. * Http Console 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 Http Console. 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. $(document).ready(function() {
  28. $("#Password").on("keydown",function(e){
  29. key = e.which;
  30. //alert(key);
  31. if (key===13) {
  32. e.preventDefault();
  33. frmHC.submit();
  34. } else {
  35. $("#Password2").val($(this).val());
  36. //e.preventDefault();
  37. }
  38. });
  39. $("#Password2").on("keydown",function(e){
  40. key = e.which;
  41. //alert(key);
  42. if (key===13) {
  43. e.preventDefault();
  44. $("#Password").val("");
  45. frmHC.submit();
  46. } else {
  47. //e.preventDefault();
  48. }
  49. });
  50. });
  51. function closeSplash() {
  52. $("#hideSplash").val("1");
  53. $("#splash").hide();
  54. }
  55. /**
  56. * Encrypt the given string
  57. *
  58. * @param {string} string - The string to encrypt
  59. * @returns {string} the encrypted string
  60. */
  61. function encryptSha2(string) {
  62. var jsSHAo = new jsSHA("SHA-256", "TEXT", 1);
  63. jsSHAo.update(string);
  64. return jsSHAo.getHash("HEX");
  65. }
  66. function setFooterPos() {
  67. if (document.getElementById("footerCont")) {
  68. //if ($("#Password").val() === "") {
  69. // tollerance = 48;
  70. // } else {
  71. // tollerance = 15;
  72. //}
  73. tollerance = 22;
  74. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  75. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance + 6) + "px");
  76. }
  77. }
  78. function delImg(id, path) {
  79. if (confirm("Do you really want to delete that picture?")) {
  80. $("#CommandLine").val("del '" + path + "'");
  81. frmHC.submit();
  82. }
  83. }
  84. function changeVisibility(id, path) {
  85. if ($("#lock-" + id).attr("src") === "/res/private.png") {
  86. $("#CommandLine").val("publicify '" + path + "'");
  87. } else {
  88. $("#CommandLine").val("privatify '" + path + "'");
  89. }
  90. frmHC.submit();
  91. }
  92. function makeNewFolder() {
  93. var newFolderName = prompt("How to name the new folder?");
  94. if (newFolderName != null) {
  95. $("#CommandLine").val("makedir '" + newFolderName + "'");
  96. frmHC.submit();
  97. }
  98. }
  99. function openLink(href, target) {
  100. window.open(href, target);
  101. }
  102. function changePath(newPath) {
  103. $("#pwd").val(newPath);
  104. frmHC.submit();
  105. }
  106. function showEncodedPassword() {
  107. if ($("#Password").val() === "") {
  108. $("#Password").addClass("emptyfield");
  109. return;
  110. }
  111. if ($("#Salt").val() === "") {
  112. $("#Salt").addClass("emptyfield");
  113. return;
  114. }
  115. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  116. msg = "Please set your hash in the config file with this value:";
  117. alert(msg + "\n\n" + passw);
  118. }
  119. function upload() {
  120. $("input#files").click();
  121. }
  122. $("input#files").on("change", function(e) {
  123. frmHC.submit();
  124. });
  125. $("#Password").on("keydown", function(e){
  126. $("#Password").removeClass("emptyfield");
  127. });
  128. $("#Salt").on("keydown", function(e){
  129. $("#Salt").removeClass("emptyfield");
  130. });
  131. function refresh() {
  132. $("#CommandLine").val("refresh");
  133. frmHC.submit();
  134. }
  135. function closePlayer() {
  136. refresh();
  137. }
  138. function openPic(pic) {
  139. //alert(pic);
  140. $("#CommandLine").val("openpic " + pic);
  141. frmHC.submit();
  142. }
  143. $("#burger-menu").on("click",function(){
  144. if (!bBurgerMenuVisible) {
  145. $(".burger-header").css("display", "table");
  146. } else {
  147. $(".burger-header").css("display", "none");
  148. }
  149. bBurgerMenuVisible=!bBurgerMenuVisible;
  150. });
  151. function hideBurgerMenu() {
  152. $(".burger-header").css("display", "none");
  153. bBurgerMenuVisible=false;
  154. }
  155. function setContentPos() {
  156. if (window.innerWidth<650) {
  157. $("#ahome").attr("href","/");
  158. $("#agithub").css("display","none");
  159. $("#afeedback").css("display","none");
  160. $("#asupport").css("display","none");
  161. $("#pwd2").css("display","inline");
  162. $("#sidebar").css("display","none");
  163. $("#burger-menu").css("display","inline");
  164. $("#contentbar").css("width","100%");
  165. $("#logo-hg").css("display","none");
  166. } else if (window.innerWidth<1120) {
  167. $("#ahome").attr("href","http://homogram.org");
  168. $("#agithub").css("display","inline");
  169. $("#afeedback").css("display","inline");
  170. $("#asupport").css("display","inline");
  171. $("#pwd2").css("display","none");
  172. $("#sidebar").css("display","inline");
  173. $("#burger-menu").css("display","none");
  174. $("#contentbar").css("width","75%");
  175. $("#logo-hg").css("display","inline");
  176. } else {
  177. $("#ahome").attr("href","http://homogram.org");
  178. $("#agithub").css("display","inline");
  179. $("#afeedback").css("display","inline");
  180. $("#asupport").css("display","inline");
  181. $("#pwd2").css("display","none");
  182. $("#sidebar").css("display","inline");
  183. $("#burger-menu").css("display","none");
  184. $("#contentbar").css("width","77.5%");
  185. $("#logo-hg").css("display","inline");
  186. }
  187. hideBurgerMenu();
  188. }
  189. function loadImages() {
  190. $(".image-cont").each(function(){
  191. $(this).css("display","inline");
  192. });
  193. }
  194. window.addEventListener("load", function() {
  195. if ($("#frmHC").css("display")==="none") {
  196. setTimeout("setContentPos()", 5200);
  197. setTimeout("setFooterPos()", 5300);
  198. } else {
  199. setTimeout("setContentPos()", 1000);
  200. setTimeout("setFooterPos()", 2000);
  201. }
  202. loadImages();
  203. //document.getElementById("CommandLine").focus();
  204. });
  205. window.addEventListener("resize", function() {
  206. if ($("#frmHC").css("display")==="none") {
  207. setTimeout("setContentPos()", 5200);
  208. setTimeout("setFooterPos()", 5300);
  209. } else {
  210. setTimeout("setContentPos()", 1000);
  211. setTimeout("setFooterPos()", 2000);
  212. }
  213. });