comm.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var VisibleMenu = ""; // 記錄目前顯示的子選單的 ID
  2. // 顯示或隱藏子選單
  3. function switchMenu(theMainMenu, theSubMenu, theEvent) {
  4. var SubMenu = document.getElementById(theSubMenu);
  5. if (SubMenu.style.display == "none") {
  6. // 顯示子選單
  7. SubMenu.style.display = "block";
  8. hideMenu(); // 隱藏子選單
  9. VisibleMenu = theSubMenu;
  10. } else {
  11. // 隱藏子選單
  12. if (theEvent != "MouseOver" || VisibleMenu != theSubMenu) {
  13. SubMenu.style.display = "none";
  14. VisibleMenu = "";
  15. }
  16. }
  17. }
  18. // 隱藏子選單
  19. function hideMenu() {
  20. if (VisibleMenu != "") {
  21. document.getElementById(VisibleMenu).style.display = "none";
  22. }
  23. VisibleMenu = "";
  24. }
  25. function com_show_sub_tree(obj) {
  26. eParent = obj.parentNode;
  27. var x = eParent.getElementsByTagName("ul");
  28. if (x[0].style.display == "none") {
  29. x[0].style.display = "block";
  30. obj.getElementsByTagName("span")[0].innerHTML = "-";
  31. } else {
  32. x[0].style.display = "none";
  33. obj.getElementsByTagName("span")[0].innerHTML = "+";
  34. }
  35. }
  36. //check if the next sibling node is an element node
  37. function com_get_nextsibling(n) {
  38. let x = n.nextSibling;
  39. if (x != null) {
  40. while (x.nodeType != 1) {
  41. x = x.nextSibling;
  42. if (x == null) {
  43. return null;
  44. }
  45. }
  46. }
  47. return x;
  48. }
  49. function com_guid(trim = true, hyphen = false) {
  50. //guid生成器
  51. if (trim) {
  52. if (hyphen) {
  53. var tmp = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
  54. } else {
  55. var tmp = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  56. }
  57. } else {
  58. if (hyphen) {
  59. var tmp = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}";
  60. } else {
  61. var tmp = "{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}";
  62. }
  63. }
  64. var guid = tmp.replace(/[xy]/g, function (c) {
  65. var r = (Math.random() * 16) | 0,
  66. v = c == "x" ? r : (r & 0x3) | 0x8;
  67. return v.toString(16);
  68. });
  69. return guid.toUpperCase();
  70. }
  71. function com_uuid() {
  72. //guid生成器
  73. let tmp = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
  74. let uuid = tmp.replace(/[xy]/g, function (c) {
  75. var r = (Math.random() * 16) | 0,
  76. v = c == "x" ? r : (r & 0x3) | 0x8;
  77. return v.toString(16);
  78. });
  79. return uuid.toLowerCase();
  80. }
  81. function com_xmlToString(elem) {
  82. var serialized;
  83. try {
  84. serializer = new XMLSerializer();
  85. serialized = serializer.serializeToString(elem);
  86. } catch (e) {
  87. serialized = elem.xml;
  88. }
  89. return serialized;
  90. }
  91. function com_getPaliReal(inStr) {
  92. var paliletter = "abcdefghijklmnoprstuvyāīūṅñṭḍṇḷṃ";
  93. var output = "";
  94. inStr = inStr.toLowerCase();
  95. inStr = inStr.replace(/ṁ/g, "ṃ");
  96. inStr = inStr.replace(/ŋ/g, "ṃ");
  97. for (x in inStr) {
  98. if (paliletter.indexOf(inStr[x]) != -1) {
  99. output += inStr[x];
  100. }
  101. }
  102. return output;
  103. }
  104. function getCookie(c_name) {
  105. if (document.cookie.length > 0) {
  106. c_start = document.cookie.indexOf(c_name + "=");
  107. if (c_start != -1) {
  108. c_start = c_start + c_name.length + 1;
  109. c_end = document.cookie.indexOf(";", c_start);
  110. if (c_end == -1) c_end = document.cookie.length;
  111. return unescape(document.cookie.substring(c_start, c_end));
  112. } else {
  113. return "";
  114. }
  115. } else {
  116. return "";
  117. }
  118. }
  119. function setTimeZone() {
  120. const date = new Date();
  121. const timezone = date.getTimezoneOffset();
  122. setCookie("timezone", timezone, 10);
  123. }
  124. function setCookie(c_name, value, expiredays) {
  125. var exdate = new Date();
  126. exdate.setDate(exdate.getDate() + expiredays);
  127. document.cookie =
  128. c_name + "=" + escape(value) + (expiredays == null ? "" : "; expires=" + exdate.toGMTString() + ";path=/");
  129. }
  130. function copy_to_clipboard(strInput) {
  131. const input = document.createElement("input");
  132. input.setAttribute("readonly", "readonly");
  133. input.setAttribute("value", strInput);
  134. document.body.appendChild(input);
  135. // input.setSelectionRange(0, strInput.length);
  136. // input.focus();
  137. input.select();
  138. if (document.execCommand("copy")) {
  139. document.execCommand("copy");
  140. console.log("复制成功");
  141. ntf_show("“" + strInput + "”" + gLocal.gui.copied_to_clipboard);
  142. }
  143. document.body.removeChild(input);
  144. }
  145. //所有页面都需要在加载的的时候设置浏览器时区
  146. setTimeZone();