document.addEventListener('DOMContentLoaded', function() {
// 1. BOOKMARK LOGIC
const bookmarkBtns = document.querySelectorAll('.meta-bookmark');
if (bookmarkBtns) {
bookmarkBtns.forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
const isSaved = this.classList.contains('is-active');
if(isSaved) { this.classList.remove('is-active'); this.innerHTML = 'BOOKMARK ☆'; }
else { this.classList.add('is-active'); this.innerHTML = 'SAVED ★'; }
const fd = new FormData();
fd.append('action', 'wso_engine_action');
fd.append('sub_action', 'toggle_fav');
fd.append('id', this.getAttribute('data-id'));
fd.append('security', wsoEngine.nonce);
fetch(wsoEngine.ajaxUrl, { method: 'POST', body: fd }).then(r=>r.json()).then(res=>{
if(!res.success) {
alert('Error saving. Please login.');
if(isSaved) { this.classList.add('is-active'); this.innerHTML = 'SAVED ★'; }
else { this.classList.remove('is-active'); this.innerHTML = 'BOOKMARK ☆'; }
}
});
});
});
}
// 2. REPORT LOGIC
const reportBtn = document.querySelector('.footer-report-btn');
if (reportBtn) {
reportBtn.addEventListener('click', function() {
if(!confirm('Report a broken link or issue?')) return;
const originalText = this.innerHTML;
this.innerHTML = 'SENDING...';
this.style.pointerEvents = 'none';
this.style.opacity = '0.7';
const fd = new FormData();
fd.append('action', 'wso_engine_action');
fd.append('sub_action', 'report_issue');
fd.append('post_id', this.getAttribute('data-id'));
fd.append('security', wsoEngine.nonce);
fetch(wsoEngine.ajaxUrl, { method: 'POST', body: fd }).then(r => r.json()).then(res => {
if(res.success) { alert('Report Sent.'); this.innerHTML = '✔ REPORTED'; }
else { alert(res.data || 'Error.'); this.innerHTML = originalText; this.style.pointerEvents = 'auto'; }
});
});
}
// 3. PRIVATE NOTES (Auto-Save)
const noteArea = document.getElementById('wso-private-note');
if (noteArea) {
let noteTimer;
const status = document.getElementById('note-status');
noteArea.addEventListener('input', function() {
if(status) { status.style.opacity = '1'; status.innerText = 'Typing...'; status.style.background = '#f5c518'; }
clearTimeout(noteTimer);
noteTimer = setTimeout(() => {
const fd = new FormData();
fd.append('action', 'wso_engine_action');
fd.append('sub_action', 'save_note');
fd.append('post_id', document.querySelector('.scholar-notes-native').getAttribute('data-id'));
fd.append('content', this.value);
fd.append('security', wsoEngine.nonce);
fetch(wsoEngine.ajaxUrl, { method: 'POST', body: fd }).then(r=>r.json()).then(res=>{
if(status) { status.innerText = 'Saved'; status.style.background = '#4ade80'; setTimeout(() => { status.style.opacity = '0'; }, 2000); }
});
}, 1000);
});
}
// 4. COPY ALL LOGIC (v8.9)
document.querySelectorAll('.wso-copy-all').forEach(btn => {
btn.addEventListener('click', function() {
const rawLinks = this.getAttribute('data-links');
// Decode hidden newlines if any
const links = rawLinks.replace(/\\n/g, '\n');
navigator.clipboard.writeText(links).then(() => {
const original = this.innerText;
this.innerText = 'COPIED!';
this.style.color = '#4ade80';
setTimeout(() => {
this.innerText = original;
this.style.color = '';
}, 2000);
});
});
});
// 5. EXPAND TOGGLE (v8.9)
document.querySelectorAll('.wso-dl-expand-btn').forEach(btn => {
btn.addEventListener('click', function() {
const container = this.closest('.dl-links-col');
container.classList.remove('is-collapsed');
this.remove(); // Remove button after expanding
});
});
});
Profitable Brands by Top Figure - WSO Downloads