Files
sisvietnamvn_01/sisvietnamvn_main/add_tab_script.py
T

53 lines
1.8 KiB
Python

import os
templates_to_update = [
'src/main/resources/templates/dao-tao-detail.html',
'src/main/resources/templates/posts/full-width.html',
'src/main/resources/templates/posts/livestream.html',
'src/main/resources/templates/posts/sidebar.html',
'src/main/resources/templates/posts/standard.html'
]
switch_script = """
<script>
document.addEventListener('click', function(e) {
if (e.target.classList.contains('custom-tab-btn')) {
var btn = e.target;
var container = btn.closest('.custom-tabs-wrapper');
if (!container) return;
var idx = btn.getAttribute('data-tab-idx');
container.querySelectorAll('.custom-tab-btn').forEach(function(b) {
b.classList.remove('active');
b.style.background = '#f8f9fa';
b.style.color = 'black';
});
btn.classList.add('active');
btn.style.background = '#0055a5';
btn.style.color = 'white';
container.querySelectorAll('.custom-tab-panel').forEach(function(p) {
p.style.display = 'none';
});
var activePanel = container.querySelector('.custom-tab-panel[data-tab-idx="' + idx + '"]');
if (activePanel) activePanel.style.display = 'block';
}
});
</script>
"""
for filepath in templates_to_update:
if not os.path.exists(filepath):
continue
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
if "document.addEventListener('click', function(e) {" not in content:
content = content.replace("</body>", switch_script + "</body>")
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
print(f"Added script to {filepath}")
else:
print(f"Script already in {filepath}")