{"id":817,"date":"2023-08-06T04:22:00","date_gmt":"2023-08-05T20:22:00","guid":{"rendered":"https:\/\/blog.guguan.us.kg\/?p=817"},"modified":"2025-07-10T02:27:00","modified_gmt":"2025-07-09T18:27:00","slug":"2024%e9%ab%98%e8%80%83%e5%80%92%e8%ae%a1%e6%97%b6","status":"publish","type":"post","link":"https:\/\/blog.guguan.us.kg\/?p=817","title":{"rendered":"2024\u9ad8\u8003\u5012\u8ba1\u65f6"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">\u8ddd\u79bb\u9ad8\u8003\u8fd8\u6709\uff1a<\/h4>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color has-link-color wp-elements-b7a14d5f2b9968847ee6dda5b1e8f95c wp-block-paragraph\" id=\"countdown\">\u8b66\u544a\uff1a\u5012\u8ba1\u65f6\u65e0\u6cd5\u5728\u8f83\u65e7\u6216\u8005\u4e0d\u652f\u6301 JavaScript \u7684\u6d4f\u89c8\u5668\u4e0b\u8fd0\u884c<\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">\u543e\u5c1d\u7ec8\u65e5\u800c\u601d\u77e3\uff0c\u4e0d\u5982\u987b\u81fe\u4e4b\u6240\u5b66\u4e5f\u3002\u543e\u5c1d\u8dc2\u800c\u671b\u77e3\uff0c\u4e0d\u5982\u767b\u9ad8\u4e4b\u535a\u89c1\u4e5f\u3002\u2014\u2014\u300a\u529d\u5b66\u300b<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">\u8054\u7cfb\u65b9\u5f0f\uff1a<a href=\"https:\/\/blog.guguan.us.kg\/?p=188\" data-type=\"post\" data-id=\"188\">\u8054\u7cfb\u6211<\/a><\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">\u00a9 2023 Not right reserved. \u81ea\u8c6a\u5730\u4e0d\u7531<a href=\"https:\/\/netlify.com\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Netlify<\/a>\u5f3a\u529b\u9a71\u52a8.<\/p>\n\n\n\n<script>\n\tconst examDate = new Date(\"2024-06-07 09:00\");\n\tconst examTime = examDate.getTime();\n\tconst threshold = 30 * 1000; \/\/ 30\u79d2\n\tconst apiConfigs = [\n\t\t{\n\t\t\turl: \"https:\/\/worldtimeapi.org\/api\/timezone\/Asia\/Shanghai\",\n\t\t\ttype: \"json\",\n\t\t\tparse: data => new Date(data.datetime).getTime()\n\t\t},\n\t\t{\n\t\t\turl: \"https:\/\/f.m.suning.com\/api\/ct.do\",\n\t\t\ttype: \"json\",\n\t\t\tparse: data => new Date(data.currentTime).getTime()\n\t\t},\n\t\t{\n\t\t\turl: \"https:\/\/cloudflare.com\/cdn-cgi\/trace\",\n\t\t\ttype: \"ini\",\n\t\t\tparse: text => {\n\t\t\t\t\/\/ \u89e3\u6790INI\u683c\u5f0f\uff0c\u63d0\u53d6ts\u5b57\u6bb5\n\t\t\t\tconst match = text.match(\/^ts=(\\d+(\\.\\d+)?)\/m);\n\t\t\t\treturn match ? Number(match[1]) * 1000 : null;\n\t\t\t}\n\t\t}\n\t];\n\tconst countdownEl = document.getElementById(\"countdown\");\n\tconst countdownTextEl = document.getElementById(\"countdownText\");\n\n\tlet useOnlineTime = false;\n\tlet onlineTime = null;\n\tlet tickCount = 0;\n\n\tasync function fetchOnlineTime() {\n\t\tconst fetches = apiConfigs.map(cfg =>\n\t\t\tfetch(cfg.url)\n\t\t\t\t.then(res => cfg.type === \"json\" ? res.json() : res.text())\n\t\t\t\t.then(data => cfg.parse(data))\n\t\t\t\t.catch(() => null)\n\t\t);\n\t\tconst results = await Promise.all(fetches);\n\t\treturn results.find(ts => typeof ts === \"number\" && !isNaN(ts)) || null;\n\t}\n\n\tasync function calibrateTime() {\n\t\tconst online = await fetchOnlineTime();\n\t\tconsole.log(\"Online time: \" + online)\n\t\tif (online) {\n\t\t\tconst local = Date.now();\n\t\t\tuseOnlineTime = Math.abs(online - local) > threshold;\n\t\t\tonlineTime = online;\n\t\t} else {\n\t\t\tuseOnlineTime = false;\n\t\t\tonlineTime = null;\n\t\t}\n\t}\n\n\tfunction getNow() {\n\t\tif (useOnlineTime && onlineTime !== null) {\n\t\t\tonlineTime += 1000;\n\t\t\treturn onlineTime;\n\t\t}\n\t\treturn Date.now();\n\t}\n\n\tfunction formatCountdown(diff) {\n\t\tif (diff <= 0) return \"\u5012\u8ba1\u65f6\u7ed3\u675f\";\n\t\tconst days = Math.floor(diff \/ 86400);\n\t\tconst hours = Math.floor((diff % 86400) \/ 3600);\n\t\tconst minutes = Math.floor((diff % 3600) \/ 60);\n\t\tconst seconds = Math.floor(diff % 60);\n\t\treturn `${days}\u5929${hours}\u5c0f\u65f6${minutes}\u5206\u949f${seconds}\u79d2`;\n\t}\n\n\tasync function startCountdown() {\n\t\tawait calibrateTime();\n\t\tsetInterval(async () => {\n\t\t\ttickCount++;\n\t\t\tif (tickCount % 30 === 0) await calibrateTime();\n\t\t\tconst now = getNow();\n\t\t\tconst diff = Math.floor((examTime - now) \/ 1000);\n\t\t\tconst text = formatCountdown(diff);\n\t\t\tcountdownEl.textContent = text;\n\t\t}, 1000);\n\t}\n\n\tstartCountdown();\n<\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8ddd\u79bb\u9ad8\u8003\u8fd8\u6709\uff1a \u8b66\u544a\uff1a\u5012\u8ba1\u65f6\u65e0\u6cd5\u5728\u8f83\u65e7\u6216\u8005\u4e0d\u652f\u6301 JavaScript \u7684\u6d4f\u89c8\u5668\u4e0b\u8fd0\u884c \u543e\u5c1d\u7ec8\u65e5\u800c\u601d\u77e3\uff0c\u4e0d\u5982\u987b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-817","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=817"}],"version-history":[{"count":7,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/817\/revisions"}],"predecessor-version":[{"id":839,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/817\/revisions\/839"}],"wp:attachment":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}