${data}`;
popup.style.display = 'block';
overlay.style.display = 'block';
// 获取当前滚动位置并加上偏移量
var scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
targetScrollPosition = scrollPosition + 100;
popup.style.top = (targetScrollPosition + 200) + 'px'; // 设置弹出层顶部位置
document.querySelector('.sslphpzd-popup-close').addEventListener('click', closePopup);
overlay.addEventListener('click', closePopup);
setupCommentForm();
// 加载字体文件和处理字体大小
loadFontAndSetupSlider();
});
}
// 监听滚动事件并防止页面向上滚动超过目标位置
window.addEventListener('scroll', function() {
if (targetScrollPosition !== null) {
var currentScrollPosition = window.pageYOffset || document.documentElement.scrollTop;
if (currentScrollPosition < targetScrollPosition) {
window.scrollTo(0, targetScrollPosition);
}
}
});
function loadFontAndSetupSlider() {
const fontFileUrl = document.getElementById('fontFileUrl').value;
const progressBar = document.querySelector('.progress-bar');
const loadingText = document.querySelector('.loading-text');
// 模拟进度条
let progress = 0;
const interval = setInterval(() => {
if (progress < 90) {
progress += 1;
progressBar.style.width = `${progress}%`;
}
}, 100);
const font = new FontFace('FeiBoZhengDianTi', `url(${fontFileUrl})`);
font.load().then(function(loadedFont) {
document.fonts.add(loadedFont);
document.getElementById('previewArea').style.fontFamily = 'FeiBoZhengDianTi';
clearInterval(interval);
progressBar.style.width = '100%';
setTimeout(() => {
progressBar.remove();
loadingText.remove(); // 字体加载完成后隐藏文本
}, 500);
}).catch(function(error) {
console.error('Failed to load font:', error);
clearInterval(interval);
progressBar.style.width = '0%';
});
// 添加过滤HTML标签的粘贴事件监听器
function filterPaste(event) {
event.preventDefault();
const text = (event.originalEvent || event).clipboardData.getData('text/plain');
document.execCommand('insertText', false, text);
}
// 为可编辑区域添加事件监听器
const editableElements = document.querySelectorAll('[contenteditable="true"]');
editableElements.forEach(element => {
element.addEventListener('paste', filterPaste);
});
// Update font size
const fontSizeSlider = document.getElementById('fontSizeSlider');
const textElement = document.querySelector('.zaofontsslphp-text');
fontSizeSlider.addEventListener('input', function() {
const fontSize = this.value + 'px';
textElement.style.fontSize = fontSize;
});
/*
document.getElementById('fontSizeSlider').addEventListener('input', function() {
const fontSize = this.value + 'px';
document.querySelector('.zaofontsslphp-small-text').style.fontSize = fontSize;
document.querySelector('.zaofontsslphp-large-text').style.fontSize = (parseInt(this.value) * 2) + 'px';
});
*/
}
function closePopup() {
popup.style.display = 'none';
overlay.style.display = 'none';
targetScrollPosition = null; // 关闭弹出层时重置目标滚动位置
}
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const category = this.getAttribute('data-category');
navLinks.forEach(link => link.classList.remove('active'));
this.classList.add('active');
categoryContents.forEach(content => {
content.style.display = 'none';
});
loadCategoryContent(category);
});
});
// 默认显示第一个分类内容
if (navLinks.length > 0) {
navLinks[0].click();
}
});
✓已经复制链接,分享给小伙伴吧~';
document.body.appendChild(successPopup);
const overlay = document.createElement('div');
overlay.classList.add('wujishunsslphplll-overlay');
document.body.appendChild(overlay);
successPopup.style.display = 'block';
overlay.style.display = 'block';
// 设置3秒后自动关闭
setTimeout(() => {
successPopup.style.display = 'none';
overlay.style.display = 'none';
document.body.removeChild(successPopup);
document.body.removeChild(overlay);
}, 2000);
document.querySelector('.wujishunsslphplll-popup-close').addEventListener('click', function() {
successPopup.style.display = 'none';
overlay.style.display = 'none';
document.body.removeChild(successPopup);
document.body.removeChild(overlay);
});
overlay.addEventListener('click', function() {
successPopup.style.display = 'none';
overlay.style.display = 'none';
document.body.removeChild(successPopup);
document.body.removeChild(overlay);
});
}
// 复制文章链接
//收藏
function toggleFavorite(element) {
const postId = element.getAttribute('data-post-id');
const isFavorite = element.getAttribute('data-favorite') === 'true';
fetch('https://www.mfonts.cn/wp-admin/admin-ajax.php?action=handle_favorite', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: `post_id=${postId}`
})
.then(response => response.json())
.then(data => {
if (data.success) {
const iconElement = element.querySelector('img');
const favoriteIcon = element.getAttribute('data-favorite-icon');
const unfavoriteIcon = element.getAttribute('data-unfavorite-icon');
if (data.data.action === 'favorite') {
element.setAttribute('data-favorite', 'true');
element.querySelector('span').textContent = '取消收藏';
iconElement.src = unfavoriteIcon; // 更改为取消收藏的图标
} else {
element.setAttribute('data-favorite', 'false');
element.querySelector('span').textContent = '收藏';
iconElement.src = favoriteIcon; // 更改为收藏的图标
}
} else {
console.error(data.data);
}
})
.catch(error => console.error('Error:', error));
}