summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/features/forked-to.tsx5
-rw-r--r--source/features/mark-unread.tsx2
-rw-r--r--source/features/more-dropdown.tsx2
-rw-r--r--source/features/releases-tab.tsx8
-rw-r--r--source/features/sticky-discussion-sidebar.tsx4
-rw-r--r--source/libs/features.tsx14
6 files changed, 27 insertions, 8 deletions
diff --git a/source/features/forked-to.tsx b/source/features/forked-to.tsx
index 4fd445ae..b6944d9f 100644
--- a/source/features/forked-to.tsx
+++ b/source/features/forked-to.tsx
@@ -4,6 +4,7 @@ import cache from 'webext-storage-cache';
import select from 'select-dom';
import pFilter from 'p-filter';
import onetime from 'onetime';
+import elementReady from 'element-ready';
import features from '../libs/features';
import {isRepoWithAccess} from '../libs/page-detect';
import {getRepoURL, getUsername} from '../libs/utils';
@@ -65,7 +66,7 @@ async function init(): Promise<void> {
document.body.classList.add('rgh-forked-to');
- const forkCounter = select('.social-count[href$="/network/members"]')!;
+ const forkCounter = (await elementReady('.social-count[href$="/network/members"]'))!;
if (forks.length === 1) {
forkCounter.before(
<a href={`/${forks[0]}`}
@@ -111,6 +112,6 @@ features.add({
include: [
features.isRepo
],
- load: features.onAjaxedPages,
+ load: features.nowAndOnAjaxedPages,
init
});
diff --git a/source/features/mark-unread.tsx b/source/features/mark-unread.tsx
index a5a15ccc..74bd32a7 100644
--- a/source/features/mark-unread.tsx
+++ b/source/features/mark-unread.tsx
@@ -1,6 +1,7 @@
import './mark-unread.css';
import React from 'dom-chef';
import select from 'select-dom';
+import onDomReady from 'dom-loaded';
import elementReady from 'element-ready';
import delegate, {DelegateSubscription, DelegateEvent} from 'delegate-it';
import features from '../libs/features';
@@ -392,6 +393,7 @@ function destroy(): void {
async function init(): Promise<void> {
destroy();
+ await onDomReady;
if (pageDetect.isNotifications()) {
const notifications = await getNotifications();
diff --git a/source/features/more-dropdown.tsx b/source/features/more-dropdown.tsx
index 310a3942..8f05e3bc 100644
--- a/source/features/more-dropdown.tsx
+++ b/source/features/more-dropdown.tsx
@@ -79,6 +79,6 @@ features.add({
include: [
features.isRepo
],
- load: features.onAjaxedPages,
+ load: features.nowAndOnAjaxedPages,
init
});
diff --git a/source/features/releases-tab.tsx b/source/features/releases-tab.tsx
index 9144cb27..d16abc27 100644
--- a/source/features/releases-tab.tsx
+++ b/source/features/releases-tab.tsx
@@ -1,9 +1,11 @@
import cache from 'webext-storage-cache';
import React from 'dom-chef';
import select from 'select-dom';
+import elementReady from 'element-ready';
import features from '../libs/features';
import * as api from '../libs/api';
import * as icons from '../libs/icons';
+import {appendBefore} from '../libs/dom-utils';
import {getRepoURL, getRepoGQL} from '../libs/utils';
import {isRepoRoot, isReleasesOrTags} from '../libs/page-detect';
@@ -52,7 +54,9 @@ async function init(): Promise<false | void> {
{count === undefined ? '' : <span className="Counter">{count}</span>}
</a>
);
- select('.reponav-dropdown')!.before(releasesTab);
+
+ await elementReady('.pagehead + *'); // Wait for the tab bar to be loaded
+ appendBefore('.reponav', '.reponav-dropdown, [href$="settings"]', releasesTab);
// Update "selected" tab mark
if (isReleasesOrTags()) {
@@ -73,7 +77,7 @@ features.add({
include: [
features.isRepo
],
- load: features.onAjaxedPages,
+ load: features.nowAndOnAjaxedPages,
shortcuts: {
'g r': 'Go to Releases'
},
diff --git a/source/features/sticky-discussion-sidebar.tsx b/source/features/sticky-discussion-sidebar.tsx
index 9ea42519..8d3ad1ef 100644
--- a/source/features/sticky-discussion-sidebar.tsx
+++ b/source/features/sticky-discussion-sidebar.tsx
@@ -1,6 +1,7 @@
import './sticky-discussion-sidebar.css';
import select from 'select-dom';
import debounce from 'debounce-fn';
+import onDomReady from 'dom-loaded';
import features from '../libs/features';
import onUpdatableContentUpdate from '../libs/on-updatable-content-update';
@@ -14,7 +15,8 @@ function updateStickiness(): void {
const handler = debounce(updateStickiness, {wait: 100});
-function init(): void {
+async function init(): Promise<void> {
+ await onDomReady;
updateStickiness();
window.addEventListener('resize', handler);
onUpdatableContentUpdate(select(sideBarSelector)!, updateStickiness);
diff --git a/source/libs/features.tsx b/source/libs/features.tsx
index cc8f718f..0914b60a 100644
--- a/source/libs/features.tsx
+++ b/source/libs/features.tsx
@@ -43,13 +43,22 @@ export interface FeatureDetails {
* Alternatively, use `onAjaxedPagesRaw` if your callback needs to be called at every page
* change (e.g. to "unmount" a feature / listener) regardless of *newness* of the page.
*/
-async function onAjaxedPagesRaw(callback: () => void): Promise<void> {
- await onDomReady;
+function onAjaxedPagesRaw(callback: () => void): void {
document.addEventListener('pjax:end', callback);
callback();
}
function onAjaxedPages(callback: () => void): void {
+ onAjaxedPagesRaw(async () => {
+ await onDomReady;
+ if (!select.exists('has-rgh')) {
+ callback();
+ }
+ });
+}
+
+// Like onAjaxedPages but doesn't wait for `dom-ready`
+function nowAndOnAjaxedPages(callback: () => void): void {
onAjaxedPagesRaw(() => {
if (!select.exists('has-rgh')) {
callback();
@@ -186,6 +195,7 @@ export default {
onNewComments,
onFileListUpdate,
onAjaxedPages,
+ nowAndOnAjaxedPages,
onAjaxedPagesRaw,
// Loading filters