Skip to content

Commit 70fe510

Browse files
author
Mike Castle
committed
Enhance Page to take a PageDetails upon construction.
With #private variables, we need to move away from having code in the base class that can use overrides in the subclasses. Instead, we will need to pass them in through the constructor or other mechanisms. Here, we are adding some items similar to what we already use, but can do differently. Issue #130. ␄
1 parent 0dfd511 commit 70fe510

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Diff for: linkedin-tool.user.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,8 @@
17511751
*/
17521752
_pathname;
17531753

1754+
#pageReadyCSS
1755+
17541756
/**
17551757
* @type {string} - CSS selector for capturing clicks on this page. If
17561758
* overridden, then the class should also provide a _onClick() method.
@@ -1788,12 +1790,34 @@
17881790
condition: '!inputFocus && !inDialog',
17891791
};
17901792

1791-
/** Create a Page instance. */
1792-
constructor() {
1793+
/**
1794+
* @typedef {object} PageDetails
1795+
* @property {string|RegExp} [pathname=RegExp] - Pathname portion of the
1796+
* URL this page should handle.
1797+
* @property {string} [pageReadyCSS='body'] - CSS selector that is used to
1798+
* detect that the page is loaded enough to activate.
1799+
*/
1800+
1801+
/**
1802+
* Create a Page instance.
1803+
* @param {PageDetails} details - Details about the instance.
1804+
*/
1805+
constructor(details = {}) {
17931806
if (new.target === Page) {
17941807
throw new TypeError('Abstract class; do not instantiate directly.');
17951808
}
1809+
if (details.pathname) {
1810+
if (details.pathname instanceof RegExp) {
1811+
this.#pathnameRE = details.pathname;
1812+
} else {
1813+
this.#pathnameRE = RegExp(`^${details.pathname}$`, 'u');
1814+
}
1815+
}
1816+
({
1817+
pageReadyCSS: this.#pageReadyCSS = 'body',
1818+
} = details);
17961819
this.#logger = new Logger(this.constructor.name);
1820+
this.#logger.log('Base page constructed', this);
17971821
}
17981822

17991823
/**

0 commit comments

Comments
 (0)