// javascript/menu-loader.js
// 仅保留页脚修改功能
(function () {
/* ========== 页脚修改 ========== */
function debugFooter(msg) {
console.log('[页脚修改] ' + msg);
}
function modifyFooter() {
// 预加载 ZWY logo
var preloadImg = new Image();
preloadImg.src = '/Artocarpus/images/ZWY_LOGO.png';
// 查找页脚表格
var footerTables = document.querySelectorAll(
'table[width="1200px"][height="100%"], table[align="center"][width="1200px"]'
);
if (footerTables.length === 0) {
var allTables = document.querySelectorAll('table');
for (var i = 0; i < allTables.length; i++) {
if (allTables[i].textContent.indexOf('ArtocarpusGD is developed by') !== -1) {
footerTables = [allTables[i]];
break;
}
}
}
if (footerTables.length === 0) {
debugFooter('未找到页脚表格');
return;
}
var footerTable = footerTables[0];
var footerRow = footerTable.querySelector('tr');
if (!footerRow) {
debugFooter('未找到表格行');
return;
}
var cells = footerRow.querySelectorAll('td');
if (cells.length !== 2) {
debugFooter('未找到预期的2个单元格');
return;
}
var textCell = cells[0];
var logoCell = cells[1];
try {
var originalHeight = footerRow.offsetHeight;
footerRow.innerHTML = '';
footerRow.style.display = 'flex';
footerRow.style.alignItems = 'center';
footerRow.style.justifyContent = 'space-between';
// 左侧 ZWY logo
var zwyCell = document.createElement('td');
zwyCell.style.flex = '0 0 15%';
zwyCell.style.display = 'flex';
zwyCell.style.justifyContent = 'flex-start';
zwyCell.style.alignItems = 'center';
zwyCell.style.height = originalHeight + 'px';
var zwyLink = document.createElement('a');
zwyLink.href = 'http://www.scib.ac.cn';
zwyLink.target = '_blank';
zwyLink.style.display = 'flex';
zwyLink.style.alignItems = 'center';
zwyLink.style.justifyContent = 'center';
zwyLink.style.height = '100%';
var zwyImg = document.createElement('img');
zwyImg.src = '/Artocarpus/images/ZWY_LOGO.png';
zwyImg.alt = 'ZWY logo';
zwyImg.style.maxWidth = '80px';
zwyImg.style.maxHeight = '80px';
zwyImg.style.objectFit = 'contain';
zwyImg.style.border = '0';
zwyLink.appendChild(zwyImg);
zwyCell.appendChild(zwyLink);
// 中间文本内容
var centerCell = document.createElement('td');
centerCell.style.flex = '1';
centerCell.style.display = 'flex';
centerCell.style.flexDirection = 'column';
centerCell.style.justifyContent = 'center';
centerCell.style.alignItems = 'center';
centerCell.style.textAlign = 'center';
centerCell.style.height = originalHeight + 'px';
centerCell.style.padding = '0 20px';
var textDiv = document.createElement('div');
textDiv.innerHTML = textCell.innerHTML;
centerCell.appendChild(textDiv);
// 右侧原有 logo
var rightCell = document.createElement('td');
rightCell.style.flex = '0 0 15%';
rightCell.style.display = 'flex';
rightCell.style.justifyContent = 'flex-end';
rightCell.style.alignItems = 'center';
rightCell.style.height = originalHeight + 'px';
var logoWrapper = document.createElement('div');
logoWrapper.style.display = 'flex';
logoWrapper.style.justifyContent = 'flex-end';
logoWrapper.style.alignItems = 'center';
logoWrapper.style.height = '100%';
var originalLogo = logoCell.querySelector('img');
if (originalLogo) {
var clonedLogo = originalLogo.cloneNode(true);
clonedLogo.style.maxWidth = '80px';
clonedLogo.style.maxHeight = '80px';
clonedLogo.style.objectFit = 'contain';
logoWrapper.appendChild(clonedLogo);
} else {
logoWrapper.innerHTML = logoCell.innerHTML;
var logoImg = logoWrapper.querySelector('img');
if (logoImg) {
logoImg.style.maxWidth = '80px';
logoImg.style.maxHeight = '80px';
logoImg.style.objectFit = 'contain';
}
}
rightCell.appendChild(logoWrapper);
// 添加三列到页脚行
footerRow.appendChild(zwyCell);
footerRow.appendChild(centerCell);
footerRow.appendChild(rightCell);
debugFooter('成功创建完美居中的三列布局页脚');
} catch (e) {
debugFooter('修改页脚时出错: ' + e.message);
// 出错时恢复原始内容
footerRow.innerHTML = '';
footerRow.appendChild(textCell);
footerRow.appendChild(logoCell);
}
}
/* ========== 初始化:使用 DOMContentLoaded ========== */
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function () {
modifyFooter();
});
} else {
// 如果脚本加载时DOM已经ready,立即执行
modifyFooter();
}
})();