From 7c55ed072782d5d6cea06d6ea37d691ea1bb35ca Mon Sep 17 00:00:00 2001 From: Wiz <127123086+WizisCool@users.noreply.github.com> Date: Thu, 25 Apr 2024 23:04:11 +0800 Subject: [PATCH] Init Init --- favicon.png | Bin 0 -> 1792 bytes index.html | 126 ++++++++++++++++++++++++++++++++++++++++++ script.js | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++ styles.css | 21 +++++++ 4 files changed, 303 insertions(+) create mode 100644 favicon.png create mode 100644 index.html create mode 100644 script.js create mode 100644 styles.css diff --git a/favicon.png b/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..a78b7fe9432e01118d5bfa227348a30750cb5518 GIT binary patch literal 1792 zcmZ{kX*An;7sr2Mi>+dtR1K2nL6t%5m9eH#R4t9vGF598C1_Cp2+5WNw+7p}rplAR9Q32RHvY-zDe2)QO)eit{5dg@jyKNWDj}9UM zj&^v!|56p~2YE-1DA~cuR`i3AoG4br{u(d^KzP;xZ$tEawpMUC+}lo}htDr&?Q$vX z_UUowfVVn1XWkqAZemo4PSmVP5ND!n@yDdCc?EkAann@|Q3V%}hNIDR#I;ckS*c8T z%}}ijvCC1&xXKAHe#*UL;zfBQJ8Zp&9eeedv`_F_^`?e7dU(sk!!S5$_kh0~0=3NZ zEyg3BeO9$f)vRrj-SsoPl{vlR*P_2-VH2AHJJ5hmYQBRC{kQ+-GoQn1*?t_FqON!}vCs;0N$zFIh+xoWHy)^gOa#zCb zXLB=CSnI`J-BH8chxPrcmNi-SMZkzT*^aAx+q&KsgzL4nApB7 z8J;xwO3Nguw-R~X#Lbi3?ZS>5z|ZODTa^wo{;z&F9%=a65 z4y^R1mlJmAm^kL5$UePs;nE6nLhy7LI`ko05)GIHXe7kT>igk#PDW=liZ;k#*0BCg z_EzEjwV>OdER&LNX4Y7`{5pApd20doWc(4Xv*1eMjza#jkFRQ1`|;P^@|iyFGOhJ% z)lYPPyj8j1zhy9Tm=!pUw=2HT^_;`-{%%$9Q}L33@Hl!R8oq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 + +
+
+ +
+ + + +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..451f8a5 --- /dev/null +++ b/script.js @@ -0,0 +1,156 @@ +$(document).ready(function () { + // 获取所有时区 + const allTimezones = moment.tz.names(); + + // 按 UTC 偏移量排序时区 + allTimezones.sort((a, b) => { + const offsetA = moment.tz(a).utcOffset(); + const offsetB = moment.tz(b).utcOffset(); + return offsetA - offsetB; + }); + + // 生成时区选项 + const timezoneOptions = allTimezones.map(timezone => { + const offset = moment.tz(timezone).format('Z'); + return ``; + }).join(''); + + + $('#cycleStartTimezone').html(timezoneOptions); + + // 设置默认时区为 UTC+8 上海时间 + $('#cycleStartTimezone').val('Asia/Shanghai'); + + // 初始化日期选择器 + const datePickr = flatpickr('#cycleStartDate', { + defaultDate: moment().startOf('month').toDate(), + dateFormat: 'Y-m-d', + onChange: updateCycleStart + }); + + // 初始化时间选择器 + const timePickr = flatpickr('#cycleStartTime', { + noCalendar: true, + enableTime: true, + dateFormat: 'H:i', + time_24hr: true, + defaultDate: '00:00', + onChange: updateCycleStart + }); + + // 页面加载时生成初始的 RFC3339 和 规则 + updateCycleStart(); + generateRule(); + + // 更新统计周期开始时间 + function updateCycleStart() { + const timezone = $('#cycleStartTimezone').val(); + const date = $('#cycleStartDate').val(); + const time = $('#cycleStartTime').val(); + const formattedDate = moment.tz(`${date} ${time}`, timezone).format(); + $('#cycleStart').val(formattedDate); + generateRule(); + } + + // 防止用户编辑 RFC3339 格式时间 + $('#cycleStart').on('input', function () { + showErrorModal('请使用上方的时间选择器选择时间'); + $(this).val(moment.tz($('#cycleStartDate').val() + ' ' + $('#cycleStartTime').val(), $('#cycleStartTimezone').val()).format()); + }); + + // 生成规则按钮 + $('#generateRuleBtn').click(generateRule); + + // 生成规则 + function generateRule() { + const serverIds = $('#serverIds').val().split(',').map(id => id.trim()); + const cycleStart = $('#cycleStart').val(); + const trafficType = $('#trafficType').val(); + const cycleUnit = $('#cycleUnit').val(); + const cycleInterval = parseInt($('#cycleInterval').val()); + const maxTraffic = $('#maxTraffic').val() * $('#trafficUnit').val(); + + if (!validateInput(serverIds, cycleStart, trafficType, cycleUnit, cycleInterval, maxTraffic)) { + return; + } + + const rule = [{ + type: trafficType, + max: maxTraffic, + cycle_start: cycleStart, + cycle_interval: cycleInterval, + cycle_unit: cycleUnit, + cover: 1, + ignore: serverIds.reduce((obj, id) => { + obj[id] = true; + return obj; + }, {}) + }]; + + const ruleJson = JSON.stringify(rule, null, 2); + $('#ruleOutput').text(ruleJson); + hljs.highlightBlock(document.getElementById('ruleOutput')); + } + + // 复制规则按钮 + $('#copyRuleBtn').click(function () { + const ruleOutput = document.getElementById('ruleOutput'); + const range = document.createRange(); + range.selectNode(ruleOutput); + window.getSelection().removeAllRanges(); + window.getSelection().addRange(range); + document.execCommand('copy'); + window.getSelection().removeAllRanges(); + showSuccessModal('JSON 规则已复制到剪贴板'); + }); + + // 输入验证 + function validateInput(serverIds, cycleStart, trafficType, cycleUnit, cycleInterval, maxTraffic) { + if (serverIds.length === 0 || (serverIds.length === 1 && serverIds[0] === '')) { + showErrorModal('请输入服务器 ID'); + return false; + } + + if (!cycleStart) { + showErrorModal('请选择统计周期开始时间'); + return false; + } + + if (!trafficType) { + showErrorModal('请选择流量类型'); + return false; + } + + if (!cycleUnit) { + showErrorModal('请选择周期单位'); + return false; + } + + if (isNaN(cycleInterval) || cycleInterval <= 0) { + showErrorModal('请输入有效的周期间隔 (大于 0 的数字)'); + return false; + } + + if (isNaN(maxTraffic) || maxTraffic <= 0) { + showErrorModal('请输入有效的流量上限 (大于 0 的数字)'); + return false; + } + + return true; + } + + // 时区选择器变更事件 + $('#cycleStartTimezone').change(updateCycleStart); + + + function showErrorModal(message) { + $('#errorMessage').text(message); + $('#errorModal').modal('show'); + } + + + function showSuccessModal(message) { + $('#errorMessage').text(message); + $('#errorModal').modal('show'); + } +}); \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..6f5eab4 --- /dev/null +++ b/styles.css @@ -0,0 +1,21 @@ +body { + background-color: #f8f9fa; +} + +.container { + max-width: 800px; +} + +.form-group label { + font-weight: bold; +} + +#ruleOutput { + font-family: 'Courier New', Courier, monospace; + white-space: pre-wrap; + word-break: break-all; +} + +.rule-output { + min-height: 200px; +} \ No newline at end of file