Skip to content

Commit 7d850de

Browse files
authored
refactor: optimize type annotation and logic; replace replaceChild with replaceWith; remove IE code (qiuwenbaike#1700)
* refactor: optimize type annotation and logic; replace replaceChild with replaceWith; remove IE code
1 parent 5bc743c commit 7d850de

35 files changed

+402
-556
lines changed

dist/EasyArchive/EasyArchive.js

Lines changed: 100 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Editform_Attribution/Editform_Attribution.js

Lines changed: 18 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/HistoryDisclaimer/HistoryDisclaimer.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/HotCat/HotCat.js

Lines changed: 7 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/PagePatroller/PagePatroller.js

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/QuickImport/QuickImport.js

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Twinkle/Twinkle.js

Lines changed: 18 additions & 18 deletions
Large diffs are not rendered by default.

dist/WhoIsActive/WhoIsActive.js

Lines changed: 59 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/EasyArchive/EasyArchive.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {ArcLocNotAllowed, InBlackList, NoArcLoc, NotAllowed} from './modules/components/react';
2-
import {addLinks, appendFooterNotice} from './modules/addLinks';
1+
import {ArcLocNotAllowed, Enabled, InBlackList, NoArcLoc, NotAllowed} from './modules/components/react';
32
import {getSettings, ifArcLocNotAllowed, isInBlacklist, isNotAllowed, isNotSupported} from './modules/util/getSettings';
43
import React from 'ext.gadget.React';
4+
import {addLinks} from './modules/addLinks';
5+
import {appendFooterNotice} from './modules/appendFooterNotice';
56

67
(function easyArchive() {
78
const notSupported = isNotSupported();
@@ -39,5 +40,7 @@ import React from 'ext.gadget.React';
3940
return;
4041
}
4142

43+
appendFooterNotice(<Enabled arcLoc={arcLoc} />);
44+
4245
void addLinks(settings);
4346
})();

src/EasyArchive/modules/addLinks.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
1-
import * as OPTIONS from '../options.json';
2-
import {EditConflictNotice, Enabled} from './components/react';
3-
import React, {ReactElement} from 'ext.gadget.React';
41
import {ArchiveAndDeleteSectionLink} from './components/sectionLink';
2+
import {EditConflictNotice} from './components/react';
3+
import React from 'ext.gadget.React';
54
import {getSections} from './util/getSection';
65
import {refresh} from './util/refreshPage';
76
import {toastify} from 'ext.gadget.Toastify';
87

9-
const appendFooterNotice = (element: Element) => {
10-
const mountPoint = document.querySelector<HTMLElement>(OPTIONS.mountPointSelector);
11-
12-
if (mountPoint) {
13-
mountPoint.prepend(element);
14-
}
15-
};
16-
178
const addLinks = async ({
189
arcLevel,
1910
arcLoc,
2011
secArc,
2112
secDel,
2213
}: {
2314
arcLevel: string;
24-
arcLoc: string | null;
15+
arcLoc: string;
2516
secArc: string;
2617
secDel: string;
2718
}) => {
28-
if (!arcLoc) {
29-
return;
30-
}
31-
appendFooterNotice(<Enabled arcLoc={arcLoc} />);
32-
3319
const {wgPageName} = mw.config.get();
3420
const sectionsToArchive = await getSections(wgPageName);
3521

@@ -39,10 +25,12 @@ const addLinks = async ({
3925

4026
for (const heading of headings) {
4127
const headline = heading.querySelector('.mw-headline');
42-
headlines[headlines.length] = headline?.id;
28+
if (headline) {
29+
headlines[headlines.length] = headline.id;
30+
}
4331
}
4432

45-
const sectionIdSpans: ReactElement[] = [];
33+
const sectionIdSpans: Element[] = [];
4634
let toastifyInstance: ToastifyInstance = {
4735
hideToast: () => {},
4836
};
@@ -133,4 +121,4 @@ const addLinks = async ({
133121
});
134122
};
135123

136-
export {addLinks, appendFooterNotice};
124+
export {addLinks};

0 commit comments

Comments
 (0)