asdsd
This commit is contained in:
@@ -1,15 +1,35 @@
|
|||||||
(function () {
|
(function () {
|
||||||
const root = document.getElementById('mining-checker-app');
|
window.initMiningCheckerApp = function initMiningCheckerApp(rootNode, options) {
|
||||||
|
const root = rootNode || document.getElementById('mining-checker-app');
|
||||||
if (!root || !window.React || !window.ReactDOM) {
|
if (!root || !window.React || !window.ReactDOM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root.dataset.moduleInitialized === '1') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
root.dataset.moduleInitialized = '1';
|
||||||
|
|
||||||
|
const React = window.React;
|
||||||
|
const ReactDOM = window.ReactDOM;
|
||||||
const h = React.createElement;
|
const h = React.createElement;
|
||||||
const { useEffect, useMemo, useRef, useState } = React;
|
const { useEffect, useMemo, useRef, useState } = React;
|
||||||
const apiBase = root.dataset.apiBase || '/api/mining-checker/v1';
|
const normalizedOptions = options && typeof options === 'object' ? options : {};
|
||||||
const initialProjectKey = root.dataset.defaultProjectKey || 'doge-main';
|
const apiBase = normalizedOptions.apiBase || root.dataset.apiBase || '/api/mining-checker/v1';
|
||||||
const initialActiveTab = String(root.dataset.activeView || 'overview').trim() || 'overview';
|
const initialProjectKey = normalizedOptions.defaultProjectKey || root.dataset.defaultProjectKey || 'doge-main';
|
||||||
|
const initialActiveTab = String(normalizedOptions.activeView || root.dataset.activeView || 'overview').trim() || 'overview';
|
||||||
const configuredSections = (() => {
|
const configuredSections = (() => {
|
||||||
|
const optionSections = Array.isArray(normalizedOptions.sections) ? normalizedOptions.sections : null;
|
||||||
|
if (optionSections) {
|
||||||
|
return optionSections
|
||||||
|
.map((section) => {
|
||||||
|
const key = section && typeof section.key === 'string' ? section.key.trim() : '';
|
||||||
|
const label = section && typeof section.label === 'string' ? section.label.trim() : '';
|
||||||
|
return key && label ? [key, label] : null;
|
||||||
|
})
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(root.dataset.sectionsJson || '[]');
|
const parsed = JSON.parse(root.dataset.sectionsJson || '[]');
|
||||||
if (!Array.isArray(parsed)) {
|
if (!Array.isArray(parsed)) {
|
||||||
@@ -26,7 +46,8 @@
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
const initialDebugMode = document.body && document.body.dataset.moduleDebugEnabled === '1';
|
const initialDebugMode = normalizedOptions.moduleDebugEnabled === true
|
||||||
|
|| (document.body && document.body.dataset.moduleDebugEnabled === '1');
|
||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
const pattern = `; ${document.cookie}`;
|
const pattern = `; ${document.cookie}`;
|
||||||
const parts = pattern.split(`; ${name}=`);
|
const parts = pattern.split(`; ${name}=`);
|
||||||
@@ -3264,4 +3285,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReactDOM.createRoot(root).render(h(App));
|
ReactDOM.createRoot(root).render(h(App));
|
||||||
|
};
|
||||||
|
|
||||||
|
const standaloneRoot = document.getElementById('mining-checker-app');
|
||||||
|
if (standaloneRoot) {
|
||||||
|
window.initMiningCheckerApp(standaloneRoot);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ $sections = array_values(array_filter(
|
|||||||
static fn (mixed $section): bool => is_array($section)
|
static fn (mixed $section): bool => is_array($section)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$assetVersion = static function (string $relativePath): string {
|
||||||
|
$fullPath = __DIR__ . '/' . ltrim($relativePath, '/');
|
||||||
|
$mtime = is_file($fullPath) ? filemtime($fullPath) : false;
|
||||||
|
|
||||||
|
return $mtime === false ? '0' : (string) $mtime;
|
||||||
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'app_id' => 'mining-checker',
|
'app_id' => 'mining-checker',
|
||||||
'title' => (string) ($manifest['title'] ?? 'Mining-Checker'),
|
'title' => (string) ($manifest['title'] ?? 'Mining-Checker'),
|
||||||
@@ -45,12 +52,12 @@ return [
|
|||||||
],
|
],
|
||||||
'assets' => [
|
'assets' => [
|
||||||
'styles' => [
|
'styles' => [
|
||||||
['href' => '/module-assets/index.php?module=mining-checker&path=assets/css/app.css'],
|
['href' => '/module-assets/index.php?module=mining-checker&path=assets/css/app.css&v=' . rawurlencode($assetVersion('assets/css/app.css'))],
|
||||||
],
|
],
|
||||||
'scripts' => [
|
'scripts' => [
|
||||||
['src' => 'https://unpkg.com/react@18/umd/react.production.min.js', 'crossorigin' => true],
|
['src' => 'https://unpkg.com/react@18/umd/react.production.min.js', 'crossorigin' => true],
|
||||||
['src' => 'https://unpkg.com/react-dom@18/umd/react-dom.production.min.js', 'crossorigin' => true],
|
['src' => 'https://unpkg.com/react-dom@18/umd/react-dom.production.min.js', 'crossorigin' => true],
|
||||||
['src' => '/module-assets/index.php?module=mining-checker&path=assets/js/app.js'],
|
['src' => '/module-assets/index.php?module=mining-checker&path=assets/js/app.js&v=' . rawurlencode($assetVersion('assets/js/app.js'))],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ if ($designRaw !== false) {
|
|||||||
|
|
||||||
$moduleConfig = require dirname(__DIR__) . '/config/module.php';
|
$moduleConfig = require dirname(__DIR__) . '/config/module.php';
|
||||||
$defaultProjectKey = (string) ($moduleConfig['default_project_key'] ?? 'doge-main');
|
$defaultProjectKey = (string) ($moduleConfig['default_project_key'] ?? 'doge-main');
|
||||||
|
$assetVersion = static function (string $relativePath): string {
|
||||||
|
$fullPath = dirname(__DIR__) . '/' . ltrim($relativePath, '/');
|
||||||
|
$mtime = is_file($fullPath) ? filemtime($fullPath) : false;
|
||||||
|
|
||||||
|
return $mtime === false ? '0' : (string) $mtime;
|
||||||
|
};
|
||||||
$sections = is_array($design['sections'] ?? null) ? $design['sections'] : [];
|
$sections = is_array($design['sections'] ?? null) ? $design['sections'] : [];
|
||||||
$activeView = trim((string) ($_GET['view'] ?? 'overview'));
|
$activeView = trim((string) ($_GET['view'] ?? 'overview'));
|
||||||
$sectionKeys = array_values(array_filter(array_map(
|
$sectionKeys = array_values(array_filter(array_map(
|
||||||
@@ -77,7 +83,7 @@ $sectionsJson = json_encode($sections, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_S
|
|||||||
padding: 18px;
|
padding: 18px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="/module-assets/index.php?module=mining-checker&path=assets/css/app.css">
|
<link rel="stylesheet" href="/module-assets/index.php?module=mining-checker&path=assets/css/app.css&v=<?= htmlspecialchars($assetVersion('assets/css/app.css'), ENT_QUOTES) ?>">
|
||||||
</head>
|
</head>
|
||||||
<body data-module-debug-enabled="0">
|
<body data-module-debug-enabled="0">
|
||||||
<div class="mining-module-shell">
|
<div class="mining-module-shell">
|
||||||
@@ -92,6 +98,6 @@ $sectionsJson = json_encode($sections, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_S
|
|||||||
|
|
||||||
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
||||||
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
||||||
<script src="/module-assets/index.php?module=mining-checker&path=assets/js/app.js"></script>
|
<script src="/module-assets/index.php?module=mining-checker&path=assets/js/app.js&v=<?= htmlspecialchars($assetVersion('assets/js/app.js'), ENT_QUOTES) ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user