/* docker run -v ./script.js:/app/script.js --rm playwright:1.47.0 */ import type { Page } from "playwright"; import login from "../login.ts"; import forms from "../forms.ts"; async function removeLoginForgottenPasswordLink( { page, dolibarrAddress }: { page: Page; dolibarrAddress: string; imgFolderPath: string; }, ): Promise { await page.goto(`${dolibarrAddress}/admin/security.php`); const label = `Cacher le lien "Mot de passe oublié" sur la page de connexion`; const row = page.locator("tr").filter({ has: page.locator("td", { hasText: label }), }); const enableLink = row.locator("a", { hasText: /^Activer$/, hasNotText: /^Désactiver$/, }); const disableLink = row.locator("a", { hasText: /^Désactiver$/, hasNotText: /^Activer$/, }); if (await enableLink.isVisible()) { await enableLink.click(); } else if (!await disableLink.isVisible()) { throw new Error("Enable/Disable link not found"); } } async function setupLoginPage( globalCtx: { page: Page; dolibarrAddress: string; imgFolderPath: string; }, { removeHelpLink, HTMLMessage, backgroundImage }: { removeHelpLink?: boolean; HTMLMessage?: string; backgroundImage?: string; }, ): Promise { const { page, dolibarrAddress } = globalCtx; await page.goto(`${dolibarrAddress}/admin/ihm.php?mode=login`); await forms.fillForm( globalCtx, { HTMLMessage, backgroundImage, removeHelpLink: (removeHelpLink||false).toString(), }, new Map([ ["removeHelpLink",`Cacher le lien «Besoin d'aide ou assistance» sur la page de connexion:toggle`], ["backgroundImage","imagebackground:file"], ["HTMLMessage", "main_home:cke"] ]), 1, ); } async function setGlobalCSS( { page, dolibarrAddress, imgFolderPath }: { page: Page; dolibarrAddress: string; imgFolderPath: string; }, cssStyleSheet: string) { await page.goto(`${dolibarrAddress}/admin/ihm.php?mode=css`); await forms.fillForm( {page, imgFolderPath}, {cssStyleSheet}, new Map([ ["cssStyleSheet","MAIN_IHM_CUSTOM_CSSaceeditorid:ace"] ]), 1, ) } async function setupDisplay( globalCtx: { page: Page; dolibarrAddress: string; adminCredentials: { username: string; password: string }; imgFolderPath: string; }, ): Promise { await login.doAdminLogin(globalCtx); // await removeLoginForgottenPasswordLink(globalCtx); // await setupLoginPage(globalCtx, { // removeHelpLink: true, // HTMLMessage: ` //
Bienvenue chez Gabriel Radureau
// l'archange du code
// 🏹💻🪽
// Pariez sur le bon sagitaire
// `.trim(), // backgroundImage: "$IMG/loginBackground.jpeg", // }); await setGlobalCSS(globalCtx, ` body { color: black; } `.trim()); } export default { setupDisplay, removeLoginForgottenPasswordLink, setupLoginPage, };