Commit 8a2fc4b 1 parent dbd2a08 commit 8a2fc4b Copy full SHA for 8a2fc4b
File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Finds a MediaWiki section heading from the current DOM using its title.
3
+ *
4
+ * @param sectionHeadingName The name of the section to find.
5
+ * @param n The `n` of the section. Starts at 1.
6
+ * @return The found section heading. `null` if not found.
7
+ */
8
+ export default function findSectionHeading (
9
+ sectionHeadingName : string ,
10
+ n = 1
11
+ ) : HTMLElement | null {
12
+ let currentN = 1 ;
13
+
14
+ const headlines = Array . from ( document . querySelectorAll ( 'h2 > .mw-headline' ) ) ;
15
+ for ( const el of headlines ) {
16
+ if ( el instanceof HTMLElement && el . innerText === sectionHeadingName ) {
17
+ if ( currentN >= n ) {
18
+ return el . parentElement ;
19
+ } else {
20
+ currentN ++ ;
21
+ }
22
+ }
23
+ }
24
+
25
+ return null ;
26
+ }
Original file line number Diff line number Diff line change 1
1
import decorateEditSummary from './decorateEditSummary' ;
2
2
import delink from './delink' ;
3
3
import errorToOO from './errorToOO' ;
4
+ import findSectionHeading from './findSectionHeading' ;
4
5
import getApiErrorText from './getApiErrorText' ;
5
6
import getNativeRange from './getNativeRange' ;
6
7
import getPageContent from './getPageContent' ;
@@ -32,6 +33,7 @@ export default {
32
33
decorateEditSummary : decorateEditSummary ,
33
34
delink : delink ,
34
35
errorToOO : errorToOO ,
36
+ findSectionHeading : findSectionHeading ,
35
37
getApiErrorText : getApiErrorText ,
36
38
getNativeRange : getNativeRange ,
37
39
getPageContent : getPageContent ,
You can’t perform that action at this time.
0 commit comments