@@ -10,12 +10,70 @@ function ping() {
1010ping ( ) ; // inject version info
1111
1212
13- let darkMode = false
13+ const banner = document . getElementById ( 'banner' )
14+ const snippet = document . getElementById ( 'snippet' )
15+ const about = document . getElementById ( 'about' )
16+ const funcname = document . getElementById ( 'funcname' )
17+ const gcflags = document . getElementById ( 'gcflags' )
18+ const horiz = document . querySelectorAll ( '.gutter.gutter-horizontal' )
19+ const btns = document . querySelectorAll ( 'input[type=button]' )
20+ const code = document . getElementById ( 'code' )
21+ const links = document . querySelectorAll ( '#about a' )
22+ const gutter = document . getElementsByClassName ( 'gutter' )
23+ const output = document . getElementById ( 'output' )
24+
25+ function setDarkMode ( ) {
26+ banner . style . backgroundColor = '#566'
27+ snippet . style . backgroundColor = '#665'
28+ about . style . backgroundColor = '#665'
29+ funcname . style . backgroundColor = '#343'
30+ funcname . style . border = '1px solid #454'
31+ funcname . style . color = 'lightgray'
32+ gcflags . style . backgroundColor = '#343'
33+ gcflags . style . border = '1px solid #454'
34+ gcflags . style . color = 'lightgray'
35+ horiz . forEach ( v => v . style . filter = 'invert(.7)' )
36+ btns . forEach ( v => {
37+ v . style . backgroundColor = '#0044cb'
38+ v . style . color = 'lightgray'
39+ } )
40+ code . style . color = 'rgb(230, 255, 255)'
41+ links . forEach ( v => v . style . color = '#809fff' )
42+ gutter [ 0 ] . style . backgroundColor = 'rgb(45, 45, 45)'
43+ output . style . backgroundColor = 'rgb(60, 60, 60)'
44+ document . body . style . color = 'lightgray'
45+ }
46+
47+ function setLightMode ( ) {
48+ banner . style . backgroundColor = '#E0EBF5'
49+ snippet . style . backgroundColor = 'rgba(255, 252, 221, 0.81)'
50+ about . style . backgroundColor = '#FFD'
51+ funcname . style . backgroundColor = '#fff'
52+ funcname . style . border = '1px solid #ccc'
53+ funcname . style . color = ''
54+ gcflags . style . backgroundColor = '#fff'
55+ gcflags . style . border = '1px solid #ccc'
56+ gcflags . style . color = ''
57+ horiz . forEach ( v => v . style . filter = '' )
58+ btns . forEach ( v => {
59+ v . style . backgroundColor = '#375EAB'
60+ v . style . color = '#fff'
61+ } )
62+ code . style . color = 'black'
63+ links . forEach ( v => v . style . color = '' )
64+ gutter [ 0 ] . style . backgroundColor = '#eee'
65+ output . style . backgroundColor = '#f1f1f1'
66+ document . body . style . color = 'black'
67+ }
68+
1469let msgbox = document . getElementById ( 'outputMsg' )
1570let ssabox = document . getElementById ( 'ssa' )
1671ssabox . addEventListener ( 'load' , ( ) => {
17- if ( darkMode ) {
18- ssabox . contentWindow . document . getElementById ( 'dark-mode-button' ) . click ( )
72+ const darkBtn = ssabox . contentWindow . document . getElementById ( 'dark-mode-button' )
73+ if ( darkBtn . checked ) {
74+ setDarkMode ( )
75+ } else {
76+ setLightMode ( )
1977 }
2078
2179 // inject ssa style
@@ -24,68 +82,24 @@ ssabox.addEventListener('load', () => {
2482 ssabox . contentWindow . document
2583 . getElementById ( 'dark-mode-button' )
2684 . addEventListener ( 'click' , function ( ) {
27- const banner = document . getElementById ( 'banner' )
28- const snippet = document . getElementById ( 'snippet' )
29- const about = document . getElementById ( 'about' )
30- const funcname = document . getElementById ( 'funcname' )
31- const gcflags = document . getElementById ( 'gcflags' )
32- const horiz = document . querySelectorAll ( '.gutter.gutter-horizontal' )
33- const btns = document . querySelectorAll ( 'input[type=button]' )
34- const code = document . getElementById ( 'code' )
35- const links = document . querySelectorAll ( '#about a' )
36-
37- if ( darkMode ) {
38- banner . style . backgroundColor = '#E0EBF5'
39- snippet . style . backgroundColor = 'rgba(255, 252, 221, 0.81)'
40- about . style . backgroundColor = '#FFD'
41- funcname . style . backgroundColor = '#fff'
42- funcname . style . border = '1px solid #ccc'
43- funcname . style . color = ''
44- gcflags . style . backgroundColor = '#fff'
45- gcflags . style . border = '1px solid #ccc'
46- gcflags . style . color = ''
47- horiz . forEach ( ( v ) => {
48- v . style . filter = ''
49- } )
50- btns . forEach ( ( v ) => {
51- v . style . backgroundColor = '#375EAB'
52- v . style . color = '#fff'
53- } )
54- code . style . color = 'black'
55- links . forEach ( v => {
56- v . style . color = ''
57- } )
58- document . body . style . color = 'black'
59-
60- darkMode = false
85+ if ( darkBtn . checked ) {
86+ setDarkMode ( )
6187 } else {
62- banner . style . backgroundColor = '#566'
63- snippet . style . backgroundColor = '#665'
64- about . style . backgroundColor = '#665'
65- funcname . style . backgroundColor = '#343'
66- funcname . style . border = '1px solid #454'
67- funcname . style . color = 'lightgray'
68- gcflags . style . backgroundColor = '#343'
69- gcflags . style . border = '1px solid #454'
70- gcflags . style . color = 'lightgray'
71- horiz . forEach ( ( v ) => {
72- v . style . filter = 'invert(.7)'
73- } )
74- btns . forEach ( ( v ) => {
75- v . style . backgroundColor = '#0044cb'
76- v . style . color = 'lightgray'
77- } )
78- code . style . color = 'rgb(230, 255, 255)'
79- links . forEach ( v => {
80- v . style . color = '#809fff'
81- } )
82- document . body . style . color = 'lightgray'
83-
84- darkMode = true
88+ setLightMode ( )
8589 }
8690 } )
8791} ) ;
8892
93+ window . matchMedia ( '(prefers-color-scheme: dark)' ) . addEventListener ( 'change' , e => {
94+ ssabox . contentWindow . document . getElementById ( 'dark-mode-button' ) . click ( )
95+ if ( e . matches ) {
96+ setDarkMode ( )
97+ } else {
98+ setLightMode ( )
99+ }
100+ console . log ( 'changed' )
101+ } )
102+
89103let lastFuncName , lastCode , lastGcflags ;
90104function build ( ) {
91105 let funcname = document . getElementById ( 'funcname' ) . value ;
@@ -98,7 +112,7 @@ function build() {
98112 return
99113 }
100114 if ( ! findSSAFunc ( code , funcname ) ) {
101- setMessageBox ( 'GOFUNCNAME does not exist in your code.' , false )
115+ setMessageBox ( 'GOSSAFUNC does not exist in your code.' , false )
102116 return
103117 }
104118
@@ -232,32 +246,4 @@ function loadCode() {
232246}
233247loadCode ( ) // load content if access with id
234248
235- Split ( [ '#snippet' , '#output' ] , {
236- sizes : [ 30 , 70 ] ,
237- } )
238-
239- // TODO: dragable scroll
240- // let wholePage = document.querySelector('body');
241- // let el = document.querySelector("#ssa").contentDocument.querySelector('body');
242- // let x = 0, y = 0, t = 0, l = 0;
243- // console.log(el);
244-
245- // let draggingFunction = (e) => {
246- // wholePage.addEventListener('mouseup', () => {
247- // wholePage.removeEventListener("mousemove", draggingFunction);
248- // });
249-
250- // el.scrollLeft = l - e.pageX + x;
251- // el.scrollTop = t - e.pageY + y;
252- // };
253-
254- // wholePage.addEventListener('click', (e) => {
255- // console.log("xxx")
256-
257- // y = e.pageY;
258- // x = e.pageX;
259- // t = el.scrollTop;
260- // l = el.scrollLeft;
261-
262- // el.addEventListener('mousemove', draggingFunction);
263- // });
249+ Split ( [ '#snippet' , '#output' ] , { sizes : [ 30 , 70 ] } )
0 commit comments