2026-11-20 14:46:07 +08:00
<!doctype html>
< html lang = "zh-Hant" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
2026-11-20 15:45:56 +08:00
< title > 滑鼠立體時鐘 線上編輯器</ title >
< link rel = "icon" href = "data:," >
< meta name = "description" content = "調整顏色、大小、位置與速度,即時預覽會跟著滑鼠跑的立體時鐘,複製程式碼貼到自己的網站。" >
2026-11-20 14:46:07 +08:00
< style >
2026-11-20 15:45:56 +08:00
: root {
color-scheme : light dark ;
--bg : #f6f5f1 ; --panel : #ffffff ; --text : #222 ; --muted : #666 ; --line : #dcd8cf ;
2026-11-20 17:05:20 +08:00
--accent : #9b452e ; --accent-text : #fff ; --code : #f1efe9 ; --focus : #2f6fd6 ; --ok : #2e7d4a ; --hint : #c4c4c4 ;
2026-11-20 15:45:56 +08:00
}
@ media ( prefers-color-scheme : dark ) {
: root : not ([ data-bg = "light" ]) {
--bg : #17181b ; --panel : #222327 ; --text : #e9e7e2 ; --muted : #a5a29b ; --line : #3a3b40 ;
2026-11-20 17:05:20 +08:00
--accent : #e08a6c ; --accent-text : #1a1a1a ; --code : #2b2c31 ; --focus : #7fb0ff ; --ok : #7ccf97 ; --hint : #4a4b51 ;
2026-11-20 15:45:56 +08:00
}
}
: root [ data-bg = "dark" ] {
--bg : #17181b ; --panel : #222327 ; --text : #e9e7e2 ; --muted : #a5a29b ; --line : #3a3b40 ;
2026-11-20 17:05:20 +08:00
--accent : #e08a6c ; --accent-text : #1a1a1a ; --code : #2b2c31 ; --focus : #7fb0ff ; --ok : #7ccf97 ; --hint : #4a4b51 ;
2026-11-20 15:45:56 +08:00
color-scheme : dark ;
}
: root [ data-bg = "light" ] { color-scheme : light ; }
* { box-sizing : border-box ; }
html , body { margin : 0 ; }
body { font-family : system-ui , "Noto Sans TC" , "PingFang TC" , "Microsoft JhengHei" , sans-serif ; background : var ( -- bg ); color : var ( -- text ); line-height : 1.6 ; overflow-x : hidden ; }
a { color : var ( -- accent ); }
: focus-visible { outline : 2 px solid var ( -- focus ); outline-offset : 2 px ; }
header { padding : 20 px 16 px 4 px ; max-width : 1200 px ; margin : 0 auto ; }
h1 { margin : 0 ; font-size : 1.6 rem ; }
header p { margin : 4 px 0 0 ; color : var ( -- muted ); }
2026-11-20 16:13:26 +08:00
. layout { display : grid ; grid-template-columns : minmax ( 0 , 380 px ) minmax ( 0 , 1 fr ); gap : 0 20 px ; max-width : 1200 px ; margin : 0 auto ; padding : 16 px ; align-items : start ; }
2026-11-20 15:45:56 +08:00
. panel { background : var ( -- panel ); border : 1 px solid var ( -- line ); border-radius : 12 px ; padding : 4 px 16 px 16 px ; position : sticky ; top : 12 px ; max-height : calc ( 100 vh - 24 px ); overflow : auto ; }
. panel > summary { list-style : none ; cursor : pointer ; font-weight : 700 ; padding : 12 px 0 8 px ; display : flex ; justify-content : space-between ; align-items : center ; }
. panel > summary :: -webkit-details-marker { display : none ; }
. panel > summary . hint { font-weight : 400 ; color : var ( -- muted ); font-size : .85 rem ; }
fieldset { border : 0 ; border-top : 1 px solid var ( -- line ); margin : 0 ; padding : 10 px 0 6 px ; min-width : 0 ; }
legend { font-weight : 700 ; padding : 0 6 px 0 0 ; font-size : .95 rem ; }
. row { display : grid ; grid-template-columns : 7.5 em minmax ( 0 , 1 fr ) 5.2 em ; gap : 8 px ; align-items : center ; margin : 6 px 0 ; }
. row label { font-size : .9 rem ; }
. row . color { grid-template-columns : 7.5 em 44 px minmax ( 0 , 1 fr ); }
. row . select { grid-template-columns : 7.5 em minmax ( 0 , 1 fr ); }
input , select , button , textarea { font : inherit ; color : inherit ; }
input [ type = "number" ], input [ type = "text" ], select { width : 100 % ; min-width : 0 ; padding : 4 px 6 px ; border : 1 px solid var ( -- line ); border-radius : 6 px ; background : var ( -- bg ); }
input [ type = "range" ] { width : 100 % ; min-width : 0 ; accent-color : var ( -- accent ); }
input [ type = "color" ] { width : 44 px ; height : 32 px ; padding : 2 px ; border : 1 px solid var ( -- line ); border-radius : 6 px ; background : var ( -- bg ); cursor : pointer ; }
input [ aria-invalid = "true" ] { border-color : #d33 ; }
. presets { display : flex ; flex-wrap : wrap ; gap : 6 px ; margin : 6 px 0 ; }
button { cursor : pointer ; border : 1 px solid var ( -- line ); background : var ( -- bg ); border-radius : 8 px ; padding : 6 px 12 px ; }
button : hover { border-color : var ( -- accent ); }
button . primary { background : var ( -- accent ); color : var ( -- accent - text ); border-color : var ( -- accent ); font-weight : 700 ; }
. swatch { display : inline-flex ; gap : 2 px ; margin-right : 6 px ; vertical-align : -2 px ; }
. swatch i { width : 9 px ; height : 12 px ; border-radius : 2 px ; display : inline-block ; box-shadow : inset 0 0 0 1 px rgba ( 128 , 128 , 128 , .45 ); }
. note { font-size : .85 rem ; color : var ( -- muted ); margin : 6 px 0 ; }
. warn { font-size : .85 rem ; color : var ( -- accent ); margin : 6 px 0 ; }
main { min-width : 0 ; }
2026-11-20 16:13:26 +08:00
. play-card { grid-column : 2 ; grid-row : 1 ; min-width : 0 ; }
. panel { grid-column : 1 ; grid-row : 1 / span 2 ; }
main { grid-column : 2 ; grid-row : 2 ; }
2026-11-20 15:45:56 +08:00
. card { background : var ( -- panel ); border : 1 px solid var ( -- line ); border-radius : 12 px ; padding : 16 px ; margin-bottom : 20 px ; }
. card h2 { margin : 0 0 8 px ; font-size : 1.15 rem ; }
2026-11-20 15:56:19 +08:00
. play { min-height : 320 px ; position : relative ; touch-action : pan-y ; display : grid ; place-items : center ; text-align : center ; border : 2 px dashed var ( -- line ); border-radius : 12 px ; color : var ( -- muted ); padding : 20 px ; }
2026-11-20 17:05:20 +08:00
. play { -webkit- user-select : none ; user-select : none ; }
/* 說明只是背景提示:很淡、在時鐘下層、不擋操作、不會被反白 */
. play-hint { position : relative ; z-index : 0 ; color : var ( -- hint ); font-size : .85 rem ; pointer-events : none ; transition : opacity .3 s ; }
. play-hint strong { color : inherit ; font-size : 1 rem ; font-weight : 600 ; display : block ; }
. play . is-moving . play-hint { opacity : .45 ; }
2026-11-20 15:45:56 +08:00
. bgswitch { display : flex ; gap : 14 px ; flex-wrap : wrap ; margin-top : 10 px ; font-size : .9 rem ; }
. tabs { display : flex ; gap : 6 px ; flex-wrap : wrap ; margin : 4 px 0 10 px ; }
. tabs [ role = "tab" ][ aria-selected = "true" ] { background : var ( -- accent ); color : var ( -- accent - text ); border-color : var ( -- accent ); font-weight : 700 ; }
textarea { width : 100 % ; min-height : 150 px ; resize : vertical ; font-family : ui-monospace , Consolas , "Cascadia Mono" , monospace ; font-size : .82 rem ; line-height : 1.5 ; background : var ( -- code ); border : 1 px solid var ( -- line ); border-radius : 8 px ; padding : 10 px ; white-space : pre ; overflow : auto ; }
. actions { display : flex ; flex-wrap : wrap ; gap : 8 px ; margin-top : 10 px ; align-items : center ; }
. status { color : var ( -- ok ); font-size : .9 rem ; min-height : 1.4 em ; }
. card ol { padding-left : 1.4 em ; margin : 6 px 0 ; }
code { background : var ( -- code ); padding : 1 px 5 px ; border-radius : 4 px ; font-size : .9 em ; }
footer { max-width : 1200 px ; margin : 0 auto ; padding : 0 16 px 40 px ; color : var ( -- muted ); font-size : .85 rem ; }
@ media ( max-width : 760px ) {
2026-11-20 16:13:26 +08:00
/* 聚焦設定欄位時不要被吸附的試玩區蓋住(只套在面板與輸出區,試玩區本身不受影響) */
. panel : is ( input , select , summary , button ), main : is ( input , textarea , button , a ) { scroll-margin-top : calc ( min ( 36 vh , 300 px ) + 72 px ); scroll-margin-top : calc ( min ( 36 svh , 300 px ) + 72 px ); }
. layout { grid-template-columns : minmax ( 0 , 1 fr ); padding : 0 16 px 12 px ; }
. play-card , . panel , main { grid-column : 1 ; grid-row : auto ; }
. panel { position : static ; max-height : none ; margin-bottom : 20 px ; }
/* 單欄時試玩區吸附在畫面上方,往下調設定時一直看得到 */
. play-card { position : sticky ; top : 0 ; z-index : 20 ; margin : 0 -16 px 16 px ; padding : 8 px 16 px 6 px ; border : 0 ; border-radius : 0 ; border-bottom : 1 px solid var ( -- line ); box-shadow : 0 6 px 14 px -8 px rgba ( 0 , 0 , 0 , .35 ); }
. play-card h2 { position : absolute ; width : 1 px ; height : 1 px ; overflow : hidden ; clip : rect ( 0 0 0 0 ); white-space : nowrap ; }
2026-11-20 17:05:20 +08:00
. play { min-height : 0 ; height : min ( 36 vh , 300 px ); height : min ( 36 svh , 300 px ); padding : 8 px ; line-height : 1.5 ; }
. play-hint { font-size : .78 rem ; }
. play-hint strong { font-size : .9 rem ; }
2026-11-20 16:13:26 +08:00
. play . more { display : none ; }
. bgswitch { margin-top : 10 px ; gap : 10 px ; font-size : .8 rem ; }
. bgswitch input { margin : 0 2 px 0 0 ; vertical-align : -2 px ; }
}
@ media ( max-width : 760px ) and ( max-height : 560px ) {
. play { height : 200 px ; }
2026-11-20 15:45:56 +08:00
}
2026-11-20 14:46:07 +08:00
</ style >
</ head >
< body >
2026-11-20 15:45:56 +08:00
< header >
< h1 > 滑鼠立體時鐘 線上編輯器</ h1 >
< p > 調整設定,時鐘會馬上照新的樣子跟著你跑。滿意後複製程式碼,貼到自己的網站。</ p >
</ header >
2026-11-20 14:46:07 +08:00
2026-11-20 15:45:56 +08:00
< div class = "layout" >
2026-11-20 16:13:26 +08:00
< section class = "card play-card" id = "playCard" aria-labelledby = "playTitle" >
< h2 id = "playTitle" > 試玩區</ h2 >
< div class = "play" id = "play" >
2026-11-20 17:05:20 +08:00
< div class = "play-hint" >
2026-11-20 16:13:26 +08:00
< strong > 移動滑鼠,或用手指在畫面上滑動</ strong >
時鐘會跟著你。電腦在游標右下方,手機在手指上方。< br >
< span class = "more" > 這裡的時鐘只在框內預覽;放到你的網站上會跟著整個頁面移動。</ span >
</ div >
</ div >
< div class = "bgswitch" role = "radiogroup" aria-label = "預覽底色" >
< span > 預覽底色:</ span >
< label >< input type = "radio" name = "bg" value = "auto" checked > 跟隨系統</ label >
< label >< input type = "radio" name = "bg" value = "light" > 淺色網站</ label >
< label >< input type = "radio" name = "bg" value = "dark" > 深色網站</ label >
</ div >
</ section >
2026-11-20 15:45:56 +08:00
< details class = "panel" id = "panel" open >
< summary > 設定 < span class = "hint" id = "panelHint" > 點這裡收合</ span ></ summary >
< fieldset >
< legend > 預設配色</ legend >
< div class = "presets" id = "presets" ></ div >
< button type = "button" id = "reset" > 重設為預設</ button >
</ fieldset >
< fieldset >
< legend > 顏色</ legend >
< div id = "colors" ></ div >
</ fieldset >
2026-11-20 17:47:00 +08:00
< fieldset >
< legend > 外光暈</ legend >
< div class = "row color" >
< label for = "f-glowColor" > 光暈顏色</ label >
< input type = "color" id = "f-glowColor-pick" aria-label = "光暈顏色取色器" data-key = "glowColor" >
< input type = "text" id = "f-glowColor" data-key = "glowColor" maxlength = "7" spellcheck = "false" autocomplete = "off" placeholder = "空白=不加" >
</ div >
< div id = "numbersGlow" ></ div >
< p class = "note" > 範圍設 0 或顏色留空就不加光暈。深色網站搭配亮色光暈最明顯。</ p >
</ fieldset >
< fieldset >
< legend > 字大小</ legend >
< div id = "numbersFont" ></ div >
</ fieldset >
2026-11-20 15:45:56 +08:00
< fieldset >
< legend > 大小與速度</ legend >
< div id = "numbersMain" ></ div >
</ fieldset >
< fieldset >
< legend > 位置(電腦,相對滑鼠)</ legend >
< div id = "numbersMouse" ></ div >
</ fieldset >
< fieldset >
< legend > 位置(手機,相對手指)</ legend >
< div id = "numbersTouch" ></ div >
< p class = "note" > 負數的垂直位置=在手指上方,避免被手掌擋住。</ p >
</ fieldset >
< fieldset >
< legend > 其他</ legend >
< div class = "row select" >
< label for = "f-lang" > 日期語言</ label >
< select id = "f-lang" data-key = "lang" >
< option value = "zh-TW" > 中文(2026年 十一月 20日 星期五)</ option >
< option value = "en" > 英文(FRIDAY 20 NOVEMBER 2026) </ option >
</ select >
</ div >
< div class = "row select" >
< label for = "f-reducedMotion" > 減少動態時</ label >
< select id = "f-reducedMotion" data-key = "reducedMotion" >
< option value = "hide" > 不顯示(建議)</ option >
< option value = "show" > 照常顯示</ option >
</ select >
</ div >
< div class = "row select" >
< label for = "f-zIndex" > 疊放順序</ label >
< input type = "number" id = "f-zIndex" data-key = "zIndex" min = "0" max = "2147483647" step = "1" inputmode = "numeric" >
</ div >
< p class = "note" > 疊放順序:時鐘被網站選單蓋住時調大。</ p >
< p class = "warn" id = "rmNote" hidden > 你的系統開了「減少動態」。這頁仍會顯示時鐘讓你預覽,但用「不顯示」設定時,在你的網站上不會出現。</ p >
</ fieldset >
</ details >
< main >
< section class = "card" aria-labelledby = "outTitle" >
< h2 id = "outTitle" > 取得程式碼</ h2 >
< div class = "tabs" role = "tablist" aria-label = "程式碼形式" >
< button type = "button" role = "tab" id = "tab-tag" aria-controls = "outPanel" aria-selected = "true" > 一行引用(要上傳檔案)</ button >
< button type = "button" role = "tab" id = "tab-inline" aria-controls = "outPanel" aria-selected = "false" tabindex = "-1" > 完整內嵌(直接貼上)</ button >
</ div >
< div id = "outPanel" role = "tabpanel" aria-labelledby = "tab-tag" >
< p class = "note" id = "outNote" ></ p >
< label for = "code" class = "note" > 程式碼(已含你的設定)</ label >
< textarea id = "code" readonly spellcheck = "false" ></ textarea >
< div class = "actions" >
< button type = "button" class = "primary" id = "copy" > 複製程式碼</ button >
< button type = "button" id = "download" > 下載</ button >
< button type = "button" id = "downloadJs" hidden > 下載含設定的 .js</ button >
< button type = "button" id = "share" > 複製分享連結</ button >
< span class = "status" id = "status" role = "status" aria-live = "polite" ></ span >
</ div >
</ div >
</ section >
< section class = "card" aria-labelledby = "howTitle" >
< h2 id = "howTitle" > 怎麼放到網站上</ h2 >
< ol >
< li > 選上面的形式:能上傳檔案就用「一行引用」,先下載 < code > mouse-clock.js</ code > 上傳到網站,再把那一行的 < code > src</ code > 改成檔案位置;不能上傳就用「完整內嵌」。</ li >
< li > 把程式碼貼在網頁 < code > < /body> </ code > 前面(或文章最後的 HTML 區塊)。</ li >
< li > 重新整理網頁,移動滑鼠就會看到時鐘。</ li >
</ ol >
< p class = "note" > WordPress、Typecho、Blogger、Hugo/ Hexo 等平台的詳細放法,以及常見問題,請看 < a href = "https://code.tsdylab.com/tangsongdayo/mouse-clock" > Gitea 上的說明(README) </ a > 。Medium、方格子、Notion 這類不允許自訂 JavaScript 的平台無法使用。</ p >
</ section >
</ main >
</ div >
< footer >
原作:Silly Clock 3 by Kurt Grigg ・ 中文化:網頁建置百寶箱 ・ 改寫:< a href = "https://tsdylab.com/" > 唐宋打油</ a > ・
< a href = "https://code.tsdylab.com/tangsongdayo/mouse-clock" > 原始碼與授權</ a > ・ < span id = "ver" ></ span >
</ footer >
2026-11-20 17:47:00 +08:00
< script src = "mouse-clock.js?v=1.3.0" data-manual ></ script >
2026-11-20 15:45:56 +08:00
< script >
( function () {
'use strict' ;
var MC = window . MouseClock ;
var DEF = MC . defaults ;
var STORE = 'mouse-clock-editor' ;
var KEYS = Object . keys ( DEF );
var COLORS = [
[ 'dateColor' , '日期環' ], [ 'faceColor' , '鐘面數字' ], [ 'hourColor' , '時針' ], [ 'minuteColor' , '分針' ], [ 'secondColor' , '秒針' ]
];
var NUMS = {
numbersMain : [
[ 'size' , '大小(半徑)' , 10 , 150 , 1 , '' ],
[ 'speed' , '跟隨速度' , 0.05 , 1 , 0.05 , '' ],
[ 'dateSpeed' , '日期環轉速' , 0 , 0.1 , 0.005 , '' ]
],
2026-11-20 17:47:00 +08:00
numbersGlow : [
[ 'glowSize' , '光暈範圍(px) ' , 0 , 20 , 1 , '' ]
],
numbersFont : [
[ 'fontSize' , '數字與日期' , 6 , 30 , 1 , 'px' ],
[ 'handSize' , '指針' , 8 , 40 , 1 , 'px' ]
],
2026-11-20 15:45:56 +08:00
numbersMouse : [
[ 'offsetX' , '水平' , - 300 , 300 , 1 , 'px' ],
[ 'offsetY' , '垂直' , - 300 , 300 , 1 , 'px' ]
],
numbersTouch : [
[ 'touchOffsetX' , '水平' , - 300 , 300 , 1 , 'px' ],
[ 'touchOffsetY' , '垂直' , - 300 , 300 , 1 , 'px' ]
]
};
var PRESETS = [
[ '原版' , {}],
[ '柔和' , { dateColor : '#999999' , faceColor : '#555555' , hourColor : '#b5532f' , minuteColor : '#33568b' , secondColor : '#3f8f57' }],
[ '夜光(深色網站)' , { dateColor : '#8fa3b8' , faceColor : '#e8e4d8' , hourColor : '#ff8a65' , minuteColor : '#7fb0ff' , secondColor : '#9be38f' }],
[ '糖果' , { dateColor : '#c58bd9' , faceColor : '#ff7eb6' , hourColor : '#ff5c8a' , minuteColor : '#5cc8ff' , secondColor : '#ffc24b' }],
2026-11-20 17:47:00 +08:00
[ '墨色' , { dateColor : '#888888' , faceColor : '#333333' , hourColor : '#111111' , minuteColor : '#444444' , secondColor : '#9b452e' }],
[ '霓虹(深色網站)' , { dateColor : '#ff6ec7' , faceColor : '#e0fbff' , hourColor : '#ff3b6b' , minuteColor : '#39c6ff' , secondColor : '#b6ff3b' , glowColor : '#00e5ff' , glowSize : 6 }]
2026-11-20 15:45:56 +08:00
];
2026-11-20 17:47:00 +08:00
var NUM_KEYS = [ 'size' , 'offsetX' , 'offsetY' , 'touchOffsetX' , 'touchOffsetY' , 'speed' , 'dateSpeed' , 'zIndex' , 'fontSize' , 'handSize' , 'glowSize' ];
var LOOK_KEYS = COLORS . map ( function ( c ) { return c [ 0 ]; }). concat ([ 'glowColor' , 'glowSize' ]); // 預設配色會換掉的項目
2026-11-20 15:45:56 +08:00
var state = {};
var mode = 'tag' ;
var source = null ; // mouse-clock.js 原始碼(內嵌版用)
function $ ( id ) { return document . getElementById ( id ); }
function clone ( o ) { var r = {}; for ( var k in o ) r [ k ] = o [ k ]; return r ; }
function kebab ( k ) { return k . replace ( /[A-Z]/g , function ( c ) { return '-' + c . toLowerCase (); }); }
function normColor ( v ) {
v = String ( v || '' ). trim ();
if ( v . charAt ( 0 ) !== '#' ) v = '#' + v ;
if ( /^#[0-9a-f]{3}$/i . test ( v )) v = '#' + v [ 1 ] + v [ 1 ] + v [ 2 ] + v [ 2 ] + v [ 3 ] + v [ 3 ];
return /^#[0-9a-f]{6}$/i . test ( v ) ? v . toLowerCase () : null ;
}
function round ( n ) { return Math . round ( n * 10000 ) / 10000 ; }
// 把任意來源的設定整理成合法值
function sanitize ( input ) {
var o = clone ( DEF ), k , v ;
for ( k in input || {}) {
if ( ! ( k in DEF )) continue ;
v = input [ k ];
2026-11-20 17:47:00 +08:00
if ( k === 'glowColor' && String ( v ). trim () === '' ) o [ k ] = '' ;
else if ( /Color$/ . test ( k )) { v = normColor ( v ); if ( v ) o [ k ] = v ; }
2026-11-20 15:45:56 +08:00
else if ( NUM_KEYS . indexOf ( k ) >= 0 ) { v = Number ( v ); if ( isFinite ( v ) && String ( input [ k ]). trim () !== '' ) o [ k ] = k === 'zIndex' ? Math . max ( 0 , Math . min ( 2147483647 , Math . round ( v ))) : round ( v ); }
else if ( k === 'lang' ) { if ( v === 'en' || v === 'zh-TW' ) o [ k ] = v ; }
else if ( k === 'reducedMotion' ) { if ( v === 'hide' || v === 'show' ) o [ k ] = v ; }
}
return o ;
}
function diff ( o ) {
var d = {};
KEYS . forEach ( function ( k ) { if ( o [ k ] !== DEF [ k ]) d [ k ] = o [ k ]; });
return d ;
}
// ---- 建立表單 ----
COLORS . forEach ( function ( c ) {
var row = document . createElement ( 'div' );
row . className = 'row color' ;
row . innerHTML = '<label for="f-' + c [ 0 ] + '">' + c [ 1 ] + '</label>' +
'<input type="color" id="f-' + c [ 0 ] + '-pick" aria-label="' + c [ 1 ] + '取色器" data-key="' + c [ 0 ] + '">' +
'<input type="text" id="f-' + c [ 0 ] + '" data-key="' + c [ 0 ] + '" maxlength="7" spellcheck="false" autocomplete="off">' ;
$ ( 'colors' ). appendChild ( row );
});
Object . keys ( NUMS ). forEach ( function ( box ) {
NUMS [ box ]. forEach ( function ( n ) {
var row = document . createElement ( 'div' );
row . className = 'row' ;
var unit = n [ 5 ] ? '( ' + n [ 5 ] + ') ' : '' ;
row . innerHTML = '<label for="f-' + n [ 0 ] + '">' + n [ 1 ] + unit + '</label>' +
'<input type="range" id="f-' + n [ 0 ] + '-range" aria-label="' + n [ 1 ] + '滑桿" data-key="' + n [ 0 ] + '" min="' + n [ 2 ] + '" max="' + n [ 3 ] + '" step="' + n [ 4 ] + '">' +
'<input type="number" id="f-' + n [ 0 ] + '" data-key="' + n [ 0 ] + '" min="' + n [ 2 ] + '" max="' + n [ 3 ] + '" step="' + n [ 4 ] + '" inputmode="decimal">' ;
$ ( box ). appendChild ( row );
});
});
PRESETS . forEach ( function ( p ) {
var b = document . createElement ( 'button' );
b . type = 'button' ;
var c = sanitize ( p [ 1 ]);
b . innerHTML = '<span class="swatch" aria-hidden="true">' + COLORS . map ( function ( x ) { return '<i style="background:' + c [ x [ 0 ]] + '"></i>' ; }). join ( '' ) + '</span>' + p [ 0 ];
b . addEventListener ( 'click' , function () {
var next = clone ( state );
2026-11-20 17:47:00 +08:00
LOOK_KEYS . forEach ( function ( x ) { next [ x ] = c [ x ]; });
2026-11-20 15:45:56 +08:00
apply ( next , true );
say ( '已套用「' + p [ 0 ] + '」配色' );
});
$ ( 'presets' ). appendChild ( b );
});
function fill () {
document . querySelectorAll ( '[data-key]' ). forEach ( function ( el ) {
var k = el . getAttribute ( 'data-key' );
if ( el === document . activeElement && el . type !== 'color' && el . type !== 'range' && el . tagName !== 'SELECT' ) return ;
2026-11-20 17:47:00 +08:00
el . value = ( el . type === 'color' && ! state [ k ]) ? '#ffffff' : state [ k ];
2026-11-20 15:45:56 +08:00
el . removeAttribute ( 'aria-invalid' );
});
}
var startTimer = null ;
function apply ( next , refill ) {
state = sanitize ( next );
if ( refill ) fill ();
save ();
render ();
clearTimeout ( startTimer );
startTimer = setTimeout ( restart , 30 );
}
function restart () {
var o = clone ( state );
o . reducedMotion = 'show' ; // 編輯器一律顯示預覽
2026-11-20 15:56:19 +08:00
o . container = $ ( 'play' ); // 只在試玩區內預覽(輸出的程式碼不含這項)
2026-11-20 15:45:56 +08:00
MC . start ( o );
}
document . querySelectorAll ( '[data-key]' ). forEach ( function ( el ) {
var k = el . getAttribute ( 'data-key' );
el . addEventListener ( 'input' , function () {
var v = el . value , next = clone ( state );
2026-11-20 17:47:00 +08:00
if ( k === 'glowColor' && el . type === 'text' && v . trim () === '' ) {
el . removeAttribute ( 'aria-invalid' );
next [ k ] = '' ;
} else if ( /Color$/ . test ( k )) {
2026-11-20 15:45:56 +08:00
var c = normColor ( v );
if ( ! c ) { el . setAttribute ( 'aria-invalid' , 'true' ); return ; }
el . removeAttribute ( 'aria-invalid' );
next [ k ] = c ;
} else if ( NUM_KEYS . indexOf ( k ) >= 0 ) {
if ( v === '' || ! isFinite ( Number ( v ))) { el . setAttribute ( 'aria-invalid' , 'true' ); return ; }
el . removeAttribute ( 'aria-invalid' );
next [ k ] = Number ( v );
} else next [ k ] = v ;
2026-11-20 17:47:00 +08:00
// 光暈:選了顏色但範圍是 0 → 給預設範圍;調了範圍但沒有顏色 → 給白色
if ( k === 'glowColor' && next . glowColor && ! ( Number ( next . glowSize ) > 0 )) next . glowSize = 6 ;
if ( k === 'glowSize' && Number ( next . glowSize ) > 0 && ! next . glowColor ) next . glowColor = '#ffffff' ;
var prev = state ;
2026-11-20 15:45:56 +08:00
state = sanitize ( next );
2026-11-20 17:47:00 +08:00
// 同步其他輸入框(包含連動改到的光暈欄位)
document . querySelectorAll ( '[data-key]' ). forEach ( function ( o ) {
var kk = o . getAttribute ( 'data-key' );
if ( o === el || ( kk !== k && state [ kk ] === prev [ kk ])) return ;
o . value = ( o . type === 'color' && ! state [ kk ]) ? '#ffffff' : state [ kk ];
});
2026-11-20 15:45:56 +08:00
save (); render ();
clearTimeout ( startTimer );
startTimer = setTimeout ( restart , 30 );
});
el . addEventListener ( 'change' , function () { fill (); });
});
$ ( 'reset' ). addEventListener ( 'click' , function () { apply ({}, true ); say ( '已重設為預設值' ); });
// ---- 儲存與分享 ----
function save () { try { localStorage . setItem ( STORE , JSON . stringify ( diff ( state ))); } catch ( e ) {} }
function load () {
var fromHash = null ;
if ( location . hash . length > 1 ) {
try {
var p = new URLSearchParams ( location . hash . slice ( 1 )), o = {}, any = false ;
KEYS . forEach ( function ( k ) { if ( p . has ( kebab ( k ))) { o [ k ] = p . get ( kebab ( k )); any = true ; } });
if ( any ) fromHash = o ;
} catch ( e ) {}
}
if ( fromHash ) return fromHash ;
try { return JSON . parse ( localStorage . getItem ( STORE ) || '{}' ) || {}; } catch ( e ) { return {}; }
}
function shareUrl () {
var d = diff ( state ), p = new URLSearchParams ();
Object . keys ( d ). forEach ( function ( k ) { p . set ( kebab ( k ), d [ k ]); });
var q = p . toString ();
return location . href . split ( '#' )[ 0 ] + ( q ? '#' + q : '' );
}
// ---- 輸出 ----
function tagCode () {
var d = diff ( state ), attrs = Object . keys ( d ). map ( function ( k ) { return '\n data-' + kebab ( k ) + '="' + d [ k ] + '"' ; }). join ( '' );
return '<\!-- 滑鼠立體時鐘:先下載 mouse-clock.js 上傳到網站,再把 src 改成檔案位置 -->\n' +
'<script src="/js/mouse-clock.js"' + attrs + '><\/script>' ;
}
function optionsLine () {
var d = diff ( state );
return 'window.MouseClockOptions = ' + JSON . stringify ( d , null , 2 ) + ';\n' ;
}
function jsWithOptions () {
return '/* 你的設定(滑鼠立體時鐘線上編輯器產生)*/\n' + optionsLine () + '\n' + source ;
}
function inlineCode () {
if ( source === null ) return '/* 正在讀取 mouse-clock.js… */' ;
if ( source === false ) return '/* 讀不到 mouse-clock.js,請改用「一行引用」,或從 Gitea 下載後自行貼上。 */' ;
return '<\!-- 滑鼠立體時鐘(完整內嵌版):貼在 </body> 前面 -->\n<script>\n' + jsWithOptions (). replace ( /<\/script/gi , '<\\/script' ) + '<\/script>' ;
}
function render () {
var code = mode === 'tag' ? tagCode () : inlineCode ();
$ ( 'code' ). value = code ;
$ ( 'outNote' ). textContent = mode === 'tag'
? '只寫出跟預設不同的設定。要先下載 mouse-clock.js(按「下載」)並上傳到你的網站,再把 src 改成實際位置。'
: '整份程式加上你的設定,不用上傳檔案,直接貼進網頁或文章的 HTML 區塊。開頭的原作者署名請保留。' ;
$ ( 'download' ). textContent = mode === 'tag' ? '下載 mouse-clock.js' : '下載 .html 片段' ;
$ ( 'downloadJs' ). hidden = mode !== 'inline' ;
}
function setMode ( m , focus ) {
mode = m ;
[ 'tag' , 'inline' ]. forEach ( function ( x ) {
var t = $ ( 'tab-' + x ), on = x === m ;
t . setAttribute ( 'aria-selected' , on ? 'true' : 'false' );
t . tabIndex = on ? 0 : - 1 ;
if ( on && focus ) t . focus ();
});
$ ( 'outPanel' ). setAttribute ( 'aria-labelledby' , 'tab-' + m );
render ();
}
$ ( 'tab-tag' ). addEventListener ( 'click' , function () { setMode ( 'tag' ); });
$ ( 'tab-inline' ). addEventListener ( 'click' , function () { setMode ( 'inline' ); });
document . querySelector ( '[role="tablist"]' ). addEventListener ( 'keydown' , function ( e ) {
if ( e . key === 'ArrowRight' || e . key === 'ArrowLeft' || e . key === 'Home' || e . key === 'End' ) {
e . preventDefault ();
setMode ( mode === 'tag' ? 'inline' : 'tag' , true );
}
});
var sayTimer = null ;
function say ( msg ) {
$ ( 'status' ). textContent = msg ;
clearTimeout ( sayTimer );
sayTimer = setTimeout ( function () { $ ( 'status' ). textContent = '' ; }, 3000 );
}
function copyText ( text , okMsg ) {
function fallback () {
var ta = $ ( 'code' ), old = ta . value ;
ta . value = text ; ta . select ();
var ok = false ;
try { ok = document . execCommand ( 'copy' ); } catch ( e ) {}
ta . value = old ;
say ( ok ? okMsg : '無法自動複製,請手動選取複製' );
}
if ( navigator . clipboard && window . isSecureContext ) navigator . clipboard . writeText ( text ). then ( function () { say ( okMsg ); }, fallback );
else fallback ();
}
function download ( name , text , type ) {
var blob = new Blob ([ text ], { type : type + ';charset=utf-8' });
var a = document . createElement ( 'a' );
a . href = URL . createObjectURL ( blob );
a . download = name ;
document . body . appendChild ( a ); a . click (); a . remove ();
setTimeout ( function () { URL . revokeObjectURL ( a . href ); }, 1000 );
say ( '已下載 ' + name );
}
$ ( 'copy' ). addEventListener ( 'click' , function () {
if ( mode === 'inline' && ! source ) { say ( '還讀不到 mouse-clock.js' ); return ; }
copyText ( $ ( 'code' ). value , '已複製到剪貼簿' );
});
$ ( 'download' ). addEventListener ( 'click' , function () {
if ( ! source ) { say ( '還讀不到 mouse-clock.js' ); return ; }
if ( mode === 'tag' ) download ( 'mouse-clock.js' , source , 'text/javascript' );
else download ( 'mouse-clock-snippet.html' , inlineCode () + '\n' , 'text/html' );
});
$ ( 'downloadJs' ). addEventListener ( 'click' , function () {
if ( ! source ) { say ( '還讀不到 mouse-clock.js' ); return ; }
download ( 'mouse-clock.js' , jsWithOptions (), 'text/javascript' );
});
$ ( 'share' ). addEventListener ( 'click' , function () {
var url = shareUrl ();
try { history . replaceState ( null , '' , url ); } catch ( e ) {}
copyText ( url , '已複製分享連結' );
});
// ---- 預覽底色 ----
document . querySelectorAll ( 'input[name="bg"]' ). forEach ( function ( r ) {
r . addEventListener ( 'change' , function () {
if ( r . value === 'auto' ) document . documentElement . removeAttribute ( 'data-bg' );
else document . documentElement . setAttribute ( 'data-bg' , r . value );
});
});
2026-11-20 17:05:20 +08:00
// ---- 時鐘移動中,說明再淡一點 ----
var moveTimer = null ;
function moving () {
$ ( 'play' ). classList . add ( 'is-moving' );
clearTimeout ( moveTimer );
moveTimer = setTimeout ( function () { $ ( 'play' ). classList . remove ( 'is-moving' ); }, 1200 );
}
$ ( 'play' ). addEventListener ( 'pointermove' , moving , { passive : true });
$ ( 'play' ). addEventListener ( 'pointerdown' , moving , { passive : true });
$ ( 'play' ). addEventListener ( 'touchmove' , moving , { passive : true });
2026-11-20 15:45:56 +08:00
// ---- 面板收合提示 ----
$ ( 'panel' ). addEventListener ( 'toggle' , function () { $ ( 'panelHint' ). textContent = $ ( 'panel' ). open ? '點這裡收合' : '點這裡展開' ; });
if ( window . matchMedia && window . matchMedia ( '(prefers-reduced-motion: reduce)' ). matches ) $ ( 'rmNote' ). hidden = false ;
$ ( 'ver' ). textContent = '版本 ' + ( MC . version || '' );
state = sanitize ( load ());
fill ();
render ();
restart ();
fetch ( 'mouse-clock.js?v=' + encodeURIComponent ( MC . version || '' ))
. then ( function ( r ) { if ( ! r . ok ) throw new Error ( r . status ); return r . text (); })
. then ( function ( t ) { source = t . replace ( /\r\n/g , '\n' ); if ( ! /\n$/ . test ( source )) source += '\n' ; render (); })
. catch ( function () { source = false ; render (); });
})();
</ script >
2026-11-20 14:46:07 +08:00
</ body >
</ html >