1
1
window . onload = ( ) => {
2
- // detect enums and make sure their description is easily to style
3
- document . querySelectorAll ( ".class" ) . forEach ( class_elt => {
4
- if ( isEnum ( class_elt ) ) {
5
- title = class_elt . querySelector ( "dt" ) ;
6
- title . innerHTML = title . innerHTML . replace ( / , / g, "<span>, </span>" ) ;
7
- class_elt . classList . add ( "enum" ) ;
8
- }
9
- } )
10
-
11
- // remove the dark theme watermark added in js
12
- footer = document . querySelector ( "footer" )
13
- dark_theme_link = (
14
- '<a href="https://github.com/MrDogeBro/sphinx_rtd_dark_mode">Dark theme</a>'
15
- + ' provided by '
16
- + '<a href="http://mrdogebro.com">MrDogeBro</a>.'
17
- )
18
- whenCondition (
19
- ( ) => footer . innerHTML = footer . innerHTML . replace ( dark_theme_link , '' ) ,
20
- ( ) => footer . innerHTML . includes ( dark_theme_link )
21
- )
22
-
23
- r = document . querySelector ( ':root' )
24
- r . style . setProperty ( '--dark-link-color' , '#80cb53' ) ;
25
-
26
- // t = document.querySelector('html[data-theme="dark"] .wy-side-nav-search')
27
- // t.style.setProperty('background-color', '#0d0d0d');
28
-
29
- // move the attribute and properties of a class to appear first in the class
30
- document . querySelectorAll ( ".py.class" ) . forEach ( pythonClass => {
31
- if ( ! isEnum ( pythonClass ) ) {
32
- appendAfter = getEndOfClassHeader ( pythonClass )
33
- pythonClass . querySelectorAll ( ".py.attribute" ) . forEach ( attribute => {
34
- appendAfter . insertAdjacentElement ( 'afterend' , attribute )
35
- appendAfter = attribute
36
- } )
37
- pythonClass . querySelectorAll ( ".py.property" ) . forEach ( property => {
38
- appendAfter . insertAdjacentElement ( 'afterend' , property )
39
- appendAfter = property
40
- } )
41
- }
42
- } )
43
-
44
- // move the constants of a module to appear first in the module
45
- document . querySelectorAll ( ".target" ) . forEach ( moduleMarker => {
46
- if ( moduleMarker . id . startsWith ( "module-" ) ) {
47
- appendAfter = moduleMarker
48
- sibling = moduleMarker . nextSibling
49
- for ( ; sibling ; ) {
50
- next = sibling . nextSibling
51
- if ( sibling . nodeName === "DL" && sibling . classList . contains ( "data" ) ) {
52
- appendAfter . insertAdjacentElement ( 'afterend' , sibling )
53
- appendAfter = sibling
54
- }
55
- sibling = next
56
- }
2
+ // detect enums and make sure their description is easily to style
3
+ document . querySelectorAll ( ".class" ) . forEach ( ( class_elt ) => {
4
+ if ( isEnum ( class_elt ) ) {
5
+ title = class_elt . querySelector ( "dt" ) ;
6
+ title . innerHTML = title . innerHTML . replace ( / , / g, "<span>, </span>" ) ;
7
+ class_elt . classList . add ( "enum" ) ;
8
+ }
9
+ } ) ;
10
+
11
+ // remove the dark theme watermark added in js
12
+ footer = document . querySelector ( "footer" ) ;
13
+ dark_theme_link =
14
+ '<a href="https://github.com/MrDogeBro/sphinx_rtd_dark_mode">Dark theme</a>' +
15
+ " provided by " +
16
+ '<a href="http://mrdogebro.com">MrDogeBro</a>.' ;
17
+ whenCondition (
18
+ ( ) => ( footer . innerHTML = footer . innerHTML . replace ( dark_theme_link , "" ) ) ,
19
+ ( ) => footer . innerHTML . includes ( dark_theme_link )
20
+ ) ;
21
+
22
+ r = document . querySelector ( ":root" ) ;
23
+ r . style . setProperty ( "--dark-link-color" , "#80cb53" ) ;
24
+
25
+ // t = document.querySelector('html[data-theme="dark"] .wy-side-nav-search')
26
+ // t.style.setProperty('background-color', '#0d0d0d');
27
+
28
+ // move the attribute and properties of a class to appear first in the class
29
+ document . querySelectorAll ( ".py.class" ) . forEach ( ( pythonClass ) => {
30
+ if ( ! isEnum ( pythonClass ) ) {
31
+ appendAfter = getEndOfClassHeader ( pythonClass ) ;
32
+ pythonClass . querySelectorAll ( ".py.attribute" ) . forEach ( ( attribute ) => {
33
+ appendAfter . insertAdjacentElement ( "afterend" , attribute ) ;
34
+ appendAfter = attribute ;
35
+ } ) ;
36
+ pythonClass . querySelectorAll ( ".py.property" ) . forEach ( ( property ) => {
37
+ appendAfter . insertAdjacentElement ( "afterend" , property ) ;
38
+ appendAfter = property ;
39
+ } ) ;
40
+ }
41
+ } ) ;
42
+
43
+ // move the constants of a module to appear first in the module
44
+ document . querySelectorAll ( ".target" ) . forEach ( ( moduleMarker ) => {
45
+ if ( moduleMarker . id . startsWith ( "module-" ) ) {
46
+ appendAfter = moduleMarker ;
47
+ sibling = moduleMarker . nextSibling ;
48
+ for ( ; sibling ; ) {
49
+ next = sibling . nextSibling ;
50
+ if ( sibling . nodeName === "DL" && sibling . classList . contains ( "data" ) ) {
51
+ appendAfter . insertAdjacentElement ( "afterend" , sibling ) ;
52
+ appendAfter = sibling ;
57
53
}
58
- } )
59
-
60
- // move the abstract classes of a module to appear first in the module
61
- document . querySelectorAll ( ".section" ) . forEach ( section => {
62
- if ( section . id . startsWith ( "module-" ) ) {
63
- descriptionStart = section . querySelector ( "dl" )
64
- appendAfter = descriptionStart . previousElementSibling
65
- sibling = descriptionStart
66
- for ( ; sibling ; ) {
67
- next = sibling . nextElementSibling
68
- if ( sibling . classList . contains ( "class" ) && isAbstract ( sibling ) ) {
69
- appendAfter . insertAdjacentElement ( 'afterend' , sibling )
70
- appendAfter = sibling
71
- }
72
- sibling = next
73
- }
54
+ sibling = next ;
55
+ }
56
+ }
57
+ } ) ;
58
+
59
+ // move the abstract classes of a module to appear first in the module
60
+ document . querySelectorAll ( ".section" ) . forEach ( ( section ) => {
61
+ if ( section . id . startsWith ( "module-" ) ) {
62
+ descriptionStart = section . querySelector ( "dl" ) ;
63
+ appendAfter = descriptionStart . previousElementSibling ;
64
+ sibling = descriptionStart ;
65
+ for ( ; sibling ; ) {
66
+ next = sibling . nextElementSibling ;
67
+ if ( sibling . classList . contains ( "class" ) && isAbstract ( sibling ) ) {
68
+ appendAfter . insertAdjacentElement ( "afterend" , sibling ) ;
69
+ appendAfter = sibling ;
74
70
}
75
- } )
76
-
77
-
78
- }
71
+ sibling = next ;
72
+ }
73
+ }
74
+ } ) ;
75
+ } ;
79
76
80
77
// const themeButton = document.querySelector('themeSwitcher')
81
78
// themeButton.addEventListener('click', () => {
82
- //
79
+ //
83
80
// });
84
81
85
-
86
82
function getEndOfClassHeader ( elt ) {
87
- admonition = elt . querySelectorAll ( ".admonition" )
88
- if ( admonition . length != 0 ) return admonition [ admonition . length - 1 ]
89
- examples = elt . querySelectorAll ( "dd>div.doctest" )
90
- if ( examples . length != 0 ) return examples [ examples . length - 1 ]
91
- return elt . querySelector ( ".field-list" )
83
+ admonition = elt . querySelectorAll ( ".admonition" ) ;
84
+ if ( admonition . length != 0 ) return admonition [ admonition . length - 1 ] ;
85
+ field_list = elt . querySelector ( ".class>dd>.field-list" ) ;
86
+ if ( field_list !== null ) return elt . querySelector ( ".class>dd>.field-list" ) ;
87
+ examples = elt . querySelectorAll ( ".class>dd>div.doctest" ) ;
88
+ if ( examples . length != 0 ) return examples [ examples . length - 1 ] ;
89
+ return elt ;
92
90
}
93
91
94
92
function isEnum ( elt , explored = [ ] ) {
95
- id = elt . querySelector ( "dt" ) . id
96
- if ( explored . includes ( id ) ) return false
97
-
98
- explored . push ( id )
99
-
100
- parents = elt . querySelector ( "dd > p:first-child" )
101
- if ( parents && parents . innerHTML . includes ( "Enum" ) ) {
102
- return true
103
- }
93
+ id = elt . querySelector ( "dt" ) . id ;
94
+ if ( explored . includes ( id ) ) return false ;
95
+
96
+ explored . push ( id ) ;
104
97
105
- parents_contain_enum = false
106
- elt . querySelectorAll ( "dd > p:first-child > a" ) . forEach ( link => {
107
- parent_id = link . href . split ( "#" ) [ 1 ]
108
- new_elt = document . querySelector ( `.class:has([id='${ parent_id } '])` )
109
- if ( new_elt && isEnum ( new_elt , explored ) ) parents_contain_enum = true
110
- } )
98
+ parents = elt . querySelector ( "dd > p:first-child" ) ;
99
+ if ( parents && parents . innerHTML . includes ( "Enum" ) ) {
100
+ return true ;
101
+ }
111
102
112
- return parents_contain_enum
103
+ parents_contain_enum = false ;
104
+ elt . querySelectorAll ( "dd > p:first-child > a" ) . forEach ( ( link ) => {
105
+ parent_id = link . href . split ( "#" ) [ 1 ] ;
106
+ new_elt = document . querySelector ( `.class:has([id='${ parent_id } '])` ) ;
107
+ if ( new_elt && isEnum ( new_elt , explored ) ) parents_contain_enum = true ;
108
+ } ) ;
109
+
110
+ return parents_contain_enum ;
113
111
}
114
112
115
113
function isAbstract ( elt ) {
116
- parents = elt . querySelector ( "dd > p:first-child" )
117
- if ( parents && parents . innerHTML . includes ( "ABC" ) ) {
118
- return true
119
- }
120
- return false
114
+ parents = elt . querySelector ( "dd > p:first-child" ) ;
115
+ if ( parents && parents . innerHTML . includes ( "ABC" ) ) {
116
+ return true ;
117
+ }
118
+ return false ;
121
119
}
122
120
123
121
function whenCondition ( action , condition ) {
124
- function watcher ( ) {
125
- if ( condition ( ) ) {
126
- action ( )
127
- clearInterval ( interval )
128
- }
122
+ function watcher ( ) {
123
+ if ( condition ( ) ) {
124
+ action ( ) ;
125
+ clearInterval ( interval ) ;
129
126
}
130
-
131
- interval = setInterval ( watcher , 50 ) ;
132
- }
127
+ }
128
+
129
+ interval = setInterval ( watcher , 50 ) ;
130
+ }
0 commit comments