-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmofh-javascript.js
More file actions
209 lines (186 loc) · 8.01 KB
/
mofh-javascript.js
File metadata and controls
209 lines (186 loc) · 8.01 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* mofh-javascript v2.0.0
* A modern VistaPanel helper library for MyOwnFreeHost (MOFH) panels.
*
* Authors: SpookyKipper & Deveroonie (original logic)
* Refactored and expanded by GPT-5 (2025)
* License: MIT
*/
const mofh = (() => {
const urlParams = new URLSearchParams(window.location.search);
/* ─────────────────────────────────────────────
* CORE UTILITIES
* ───────────────────────────────────────────── */
const getPageOption = () => urlParams.get('option');
const getUsername = () => document.querySelector('#lblUserNameTxt')?.textContent ?? '';
const getLogo = () => document.querySelector('#imgLogo')?.src ?? '';
const setLogo = (url) => { const logo = document.querySelector('#imgLogo'); if (logo) logo.src = url; };
const setTitle = (title) => { document.title = title; };
const setFavicon = (url) => {
const link = document.createElement('link');
link.rel = 'icon';
link.href = url;
document.head.appendChild(link);
};
const loadStylesheet = (url) => {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = url;
document.head.appendChild(link);
};
/* ─────────────────────────────────────────────
* PAGE MODIFIERS
* ───────────────────────────────────────────── */
const setPHPVersion = (version) => {
if (getPageOption() !== 'accountsettings') return;
const phpCell = document.querySelector('#content > div > table.table > tbody > tr:nth-child(29) > td:nth-child(2)');
if (!phpCell) return;
phpCell.querySelector('a')?.remove();
phpCell.textContent = version;
};
const setSSLInfoText = (text) => {
if (getPageOption() !== 'sslconfigure') return;
const alertBox = document.querySelector('#content > div > div');
if (!alertBox) return;
alertBox.classList.replace('alert-warning', 'alert-info');
alertBox.querySelector('span')?.classList.replace('glyphicon-exclamation-sign', 'glyphicon-info-sign');
const alertText = alertBox.querySelector('div');
if (alertText) alertText.textContent = text;
};
/* ─────────────────────────────────────────────
* ELEMENT UTILITIES
* ───────────────────────────────────────────── */
const hideSidebar = () => {
const sidebar = document.querySelector('#sidebar');
if (sidebar) sidebar.style.display = 'none';
};
const hideFooter = () => {
const footer = document.querySelector('footer');
if (footer) footer.style.display = 'none';
};
const setElementDetails = (featureKey, value, property, sections) => {
sections.forEach(({ items }) => {
items.forEach((item) => {
if (item.feature === featureKey) item[property] = value;
});
});
};
const hideElementById = (id) => {
const elem = document.getElementById(id);
if (elem) elem.style.display = 'none';
};
const showElementById = (id) => {
const elem = document.getElementById(id);
if (elem) elem.style.display = 'block';
};
const addCustomButton = (text, onClick, parentSelector = '#content') => {
const parent = document.querySelector(parentSelector);
if (!parent) return;
const button = document.createElement('button');
button.className = 'btn btn-primary';
button.textContent = text;
button.addEventListener('click', onClick);
parent.appendChild(button);
};
/* ─────────────────────────────────────────────
* NETWORK / API
* ───────────────────────────────────────────── */
const getVPVersion = async () => {
try {
const res = await fetch('https://panel.myownfreehost.net/xml-api/version.php');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return await res.text();
} catch (err) {
console.error('Failed to fetch VP version:', err);
return null;
}
};
const pingDomain = async (domain) => {
try {
const res = await fetch(`https://${domain}`, { mode: 'no-cors' });
return res.ok || res.type === 'opaque';
} catch {
return false;
}
};
const getUserDomains = () => {
const domainCells = document.querySelectorAll('table.table tbody tr td:first-child a');
return Array.from(domainCells).map((a) => a.textContent.trim());
};
/* ─────────────────────────────────────────────
* THEME / UI HELPERS
* ───────────────────────────────────────────── */
const applyDarkMode = () => {
document.body.classList.add('dark-mode');
const darkStyle = document.createElement('style');
darkStyle.textContent = `
body.dark-mode {
background-color: #1a1a1a;
color: #f0f0f0;
}
.table, .panel, .alert {
background-color: #2b2b2b !important;
border-color: #444 !important;
}
`;
document.head.appendChild(darkStyle);
};
const injectCustomBanner = (message, color = '#007bff') => {
const banner = document.createElement('div');
banner.textContent = message;
banner.style.cssText = `
background: ${color};
color: white;
padding: 10px;
text-align: center;
font-weight: 600;
border-radius: 0 0 8px 8px;
`;
document.body.prepend(banner);
};
const toggleLoadingOverlay = (show = true, message = 'Loading...') => {
let overlay = document.querySelector('#mofh-loading-overlay');
if (show) {
if (!overlay) {
overlay = document.createElement('div');
overlay.id = 'mofh-loading-overlay';
overlay.innerHTML = `<div>${message}</div>`;
overlay.style.cssText = `
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.5); display: flex; align-items: center;
justify-content: center; color: white; font-size: 1.5em; z-index: 9999;
`;
document.body.appendChild(overlay);
}
} else {
overlay?.remove();
}
};
/* ─────────────────────────────────────────────
* EXPORT API
* ───────────────────────────────────────────── */
return {
getPageOption,
getUsername,
getLogo,
setLogo,
setTitle,
setFavicon,
loadStylesheet,
setPHPVersion,
setSSLInfoText,
hideSidebar,
hideFooter,
hideElementById,
showElementById,
addCustomButton,
setElementDetails,
getVPVersion,
pingDomain,
getUserDomains,
applyDarkMode,
injectCustomBanner,
toggleLoadingOverlay,
};
})();