Skip to content

Commit 8cbf6ce

Browse files
author
Mike Castle
committed
Have Page use the pathname passed in via details.
Issues #130, #149. ␄
1 parent f5fb4fd commit 8cbf6ce

File tree

1 file changed

+22
-46
lines changed

1 file changed

+22
-46
lines changed

Diff for: linkedin-tool.user.js

+22-46
Original file line numberDiff line numberDiff line change
@@ -1714,19 +1714,8 @@
17141714
*/
17151715
class Page {
17161716

1717-
// The immediate following can be set in subclasses.
1718-
1719-
/**
1720-
* @type {string|RegExp} - What pathname part of the URL this page should
1721-
* handle. The special case of null is used by the {@link SPA} class to
1722-
* represent global keys.
1723-
*/
1724-
_pathname;
1725-
17261717
#pageReadySelector
17271718

1728-
// Private members.
1729-
17301719
/** @type {SPA} - SPA instance managing this instance. */
17311720
#spa;
17321721

@@ -1750,10 +1739,28 @@
17501739
condition: '!inputFocus && !inDialog',
17511740
};
17521741

1742+
/**
1743+
* Turn a pathname into a RegExp.
1744+
* @param {string|RegExp} pathname - A pathname to convert.
1745+
* @returns {RegExp} - A converted pathname.
1746+
*/
1747+
#computePathname = (pathname) => {
1748+
const me = 'computePath';
1749+
this.logger.entered(me, pathname);
1750+
let pathnameRE = /.*/u;
1751+
if (pathname instanceof RegExp) {
1752+
pathnameRE = pathname;
1753+
} else if (pathname) {
1754+
pathnameRE = RegExp(`^${pathname}$`, 'u');
1755+
}
1756+
this.logger.leaving(me, pathnameRE);
1757+
return pathnameRE;
1758+
}
1759+
17531760
/**
17541761
* @typedef {object} PageDetails
1755-
* @property {string|RegExp} [pathname=RegExp] - Pathname portion of the
1756-
* URL this page should handle.
1762+
* @property {string|RegExp} [pathname=RegExp(.*)] - Pathname portion of
1763+
* the URL this page should handle.
17571764
* @property {string} [pageReadySelector='body'] - CSS selector that is
17581765
* used to detect that the page is loaded enough to activate.
17591766
*/
@@ -1763,17 +1770,11 @@
17631770
if (new.target === Page) {
17641771
throw new TypeError('Abstract class; do not instantiate directly.');
17651772
}
1766-
if (details.pathname) {
1767-
if (details.pathname instanceof RegExp) {
1768-
this.#pathnameRE = details.pathname;
1769-
} else {
1770-
this.#pathnameRE = RegExp(`^${details.pathname}$`, 'u');
1771-
}
1772-
}
1773+
this.#logger = new Logger(this.constructor.name);
1774+
this.#pathnameRE = this.#computePathname(details.pathname);
17731775
({
17741776
pageReadySelector: this.#pageReadySelector = 'body',
17751777
} = details);
1776-
this.#logger = new Logger(this.constructor.name);
17771778
this.#logger.log('Base page constructed', this);
17781779
}
17791780

@@ -1826,16 +1827,6 @@
18261827

18271828
/** @type {RegExp} */
18281829
get pathname() {
1829-
if (!this.#pathnameRE) {
1830-
if (this._pathname instanceof RegExp) {
1831-
this.#pathnameRE = this._pathname;
1832-
} else if (this._pathname) {
1833-
this.#pathnameRE = RegExp(`^${this._pathname}$`, 'u');
1834-
} else {
1835-
// New global
1836-
this.#pathnameRE = /.*/u;
1837-
}
1838-
}
18391830
return this.#pathnameRE;
18401831
}
18411832

@@ -1941,8 +1932,6 @@
19411932
*/
19421933
class Global extends Page {
19431934

1944-
_pathname = null;
1945-
19461935
/**
19471936
* Click on the requested link in the global nav bar.
19481937
* @param {string} item - Portion of the link to match.
@@ -2023,8 +2012,6 @@
20232012
/** Class for handling the Posts feed. */
20242013
class Feed extends Page {
20252014

2026-
_pathname = '/feed/';
2027-
20282015
#tabSnippet = SPA._parseSeq2('tab'); // eslint-disable-line no-use-before-define
20292016

20302017
#postScroller = null;
@@ -2438,8 +2425,6 @@
24382425
*/
24392426
class MyNetwork extends Page {
24402427

2441-
_pathname = '/mynetwork/';
2442-
24432428
#sectionScroller
24442429
#cardScroller
24452430
#currentSectionText
@@ -2697,8 +2682,6 @@
26972682
/** Class for handling the Invitation manager page. */
26982683
class InvitationManager extends Page {
26992684

2700-
_pathname = '/mynetwork/invitation-manager/';
2701-
27022685
#inviteScroller
27032686
#currentInviteText
27042687

@@ -2882,8 +2865,6 @@
28822865
*/
28832866
class Jobs extends Page {
28842867

2885-
_pathname = '/jobs/';
2886-
28872868
#sectionScroller = null;
28882869
#jobScroller = null;
28892870

@@ -3306,9 +3287,6 @@
33063287
/** Class for handling Job collections. */
33073288
class JobCollections extends Page {
33083289

3309-
// eslint-disable-next-line prefer-regex-literals
3310-
_pathname = RegExp('^/jobs/(?:collections|search)/.*', 'u');
3311-
33123290
#lastScroller
33133291

33143292
#jobScroller = null;
@@ -3467,8 +3445,6 @@
34673445
/** Class for handling the Notifications page. */
34683446
class Notifications extends Page {
34693447

3470-
_pathname = '/notifications/';
3471-
34723448
#notificationScroller = null;
34733449

34743450
/** @type {Scroller~What} */

0 commit comments

Comments
 (0)