Skip to content

Commit 0ad81af

Browse files
authored
refactor: remove customized replaceChild(); avoid undefined childrens and IDs; optimize logic (qiuwenbaike#1699)
* refactor(EasyArchive): avoid undefined element ID; remove replaceChild(); optimize logic * refactor(PagePatroller): remove replaceChild(); optimize logic * refactor(EasyArchive, PagePatroller): avoid undefined childrens * refactor: remove customized replaceChild(); avoid undefined childrens and IDs; optimize logic
1 parent 266de28 commit 0ad81af

File tree

32 files changed

+759
-518
lines changed

32 files changed

+759
-518
lines changed

dist/EasyArchive/EasyArchive.js

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

dist/GeoLocationReader/GeoLocationReader.js

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

dist/MarkRights-Userpage/MarkRights-Userpage.js

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

dist/OnlineAdmins/OnlineAdmins.js

Lines changed: 6 additions & 2 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: 66 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/QueryContributors/QueryContributors.js

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

src/EasyArchive/modules/addLinks.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import {getSections} from './util/getSection';
66
import {refresh} from './util/refreshPage';
77
import {toastify} from 'ext.gadget.Toastify';
88

9-
const appendFooterNotice = (innerElement: Element) => {
10-
document.querySelectorAll<HTMLElement>(OPTIONS.mountPointSelector)[0]?.prepend(innerElement);
9+
const appendFooterNotice = (element: Element) => {
10+
const mountPoint = document.querySelector<HTMLElement>(OPTIONS.mountPointSelector);
11+
12+
if (mountPoint) {
13+
mountPoint.prepend(element);
14+
}
1115
};
1216

1317
const addLinks = async ({

src/EasyArchive/modules/components/react.tsx

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1+
import * as OPTIONS from '../../options.json';
12
import React, {ReactElement} from 'ext.gadget.React';
23
import {footerNotice, sectionIdSpan} from './EasyArchive.module.less';
34
import {getMessage} from '../i18n';
45
import {sanitize} from '../util/sanitize';
56

67
interface FooterNoticeProps {
7-
id: string;
8+
id?: string;
89
children?: ReactElement | ReactElement[];
910
}
1011

11-
const FooterNotice = ({id, children}: FooterNoticeProps) => (
12-
<>
13-
{mw.config.get('skin') === 'citizen' ? (
14-
<section id={id} className={[footerNotice, 'page-info__item', 'citizen-footer__pageinfo-item', 'noprint']}>
15-
{children}
16-
</section>
17-
) : ['vector', 'vector-2022', 'gongbi'].includes(mw.config.get('skin')) ||
18-
document.querySelector('ul#footer-info') ? (
19-
<li id={id} className={[footerNotice, 'noprint']}>
20-
{children}
21-
</li>
22-
) : (
23-
<div id={id} className={[footerNotice, 'noprint']}>
24-
{children}
25-
</div>
26-
)}
27-
</>
28-
);
12+
const FooterNotice = ({id, children = <></>}: FooterNoticeProps) => {
13+
const {skin} = mw.config.get();
14+
15+
return (
16+
<>
17+
{skin === 'citizen' ? (
18+
<section
19+
id={id ?? OPTIONS.elementId}
20+
className={[footerNotice, 'page-info__item', 'citizen-footer__pageinfo-item', 'noprint']}
21+
>
22+
{children}
23+
</section>
24+
) : ['vector', 'vector-2022', 'gongbi'].includes(skin) || document.querySelector('ul#footer-info') ? (
25+
<li id={id ?? OPTIONS.elementId} className={[footerNotice, 'noprint']}>
26+
{children}
27+
</li>
28+
) : (
29+
<div id={id ?? OPTIONS.elementId} className={[footerNotice, 'noprint']}>
30+
{children}
31+
</div>
32+
)}
33+
</>
34+
);
35+
};
2936

3037
const InBlackList = () => (
3138
<FooterNotice id="easy_archive_not_supported_notice">
@@ -86,27 +93,21 @@ interface OnClickProps {
8693
textContent: string;
8794
className: string;
8895
onClick?: (event: Event) => void;
89-
children?: ReactElement | ReactElement[];
9096
}
9197

92-
const OnClick = ({textContent, className, onClick, children}: OnClickProps) => (
98+
const OnClick = ({textContent, className, onClick}: OnClickProps) => (
9399
<a
94100
className={['gadget-easy_archive__link', `gadget-easy_archive__link-${className}`]}
95-
onClick={onClick}
101+
onClick={onClick || (() => {})}
96102
textContent={textContent}
97-
>
98-
{children}
99-
</a>
103+
/>
100104
);
101105

102106
interface SectionIDProps {
103-
className?: string;
104107
children?: ReactElement | ReactElement[];
105108
}
106109

107-
const SectionID = ({className, children}: SectionIDProps) => (
108-
<span className={[className, sectionIdSpan]}>{children}</span>
109-
);
110+
const SectionID = ({children}: SectionIDProps) => <span className={sectionIdSpan}>{children}</span>;
110111

111112
const Pipe = () => <span className="mw-editsection-divider" textContent={'|'} />;
112113

@@ -121,8 +122,6 @@ const EditConflictNotice = ({onClick}: EditConflictNoticeProps) => (
121122
</span>
122123
);
123124

124-
const spanWrap = (textContent: string) => <span textContent={textContent} />;
125-
126125
export {
127126
FooterNotice,
128127
Enabled,
@@ -134,5 +133,4 @@ export {
134133
Pipe,
135134
SectionID,
136135
EditConflictNotice,
137-
spanWrap,
138136
};

src/EasyArchive/modules/components/sectionLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const RemoveSectionLink = ({
5858
}: RemoveSectionLinkProps) => (
5959
<OnClick
6060
className={'delete'}
61-
textContent={getMessage('Delete')}
6261
onClick={(event) => {
6362
void removeOnClick(event, {
6463
sectionIdSpans,
@@ -69,6 +68,7 @@ const RemoveSectionLink = ({
6968
toastifyInstance,
7069
});
7170
}}
71+
textContent={getMessage('Delete')}
7272
/>
7373
);
7474

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {getMessage} from '../i18n';
2+
3+
const getArchivingMessage = (indexNo: string) => {
4+
return getMessage('Archiving') + getMessage(':') + getMessage('Section $1').replace('$1', indexNo);
5+
};
6+
7+
const getArchivedMessage = (indexNo: string) => {
8+
return getMessage('Archived') + getMessage(':') + getMessage('Section $1').replace('$1', indexNo);
9+
};
10+
11+
const getDeletingMessage = (indexNo: string) => {
12+
return getMessage('Deleting') + getMessage(':') + getMessage('Section $1').replace('$1', indexNo);
13+
};
14+
15+
const getDeletedMessage = (indexNo: string) => {
16+
return getMessage('Deleted') + getMessage(':') + getMessage('Section $1').replace('$1', indexNo);
17+
};
18+
19+
export {getArchivingMessage, getArchivedMessage, getDeletingMessage, getDeletedMessage};

0 commit comments

Comments
 (0)