re-code the userscript
Some checks failed
Deploy App / docker (ubuntu-latest) (push) Failing after 7s
Some checks failed
Deploy App / docker (ubuntu-latest) (push) Failing after 7s
This commit is contained in:
34
src/pages/page-handler.ts
Normal file
34
src/pages/page-handler.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import Page from "./page";
|
||||
import PlayerPage from "./impl/player-page";
|
||||
import {pageChangeCallback} from "../common/page-utils";
|
||||
|
||||
export default class PageHandler {
|
||||
private pages: Page[] = [];
|
||||
|
||||
constructor() {
|
||||
// Register the pages to handle
|
||||
this.registerPage(new PlayerPage());
|
||||
|
||||
// Handle page changes
|
||||
pageChangeCallback((path) => {
|
||||
console.log(`Page changed to: ${path}`);
|
||||
|
||||
for (let page of this.pages) {
|
||||
if (path.startsWith(page.route)) {
|
||||
console.log(`Handling page: ${page.route}`);
|
||||
page.onLoad();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a page to be handled
|
||||
*
|
||||
* @param page The page to register
|
||||
*/
|
||||
private registerPage(page: Page) {
|
||||
console.log(`Registered page: ${page.route}`)
|
||||
this.pages.push(page);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user