-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathbackend-ai-homepage-link.js
More file actions
48 lines (41 loc) · 1.39 KB
/
backend-ai-homepage-link.js
File metadata and controls
48 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* global document, MutationObserver */
/**
* E2E fixture for the login-screen homepage-link plugin.
*
* Served via `page.route` in `login-plugin.spec.ts`. Pure side-effect ES
* module — IIFE that finds the login form in DOM and appends a "Visit
* backend.ai" link. No exports.
*/
(function () {
'use strict';
const LINK_CLASS = 'bai-homepage-link';
const HREF = 'https://www.backend.ai/';
const LABEL = 'Visit backend.ai';
function inject() {
const form =
document.querySelector('.ant-modal-content form') ||
document.querySelector('.ant-modal-body form') ||
document.querySelector('form.ant-form') ||
document.querySelector('form');
if (!form) return false;
if (form.querySelector('.' + LINK_CLASS)) return true;
const wrapper = document.createElement('div');
wrapper.className = LINK_CLASS;
wrapper.style.textAlign = 'center';
wrapper.style.marginTop = '8px';
wrapper.style.fontSize = '13px';
const link = document.createElement('a');
link.href = HREF;
link.target = '_blank';
link.rel = 'noopener noreferrer';
link.textContent = LABEL;
wrapper.appendChild(link);
form.appendChild(wrapper);
return true;
}
if (inject()) return;
const observer = new MutationObserver(() => {
if (inject()) observer.disconnect();
});
observer.observe(document.body, { childList: true, subtree: true });
})();