Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ features.add({
/** Whether to wait for DOM ready before runnin `init`. `false` makes `init` run right as soon as `body` is found. @default true */
waitForDomReady: false,

/** Whether to re-run `init` on pages loaded via AJAX. @default true */
repeatOnAjax: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to give an example of using oneTime here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about it, but it's not necessary


/** Rarely needed: When pressing the back button, the DOM and listeners are still there, so normally `init` isn’t called again. If this is true, it’s called anyway. @default false */
repeatOnAjaxEvenOnBackButton: true,
repeatOnBackButton: true,
include: [
pageDetect.isUserProfile,
pageDetect.isRepo
Expand Down
4 changes: 2 additions & 2 deletions source/features/clean-rich-text-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './clean-rich-text-editor.css';
import select from 'select-dom';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '.';
Expand Down Expand Up @@ -28,6 +29,5 @@ void features.add({
pageDetect.isRepo
],
waitForDomReady: false,
repeatOnAjax: false,
init: hideButtons
init: onetime(hideButtons)
});
4 changes: 2 additions & 2 deletions source/features/close-out-of-view-modals.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import onetime from 'onetime';
import delegate from 'delegate-it';

import features from '.';
Expand Down Expand Up @@ -31,6 +32,5 @@ void features.add({
screenshot: 'https://user-images.githubusercontent.com/1402241/37022353-531c676e-2155-11e8-96cc-80d934bb22e0.gif'
}, {
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/comment-fields-keyboard-shortcuts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';

Expand Down Expand Up @@ -75,6 +76,5 @@ void features.add({
pageDetect.hasRichTextEditor
],
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
2 changes: 1 addition & 1 deletion source/features/copy-on-y.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void features.add({
pageDetect.isSingleFile
],
waitForDomReady: false,
repeatOnAjaxEvenOnBackButton: true,
repeatOnBackButton: true,
init,
deinit
});
4 changes: 2 additions & 2 deletions source/features/deprioritize-marketplace-link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import domLoaded from 'dom-loaded';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';
Expand Down Expand Up @@ -30,6 +31,5 @@ void features.add({
pageDetect.isGist
],
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/embed-gist-via-iframe.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import select from 'select-dom';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '.';
Expand Down Expand Up @@ -32,6 +33,5 @@ void features.add({
include: [
pageDetect.isSingleGist
],
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/esc-to-deselect-line.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '.';
Expand Down Expand Up @@ -31,6 +32,5 @@ void features.add({
pageDetect.hasCode
],
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
3 changes: 1 addition & 2 deletions source/features/file-finder-buffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,5 @@ void features.add({
pageDetect.isRepo
],
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
5 changes: 3 additions & 2 deletions source/features/hide-navigation-hover-highlight.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import './hide-navigation-hover-highlight.css';
import onetime from 'onetime';

import features from '.';

const className = 'rgh-no-navigation-highlight';
Expand All @@ -16,6 +18,5 @@ void features.add({
screenshot: false
}, {
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/hide-own-stars.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import select from 'select-dom';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '.';
Expand All @@ -21,6 +22,5 @@ void features.add({
pageDetect.isDashboard
],
onlyAdditionalListeners: true,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/hide-useless-newsfeed-events.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './hide-useless-newsfeed-events.css';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '.';
Expand All @@ -16,6 +17,5 @@ void features.add({
pageDetect.isDashboard
],
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/hide-watch-and-fork-count.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './hide-watch-and-fork-count.css';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '.';
Expand All @@ -16,6 +17,5 @@ void features.add({
pageDetect.isRepo
],
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/improve-shortcut-help.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';

import features from '.';
import {isEditable} from '../helpers/dom-utils';
Expand Down Expand Up @@ -66,6 +67,5 @@ void features.add({
screenshot: 'https://user-images.githubusercontent.com/29176678/36999174-9f07d33e-20bf-11e8-83e3-b3a9908a4b5f.png'
}, {
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
20 changes: 7 additions & 13 deletions source/features/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ interface FeatureLoader extends Partial<InternalRunConfig> {
/** Whether to wait for DOM ready before runnin `init`. `false` makes `init` run right as soon as `body` is found. @default true */
waitForDomReady?: false;

/** Whether to re-run `init` on pages loaded via AJAX. @default true */
repeatOnAjax?: false;

/** When pressing the back button, the DOM and listeners are still there, so normally `init` isn’t called again. If this is true, it’s called anyway. @default false */
repeatOnAjaxEvenOnBackButton?: true;
repeatOnBackButton?: true;

/** When true, don’t run the `init` on page load but only add the `additionalListeners`. @default false */
onlyAdditionalListeners?: true;
Expand Down Expand Up @@ -206,9 +203,8 @@ const add = async (meta?: FeatureMeta, ...loaders: FeatureLoader[]): Promise<voi
exclude = [], // Default: nothing
init,
deinit,
repeatOnAjax = true,
waitForDomReady = true,
repeatOnAjaxEvenOnBackButton = false,
repeatOnBackButton = false,
onlyAdditionalListeners = false,
additionalListeners = []
} = loader;
Expand All @@ -230,13 +226,11 @@ const add = async (meta?: FeatureMeta, ...loaders: FeatureLoader[]): Promise<voi
void setupPageLoad(id, details);
}

if (repeatOnAjax) {
document.addEventListener('pjax:end', () => {
if (repeatOnAjaxEvenOnBackButton || !select.exists('has-rgh')) {
void setupPageLoad(id, details);
}
});
}
document.addEventListener('pjax:end', () => {
if (repeatOnBackButton || !select.exists('has-rgh')) {
void setupPageLoad(id, details);
}
});
}
};

Expand Down
4 changes: 2 additions & 2 deletions source/features/infinite-scroll.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import select from 'select-dom';
import onetime from 'onetime';
import debounce from 'debounce-fn';
import * as pageDetect from 'github-url-detection';

Expand Down Expand Up @@ -65,6 +66,5 @@ void features.add({
pageDetect.isDashboard
],
onlyAdditionalListeners: true,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/linkify-labels-on-dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import {wrap} from '../helpers/dom-utils';
Expand All @@ -26,6 +27,5 @@ void features.add({
pageDetect.isDashboard
],
onlyAdditionalListeners: true,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/linkify-user-edit-history-popup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'dom-chef';
import onetime from 'onetime';
import {observe} from 'selector-observer';
import * as pageDetect from 'github-url-detection';

Expand All @@ -24,10 +25,9 @@ void features.add({
description: 'Linkifies the username in the edit history popup.',
screenshot: 'https://user-images.githubusercontent.com/1402241/88917988-9ebb7480-d260-11ea-8690-0a3440f1ebbc.png'
}, {
init,
include: [
pageDetect.isIssue,
pageDetect.isPRConversation
],
repeatOnAjax: false
init: onetime(init)
});
5 changes: 3 additions & 2 deletions source/features/monospace-textareas.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import './monospace-textareas.css';
import onetime from 'onetime';

import features from '.';

function init(): void {
Expand All @@ -11,6 +13,5 @@ void features.add({
screenshot: false
}, {
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/one-key-formatting.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import onetime from 'onetime';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import * as textFieldEdit from 'text-field-edit';
Expand Down Expand Up @@ -42,6 +43,5 @@ void features.add({
pageDetect.hasCode
],
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/open-issue-to-latest-comment.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '.';
Expand Down Expand Up @@ -34,6 +35,5 @@ void features.add({
pageDetect.isDashboard
],
onlyAdditionalListeners: true,
repeatOnAjax: false,
init: initDashboard
init: onetime(initDashboard)
});
4 changes: 2 additions & 2 deletions source/features/parse-backticks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './parse-backticks.css';
import onetime from 'onetime';
import {observe} from 'selector-observer';

import features from '.';
Expand Down Expand Up @@ -47,6 +48,5 @@ void features.add({
description: 'Renders text in `backticks` in issue titles, commit titles and more places.',
screenshot: 'https://user-images.githubusercontent.com/170270/55060505-31179b00-50a4-11e9-99a9-c3691ba38d66.png'
}, {
init,
repeatOnAjax: false
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/profile-hotkey.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import select from 'select-dom';
import onetime from 'onetime';

import features from '.';
import {getUsername} from '../github-helpers';
Expand All @@ -20,6 +21,5 @@ void features.add({
'g m': 'Go to Profile'
}
}, {
repeatOnAjax: false,
init
init: onetime(init)
});
4 changes: 2 additions & 2 deletions source/features/recently-pushed-branches-enhancements.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './recently-pushed-branches-enhancements.css';
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '.';
Expand Down Expand Up @@ -59,8 +60,7 @@ void features.add({
include: [
pageDetect.isRepo
],
repeatOnAjax: false,
init
init: onetime(init)
}, {
include: [
pageDetect.isRepo
Expand Down
4 changes: 2 additions & 2 deletions source/features/remove-projects-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'dom-chef';
import select from 'select-dom';
import onetime from 'onetime';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';

Expand Down Expand Up @@ -82,7 +83,6 @@ void features.add({
pageDetect.isRepo,
pageDetect.isOrganizationProfile
],
repeatOnAjax: false,
waitForDomReady: false,
init: addNewProjectLink
init: onetime(addNewProjectLink)
});
4 changes: 2 additions & 2 deletions source/features/selection-in-new-tab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import select from 'select-dom';
import onetime from 'onetime';

import features from '.';
import {isEditable} from '../helpers/dom-utils';
Expand Down Expand Up @@ -28,6 +29,5 @@ void features.add({
}
}, {
waitForDomReady: false,
repeatOnAjax: false,
init
init: onetime(init)
});
Loading