diff --git a/README.md b/README.md index 6772421..bc23cc4 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ [简体中文](README_zh.md) -OI Contest Schedule is a lightweight WordPress plugin that displays upcoming competitive programming contests in the WordPress dashboard or on any post or page. +OI Contest Schedule is a lightweight WordPress plugin that displays currently running and upcoming competitive programming contests in the WordPress dashboard or on any post or page. Contests that have ended are not displayed. -Contest data is provided by [OI-contest-fetch](https://github.com/hanyixuanten/OI-contest-fetch) and displayed in each visitor's device time zone. +Contest data is provided by [OI-contest-fetch](https://github.com/hanyixuanten/OI-contest-fetch) and displayed in each visitor's client device time zone, not the time zone configured in WordPress. The schedule identifies the client time zone by its IANA name, such as `Asia/Shanghai`. ## Features diff --git a/README_zh.md b/README_zh.md index 7ab5f42..126e701 100644 --- a/README_zh.md +++ b/README_zh.md @@ -2,9 +2,9 @@ [English](README.md) -OI Contest Schedule 是一款轻量级 WordPress 插件,可在 WordPress 仪表盘、文章或页面中展示即将开始的程序设计竞赛。 +OI Contest Schedule 是一款轻量级 WordPress 插件,可在 WordPress 仪表盘、文章或页面中展示正在进行和即将开始的程序设计竞赛,不显示已结束的赛事。 -比赛数据由 [OI-contest-fetch](https://github.com/hanyixuanten/OI-contest-fetch) 提供,时间会根据访客设备的时区显示。 +比赛数据由 [OI-contest-fetch](https://github.com/hanyixuanten/OI-contest-fetch) 提供,时间会根据访客客户端设备的时区显示,而非 WordPress 中设置的站点时区。日程中会标明客户端时区的 IANA 名称,例如 `Asia/Shanghai`。 ## 功能特性 diff --git a/assets/js/schedule.js b/assets/js/schedule.js index 9ae9e69..f0fdbf4 100644 --- a/assets/js/schedule.js +++ b/assets/js/schedule.js @@ -29,6 +29,13 @@ } ); } + function updateTimeZones() { + var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC'; + document.querySelectorAll( '[data-oics-time-zone]' ).forEach( function ( element ) { + element.textContent = timeZone; + } ); + } + function countdownText( startTimestamp, endTimestamp ) { var now = Date.now(); if ( endTimestamp * 1000 <= now ) { @@ -57,8 +64,25 @@ function initialize() { updateTimes(); + updateTimeZones(); updateCountdowns(); window.setInterval( updateCountdowns, 1000 ); + + if ( 'MutationObserver' in window ) { + new MutationObserver( function ( mutations ) { + var hasAddedElements = mutations.some( function ( mutation ) { + return Array.prototype.some.call( mutation.addedNodes, function ( node ) { + return 1 === node.nodeType; + } ); + } ); + + if ( hasAddedElements ) { + updateTimes(); + updateTimeZones(); + updateCountdowns(); + } + } ).observe( document.body, { childList: true, subtree: true } ); + } } if ( 'loading' === document.readyState ) { diff --git a/includes/class-plugin.php b/includes/class-plugin.php index a2595e3..8ea9ecd 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -29,7 +29,7 @@ final class OICS_Plugin { wp_register_script( 'oics-schedule-editor', OICS_URL . 'assets/js/schedule-editor.js', - array( 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-server-side-render' ), + array( 'oics-schedule', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-server-side-render' ), OICS_VERSION, true ); @@ -68,8 +68,11 @@ final class OICS_Plugin { } private function register_assets() { - wp_register_style( 'oics-schedule', OICS_URL . 'assets/css/schedule.css', array(), OICS_VERSION ); - wp_register_script( 'oics-schedule', OICS_URL . 'assets/js/schedule.js', array(), OICS_VERSION, true ); + $style_version = OICS_VERSION . '.' . filemtime( OICS_PATH . 'assets/css/schedule.css' ); + $script_version = OICS_VERSION . '.' . filemtime( OICS_PATH . 'assets/js/schedule.js' ); + + wp_register_style( 'oics-schedule', OICS_URL . 'assets/css/schedule.css', array(), $style_version ); + wp_register_script( 'oics-schedule', OICS_URL . 'assets/js/schedule.js', array(), $script_version, true ); wp_localize_script( 'oics-schedule', 'oicsScheduleL10n', diff --git a/includes/class-schedule-renderer.php b/includes/class-schedule-renderer.php index c21110e..b32f30f 100644 --- a/includes/class-schedule-renderer.php +++ b/includes/class-schedule-renderer.php @@ -32,7 +32,8 @@ final class OICS_Schedule_Renderer {

- + : + UTC

diff --git a/languages/oi-contest-schedule-zh_CN.po b/languages/oi-contest-schedule-zh_CN.po index 6234116..57abba5 100644 --- a/languages/oi-contest-schedule-zh_CN.po +++ b/languages/oi-contest-schedule-zh_CN.po @@ -64,8 +64,8 @@ msgstr "暂时无法加载赛事数据,请稍后再试。" msgid "No upcoming contests." msgstr "暂无即将开始的赛事。" -msgid "Times use your device time zone." -msgstr "时间按设备时区显示。" +msgid "Device time zone" +msgstr "设备时区" msgid "%d contest" msgid_plural "%d contests" diff --git a/languages/oi-contest-schedule.pot b/languages/oi-contest-schedule.pot index c088a1c..729be67 100644 --- a/languages/oi-contest-schedule.pot +++ b/languages/oi-contest-schedule.pot @@ -59,7 +59,7 @@ msgstr "" msgid "No upcoming contests." msgstr "" -msgid "Times use your device time zone." +msgid "Device time zone" msgstr "" msgid "%d contest" diff --git a/readme.txt b/readme.txt index ab5169c..2e071f1 100644 --- a/readme.txt +++ b/readme.txt @@ -8,11 +8,11 @@ Stable tag: 0.1.0 License: GPL-3.0-only License URI: https://www.gnu.org/licenses/gpl-3.0.html -Display upcoming OI and competitive programming contests in the WordPress dashboard or with an editor block. +Display currently running and upcoming OI contests in the WordPress dashboard or with an editor block. == Description == -OI Contest Schedule displays upcoming competitive programming contests with local times and live countdowns. +OI Contest Schedule displays currently running and upcoming competitive programming contests with local times and live countdowns. Contests that have ended are not displayed. The plugin adds an **Upcoming OI Contests** widget to the WordPress dashboard. To display the schedule on the front end, add the **OI Contest Schedule** block to a post or page. @@ -20,7 +20,7 @@ Features include: * Upcoming and currently running contests ordered by start time. * Contest platform, title, start time, end time, and live countdown. -* Dates formatted in each visitor's device time zone. +* Dates formatted in each visitor's client device time zone, rather than the time zone configured in WordPress, and identified by its IANA name (for example, `Asia/Shanghai`). * Responsive and compact layouts. * A five-minute cache using the WordPress Transients API. * English and Simplified Chinese translations. @@ -58,7 +58,7 @@ The plugin shows contests whose end time is still in the future, including conte = Which time zone is used? = -Dates are formatted in the visitor's device time zone using the browser's internationalization API. +Dates are formatted in the visitor's client device time zone using the browser's internationalization API. The time zone configured in the WordPress site settings is not used. = How often is the contest data refreshed? =