File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,52 @@ function spec_toggle_tests(rule_id) {
2222 el . classList . remove ( 'popup-hidden' ) ;
2323 }
2424}
25+
26+ function toggle_grammar ( ) {
27+ const grammarRailroad = get_railroad ( ) ;
28+ set_railroad ( ! grammarRailroad ) ;
29+ update_railroad ( ) ;
30+ }
31+
32+ function get_railroad ( ) {
33+ let grammarRailroad = null ;
34+ try {
35+ grammarRailroad = localStorage . getItem ( 'grammar-railroad' ) ;
36+ } catch ( e ) {
37+ // Ignore error.
38+ }
39+ grammarRailroad = grammarRailroad === 'true' ? true : false ;
40+ return grammarRailroad ;
41+ }
42+
43+ function set_railroad ( newValue ) {
44+ try {
45+ localStorage . setItem ( 'grammar-railroad' , newValue ) ;
46+ } catch ( e ) {
47+ // Ignore error.
48+ }
49+ }
50+
51+ function update_railroad ( ) {
52+ const grammarRailroad = get_railroad ( ) ;
53+ const railroads = document . querySelectorAll ( '.grammar-railroad' ) ;
54+ railroads . forEach ( element => {
55+ if ( grammarRailroad ) {
56+ element . classList . remove ( 'grammar-hidden' ) ;
57+ } else {
58+ element . classList . add ( 'grammar-hidden' ) ;
59+ }
60+ } ) ;
61+ const buttons = document . querySelectorAll ( '.grammar-toggle' ) ;
62+ buttons . forEach ( button => {
63+ if ( grammarRailroad ) {
64+ button . innerText = "Hide Railroad" ;
65+ } else {
66+ button . innerText = "Show Railroad" ;
67+ }
68+ } ) ;
69+ }
70+
71+ ( function railroad_onload ( ) {
72+ update_railroad ( ) ;
73+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments