common.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Copyright 2021, 2024 5 Mode
  3. *
  4. * This file is part of MacSwap.
  5. *
  6. * MacSwap 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. * MacSwap 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 MacSwap. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * common.js
  20. *
  21. * common javascript
  22. *
  23. * @author Daniele Bonini <my25mb@aol.com>
  24. * @copyrights (c) 2016, 2024, 5 Mode
  25. */
  26. /**
  27. * Encrypt the given string
  28. *
  29. * @param {string} string - The string to encrypt
  30. * @returns {string} the encrypted string
  31. */
  32. function encryptSha2(string) {
  33. var jsSHAo = new jsSHA("SHA-256", "TEXT", 1);
  34. jsSHAo.update(string);
  35. return jsSHAo.getHash("HEX");
  36. }
  37. /**
  38. * Open a link from any event handler
  39. *
  40. * @param {string} href the link to open
  41. * @param {string} target the frame target
  42. * @returns {none}
  43. */
  44. function openLink(href, target) {
  45. window.open(href, target);
  46. }
  47. function rnd(min, max) {
  48. min = Math.ceil(min);
  49. max = Math.floor(max);
  50. return Math.floor(Math.random() * (max - min +1)) + min;
  51. }
  52. window.addEventListener("load", function(){
  53. }, true);
  54. window.addEventListener("resize", function(){
  55. }, true);
  56. // Global window load event handler..
  57. window.addEventListener("scroll", function() {
  58. }, true);