|
| 1 | +import React from 'dom-chef'; |
1 | 2 | import select from 'select-dom'; |
2 | | -import delegate from 'delegate-it'; |
| 3 | +import {InfoIcon} from '@primer/octicons-react'; |
| 4 | +import elementReady from 'element-ready'; |
3 | 5 | import * as pageDetect from 'github-url-detection'; |
4 | 6 |
|
5 | 7 | import features from '.'; |
| 8 | +import onPrMerge from '../github-events/on-pr-merge'; |
| 9 | +import featureLink from '../helpers/feature-link'; |
| 10 | +import attachElement from '../helpers/attach-element'; |
| 11 | +import {canEditEveryComment} from './quick-comment-edit'; |
6 | 12 |
|
7 | | -function init(): Deinit { |
8 | | - const observer = new MutationObserver(() => { |
9 | | - const deleteButton = select('[action$="/cleanup"] [type="submit"]'); |
10 | | - if (deleteButton) { |
11 | | - deleteButton.dataset.disableWith = 'Auto-deleting…'; |
12 | | - deleteButton.click(); |
13 | | - observer.disconnect(); |
14 | | - } |
15 | | - }); |
| 13 | +// TODO: Not an exact match; Moderators can edit comments but not create releases |
| 14 | +const canCreateRelease = canEditEveryComment; |
| 15 | + |
| 16 | +async function init(): Promise<void> { |
| 17 | + const deleteButton = select('[action$="/cleanup"] [type="submit"]'); |
| 18 | + if (!deleteButton) { |
| 19 | + return; |
| 20 | + } |
| 21 | + |
| 22 | + deleteButton.dataset.disableWith = 'Auto-deleting…'; |
| 23 | + deleteButton.click(); |
16 | 24 |
|
17 | | - const subscription = delegate(document, '.js-merge-commit-button', 'click', () => { |
18 | | - subscription.destroy(); |
19 | | - observer.observe(select('.discussion-timeline-actions')!, {childList: true}); |
| 25 | + const deletionEvent = await elementReady('[data-test-selector="head-ref-deleted-event-ref-name"]', { |
| 26 | + stopOnDomReady: false, |
20 | 27 | }); |
21 | 28 |
|
22 | | - return [ |
23 | | - observer, |
24 | | - subscription, |
25 | | - ]; |
| 29 | + attachElement({ |
| 30 | + anchor: deletionEvent!.closest('.TimelineItem-body')!, |
| 31 | + position: 'append', |
| 32 | + getNewElement() { |
| 33 | + const url = featureLink(features.getFeatureID(import.meta.url)); |
| 34 | + return <a className="d-inline-block" href={url}>via Refined GitHub <InfoIcon/></a>; |
| 35 | + }, |
| 36 | + }); |
26 | 37 | } |
27 | 38 |
|
28 | 39 | void features.add(import.meta.url, { |
29 | | - include: [ |
| 40 | + asLongAs: [ |
30 | 41 | pageDetect.isPRConversation, |
| 42 | + pageDetect.isOpenPR, |
| 43 | + canCreateRelease, |
| 44 | + ], |
| 45 | + additionalListeners: [ |
| 46 | + onPrMerge, |
31 | 47 | ], |
32 | | - deduplicate: 'has-rgh-inner', |
| 48 | + onlyAdditionalListeners: true, |
33 | 49 | init, |
34 | 50 | }); |
0 commit comments