peertube-plugin-ncd-sell-st.../client/common-client-plugin.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-12-13 00:31:35 +00:00
const subPage = require("./pages/subscription");
const successPage = require("./pages/success");
const cancelPage = require("./pages/cancel");
async function register({
registerHook,
peertubeHelpers,
registerClientRoute,
}) {
/**
* Add link admin page
*/
registerHook({
target: "action:router.navigation-end",
handler: async (params) => {
if (params.path.startsWith("/my-account")) {
2023-12-13 15:06:06 +00:00
if (document.getElementById("ncd-subscription-link")) return;
2023-12-13 00:31:35 +00:00
2023-12-13 13:53:34 +00:00
let href = "/p/ncd-my-subscription";
2023-12-13 00:31:35 +00:00
// Get menu container
const menuContainer = document.getElementsByClassName("sub-menu")[0];
// Create link
const content = `
2023-12-13 15:02:03 +00:00
<a _ngcontent-dke-c79="" id="ncd-subscription-link" routerlinkactive="active" class="sub-menu-entry ng-star-inserted" href="${href}">
2023-12-13 15:25:18 +00:00
${await peertubeHelpers.translate("NCTV Storage")}
2023-12-13 00:31:35 +00:00
</a>
`;
// Create node for it
const nodeLink = document.createElement("div");
nodeLink.innerHTML = content.trim();
// Insert to menu container
menuContainer.appendChild(nodeLink.firstChild);
}
},
});
// Register routes
registerClientRoute({
2023-12-13 13:53:34 +00:00
route: "ncd-my-subscription",
2023-12-13 00:31:35 +00:00
onMount: ({ rootEl }) => {
subPage.showPage({rootEl, peertubeHelpers});
},
});
registerClientRoute({
2023-12-13 13:53:34 +00:00
route: "ncd-subscription-success",
2023-12-13 00:31:35 +00:00
onMount: ({ rootEl }) => {
successPage.showPage({rootEl, peertubeHelpers});
},
});
registerClientRoute({
2023-12-13 13:53:34 +00:00
route: "ncd-subscription-cancel",
2023-12-13 00:31:35 +00:00
onMount: ({ rootEl }) => {
cancelPage.showPage({rootEl, peertubeHelpers});
},
});
}
export { register };