-
-
流量监控代码配置
+
-
-
-
+ if (unlimitedEndDateCheckbox.checked) {
+ endDate = "0000-00-00T23:59:59" + tz // 设置为无限期
+ } else {
+ endDate = formatDateWithTimezone(document.getElementById("endDate").value, tz)
+ }
-
\ No newline at end of file
+ const autoRenewal = document.getElementById("autoRenewal").value
+ const cycleSelect = document.getElementById("cycle")
+ const cycleCustom = document.getElementById("cycleCustom").value
+ const cycle = cycleSelect.value === "custom" ? cycleCustom : cycleSelect.value
+
+ const freeamountCheckbox = document.getElementById("freeamount")
+ let amount = "0"
+ if (!freeamountCheckbox.checked) {
+ const amountValue = document.getElementById("amountValue").value
+ const amountCurrencySelect = document.getElementById("amountCurrency")
+ const amountCustom = document.getElementById("amountCustom").value
+ const amountCurrency =
+ amountCurrencySelect.value === "custom"
+ ? amountCustom
+ : amountCurrencySelect.value
+ amount = amountValue + amountCurrency
+ }
+
+ const unlimitedBandwidthCheckbox = document.getElementById("unlimitedBandwidth")
+ let bandwidth = "无限"
+ if (!unlimitedBandwidthCheckbox.checked) {
+ const bandwidthValue = document.getElementById("bandwidthValue").value
+ const bandwidthUnitSelect = document.getElementById("bandwidthUnit")
+ const bandwidthCustom = document.getElementById("bandwidthCustom").value
+ const bandwidthUnit =
+ bandwidthUnitSelect.value === "custom"
+ ? bandwidthCustom
+ : bandwidthUnitSelect.value
+ bandwidth = bandwidthValue + bandwidthUnit
+ }
+
+ const unlimitedTrafficCheckbox = document.getElementById("unlimitedTraffic")
+ let trafficVol = "无限"
+ if (!unlimitedTrafficCheckbox.checked) {
+ const trafficValue = document.getElementById("trafficValue").value
+ const trafficUnitSelect = document.getElementById("trafficUnit")
+ const trafficPeriodSelect = document.getElementById("trafficPeriod")
+ const trafficUnitCustom = document.getElementById("trafficUnitCustom").value
+ const trafficPeriodCustom = document.getElementById("trafficPeriodCustom").value
+ let trafficUnit =
+ trafficUnitSelect.value === "custom"
+ ? trafficUnitCustom
+ : trafficUnitSelect.value
+ let trafficPeriod =
+ trafficPeriodSelect.value === "custom"
+ ? trafficPeriodCustom
+ : trafficPeriodSelect.value
+ trafficVol = trafficValue + trafficUnit + trafficPeriod
+ }
+
+ const trafficType = document.getElementById("trafficType").value
+ const ipv4 = document.getElementById("ipv4").value
+ const ipv6 = document.getElementById("ipv6").value
+ let networkRoute = ""
+
+ const routeModeSelect = document.getElementById("routeMode")
+ if (routeModeSelect.value === "tags") {
+ const selectedTagsContainer = document.getElementById("selectedTagsContainer")
+ const selectedTags = Array.from(
+ selectedTagsContainer.querySelectorAll(".tag"),
+ ).map((tag) => tag.textContent)
+ networkRoute = selectedTags.join("|")
+ } else {
+ const telecomRoute1 = document.getElementById("telecomRoute1").value
+ const telecomRoute2 = document.getElementById("telecomRoute2").value
+ const mobileRoute1 = document.getElementById("mobileRoute1").value
+ const mobileRoute2 = document.getElementById("mobileRoute2").value
+ const unicomRoute1 = document.getElementById("unicomRoute1").value
+ const unicomRoute2 = document.getElementById("unicomRoute2").value
+
+ const telecomRoutes = [telecomRoute1, telecomRoute2]
+ .filter((route) => route !== "")
+ .join("|")
+ const mobileRoutes = [mobileRoute1, mobileRoute2]
+ .filter((route) => route !== "")
+ .join("|")
+ const unicomRoutes = [unicomRoute1, unicomRoute2]
+ .filter((route) => route !== "")
+ .join("|")
+
+ const routes = []
+ if (telecomRoutes) routes.push(`电信${telecomRoutes}`)
+ if (mobileRoutes) routes.push(`移动${mobileRoutes}`)
+ if (unicomRoutes) routes.push(`联通${unicomRoutes}`)
+
+ networkRoute = routes.join(" ")
+ }
+
+ const extra = document.getElementById("extra").value
+
+ const jsonOutput = document.getElementById("jsonOutput")
+ const json = {
+ billingDataMod: {
+ startDate: formatDateWithTimezone(startDate, tz),
+ endDate: endDate, // 使用经过处理的endDate
+ autoRenewal: autoRenewal,
+ cycle: cycle,
+ amount: amount,
+ },
+ planDataMod: {
+ bandwidth: bandwidth,
+ trafficVol: trafficVol,
+ trafficType: trafficType,
+ IPv4: ipv4,
+ IPv6: ipv6,
+ networkRoute: networkRoute,
+ extra: extra,
+ },
+ }
+ document.querySelector("#jsonOutput code").innerHTML = Prism.highlight(
+ JSON.stringify(json, null, 2),
+ Prism.languages.json,
+ "json",
+ )
+ }
+
+ function generateTrafficMonitorJSON() {
+ const tz = document.getElementById("timezone2").value
+ const monitorType = document.getElementById("monitorType").value
+ const maxTrafficValue = document.getElementById("maxTraffic").value
+ const maxTrafficUnit = document.getElementById("maxTrafficUnit").value
+ const cycleStart = document.getElementById("cycleStart").value
+ const cycleInterval = document.getElementById("cycleInterval").value
+ const cycleUnit = document.getElementById("cycleUnit").value
+ const cover = document.getElementById("cover").value
+ const ignore = document.getElementById("ignore").value
+
+ let maxBytes = parseFloat(maxTrafficValue)
+ if (maxTrafficUnit === "GB") {
+ maxBytes *= 1024 * 1024 * 1024
+ } else if (maxTrafficUnit === "TB") {
+ maxBytes *= 1024 * 1024 * 1024 * 1024
+ } else {
+ // MB
+ maxBytes *= 1024 * 1024
+ }
+
+ const ignoreArray = ignore
+ .split(",")
+ .map((item) => item.trim())
+ .filter((item) => item !== "")
+ const ignoreObject = {}
+ ignoreArray.forEach((item) => {
+ ignoreObject[item] = true
+ })
+
+ const jsonOutput2 = document.getElementById("jsonOutput2")
+ const json = [
+ {
+ type: monitorType,
+ max: maxBytes,
+ cycle_start: formatDateWithTimezone(cycleStart, tz),
+ cycle_interval: parseInt(cycleInterval),
+ cycle_unit: cycleUnit,
+ cover: parseInt(cover),
+ ignore: ignoreObject,
+ },
+ ]
+ document.querySelector("#jsonOutput2 code").innerHTML = Prism.highlight(
+ JSON.stringify(json, null, 2),
+ Prism.languages.json,
+ "json",
+ )
+ }
+
+ function toggleTheme() {
+ const body = document.body
+ const themeToggle = document.getElementById("themeToggle")
+ const currentTheme = themeToggle.getAttribute("data-theme")
+ let newTheme
+
+ if (currentTheme === "system") {
+ newTheme = "light"
+ body.classList.remove("dark-mode")
+ themeToggle.innerHTML = ''
+ } else if (currentTheme === "light") {
+ newTheme = "dark"
+ body.classList.add("dark-mode")
+ themeToggle.innerHTML = ''
+ } else {
+ newTheme = "system"
+ themeToggle.innerHTML = ''
+ applySystemTheme()
+ }
+
+ themeToggle.setAttribute("data-theme", newTheme)
+ localStorage.setItem("theme-preference", newTheme)
+ }
+
+ function applySystemTheme() {
+ const isDarkMode = window.matchMedia("(prefers-color-scheme: dark)").matches
+ document.body.classList.toggle("dark-mode", isDarkMode)
+ }
+
+ function setupSystemThemeListener() {
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)")
+ mediaQuery.addEventListener("change", (e) => {
+ const themeToggle = document.getElementById("themeToggle")
+ if (themeToggle.getAttribute("data-theme") === "system") {
+ document.body.classList.toggle("dark-mode", e.matches)
+ }
+ })
+ }
+
+ document.addEventListener("DOMContentLoaded", () => {
+ const themeToggle = document.getElementById("themeToggle")
+ const savedTheme = localStorage.getItem("theme-preference") || "system"
+ themeToggle.setAttribute("data-theme", savedTheme)
+
+ if (savedTheme === "system") {
+ themeToggle.innerHTML = ''
+ applySystemTheme()
+ } else if (savedTheme === "dark") {
+ themeToggle.innerHTML = ''
+ document.body.classList.add("dark-mode")
+ } else {
+ themeToggle.innerHTML = ''
+ document.body.classList.remove("dark-mode")
+ }
+
+ setupSystemThemeListener()
+
+ // Initialize end date checkbox state
+ toggleEndDate()
+ })
+
+
+
+
+