1935
This commit is contained in:
1 parent
3a8db8fb12
commit
adce55986d
2 files changed
+393
-355
No files matched your search
@@ -271,7 +271,9 @@ window.initArtalk = function() {
|
|||||||
// 能够通过 type/id/name/placeholder/class/aria-label 准确匹配
|
// 能够通过 type/id/name/placeholder/class/aria-label 准确匹配
|
||||||
var enhanceEditorInputs = function() {
|
var enhanceEditorInputs = function() {
|
||||||
var editor = document.querySelector('.atk-editor');
|
var editor = document.querySelector('.atk-editor');
|
||||||
if (!editor) return;
|
if (!editor) return 0;
|
||||||
|
|
||||||
|
var enhanced = 0;
|
||||||
|
|
||||||
// 昵称输入框
|
// 昵称输入框
|
||||||
var nickInput = editor.querySelector('input[name="nick"]');
|
var nickInput = editor.querySelector('input[name="nick"]');
|
||||||
@@ -280,6 +282,7 @@ window.initArtalk = function() {
|
|||||||
nickInput.setAttribute('aria-label', '昵称 author nick name');
|
nickInput.setAttribute('aria-label', '昵称 author nick name');
|
||||||
nickInput.classList.add('comment-author', 'user-nick');
|
nickInput.classList.add('comment-author', 'user-nick');
|
||||||
nickInput.setAttribute('data-autofill-done', '1');
|
nickInput.setAttribute('data-autofill-done', '1');
|
||||||
|
enhanced++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 邮箱输入框
|
// 邮箱输入框
|
||||||
@@ -289,6 +292,7 @@ window.initArtalk = function() {
|
|||||||
emailInput.setAttribute('aria-label', '邮箱 email mail');
|
emailInput.setAttribute('aria-label', '邮箱 email mail');
|
||||||
emailInput.classList.add('comment-email', 'user-email');
|
emailInput.classList.add('comment-email', 'user-email');
|
||||||
emailInput.setAttribute('data-autofill-done', '1');
|
emailInput.setAttribute('data-autofill-done', '1');
|
||||||
|
enhanced++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网址输入框
|
// 网址输入框
|
||||||
@@ -298,6 +302,7 @@ window.initArtalk = function() {
|
|||||||
linkInput.setAttribute('aria-label', '网址 website url link homepage site web');
|
linkInput.setAttribute('aria-label', '网址 website url link homepage site web');
|
||||||
linkInput.classList.add('comment-url', 'user-link', 'user-website');
|
linkInput.classList.add('comment-url', 'user-link', 'user-website');
|
||||||
linkInput.setAttribute('data-autofill-done', '1');
|
linkInput.setAttribute('data-autofill-done', '1');
|
||||||
|
enhanced++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 内容输入框(避免被误识别为昵称)
|
// 内容输入框(避免被误识别为昵称)
|
||||||
@@ -306,25 +311,168 @@ window.initArtalk = function() {
|
|||||||
contentInput.setAttribute('autocomplete', 'off');
|
contentInput.setAttribute('autocomplete', 'off');
|
||||||
contentInput.setAttribute('aria-label', '评论内容 content comment');
|
contentInput.setAttribute('aria-label', '评论内容 content comment');
|
||||||
contentInput.setAttribute('data-autofill-done', '1');
|
contentInput.setAttribute('data-autofill-done', '1');
|
||||||
|
enhanced++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 触发油猴脚本自动填充(延迟到评论框稳定后)
|
||||||
|
if (enhanced > 0) {
|
||||||
|
triggerAutoFill(editor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return enhanced;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ── 触发油猴脚本自动填充 ──
|
||||||
|
// 问题:油猴脚本可能在评论框还没完全加载时就填充了,
|
||||||
|
// 导致填充的数据在 Artalk 重新渲染后丢失。
|
||||||
|
// 解决:使用 MutationObserver 监控评论框 DOM 变化,
|
||||||
|
// 在评论框稳定后(300ms 内没有变化)才触发填充。
|
||||||
|
var pendingFillTimer = null;
|
||||||
|
var fillDebounceDelay = 300; // 评论框稳定后 300ms 才触发填充
|
||||||
|
|
||||||
|
var triggerAutoFill = function(editor) {
|
||||||
|
if (pendingFillTimer) {
|
||||||
|
clearTimeout(pendingFillTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 延迟触发,等待评论框稳定
|
||||||
|
pendingFillTimer = setTimeout(function() {
|
||||||
|
pendingFillTimer = null;
|
||||||
|
|
||||||
|
// 再次检查评论框是否存在
|
||||||
|
editor = document.querySelector('.atk-editor');
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
|
// 获取评论框中的输入框
|
||||||
|
var nickInput = editor.querySelector('input[name="nick"]');
|
||||||
|
var emailInput = editor.querySelector('input[name="email"]');
|
||||||
|
var linkInput = editor.querySelector('input[name="link"]');
|
||||||
|
|
||||||
|
// 保存当前输入框的值到 sessionStorage
|
||||||
|
var fillData = {
|
||||||
|
nick: nickInput ? nickInput.value : '',
|
||||||
|
email: emailInput ? emailInput.value : '',
|
||||||
|
link: linkInput ? linkInput.value : '',
|
||||||
|
timestamp: Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
|
// 如果有填充数据,保存到 sessionStorage
|
||||||
|
if (fillData.nick || fillData.email || fillData.link) {
|
||||||
|
try {
|
||||||
|
sessionStorage.setItem('artalk_autofill_data', JSON.stringify(fillData));
|
||||||
|
console.log('[ArtalkEnhancer] 保存填充数据到 sessionStorage:', fillData);
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 手动触发 input 事件,通知可能存在的自动填充脚本
|
||||||
|
// 一些油猴脚本会监听 input/change 事件来检测新字段
|
||||||
|
[nickInput, emailInput, linkInput].forEach(function(input) {
|
||||||
|
if (input && input.value) {
|
||||||
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 尝试调用油猴脚本的公开 API(如果有)
|
||||||
|
// 例如 Greasemonkey/Tampermonkey 的 GM_setValue 配合 GM_getValue
|
||||||
|
if (typeof window.GM !== 'undefined' && window.GM.setValue) {
|
||||||
|
// 通知油猴脚本评论框已加载完成
|
||||||
|
window.GM_setValue('artalk_editor_ready', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[ArtalkEnhancer] 评论框稳定,触发自动填充');
|
||||||
|
}, fillDebounceDelay);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ── 恢复 sessionStorage 中的填充数据 ──
|
||||||
|
// 问题:Artalk 评论框可能在填充后又重新渲染,导致填充的数据丢失。
|
||||||
|
// 解决:在评论框稳定后,检查 sessionStorage 是否有之前保存的填充数据,
|
||||||
|
// 如果有,自动恢复到输入框中。
|
||||||
|
var restoreAutoFillData = function() {
|
||||||
|
var editor = document.querySelector('.atk-editor');
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var stored = sessionStorage.getItem('artalk_autofill_data');
|
||||||
|
if (!stored) return;
|
||||||
|
|
||||||
|
var fillData = JSON.parse(stored);
|
||||||
|
if (!fillData || !fillData.timestamp) return;
|
||||||
|
|
||||||
|
// 数据是否在 24 小时内有效
|
||||||
|
var maxAge = 24 * 60 * 60 * 1000; // 24 小时
|
||||||
|
if (Date.now() - fillData.timestamp > maxAge) {
|
||||||
|
sessionStorage.removeItem('artalk_autofill_data');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 恢复到输入框
|
||||||
|
var nickInput = editor.querySelector('input[name="nick"]');
|
||||||
|
var emailInput = editor.querySelector('input[name="email"]');
|
||||||
|
var linkInput = editor.querySelector('input[name="link"]');
|
||||||
|
|
||||||
|
if (fillData.nick && nickInput && !nickInput.value) {
|
||||||
|
nickInput.value = fillData.nick;
|
||||||
|
nickInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
|
if (fillData.email && emailInput && !emailInput.value) {
|
||||||
|
emailInput.value = fillData.email;
|
||||||
|
emailInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
|
if (fillData.link && linkInput && !linkInput.value) {
|
||||||
|
linkInput.value = fillData.link;
|
||||||
|
linkInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fillData.nick || fillData.email || fillData.link) {
|
||||||
|
console.log('[ArtalkEnhancer] 从 sessionStorage 恢复填充数据:', fillData);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.warn('[ArtalkEnhancer] 恢复填充数据失败:', e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 立即执行一次
|
// 立即执行一次
|
||||||
enhanceEditorInputs();
|
enhanceEditorInputs();
|
||||||
|
|
||||||
// 监听评论框加载完成
|
// 评论框加载完成(Artalk 内置事件)
|
||||||
artalk.on('mounted', function() {
|
artalk.on('mounted', function() {
|
||||||
setTimeout(enhanceEditorInputs, 100);
|
setTimeout(function() {
|
||||||
|
enhanceEditorInputs();
|
||||||
|
restoreAutoFillData();
|
||||||
|
}, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听评论列表加载(PJAX 切换后)
|
// 评论列表加载完成(PJAX 切换后)
|
||||||
artalk.on('list-loaded', function() {
|
artalk.on('list-loaded', function() {
|
||||||
setTimeout(enhanceEditorInputs, 200);
|
setTimeout(function() {
|
||||||
|
enhanceEditorInputs();
|
||||||
|
restoreAutoFillData();
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 评论发送成功后保存填充数据
|
||||||
|
artalk.on('comment-submit', function() {
|
||||||
|
try {
|
||||||
|
var editor = document.querySelector('.atk-editor');
|
||||||
|
if (editor) {
|
||||||
|
var fillData = {
|
||||||
|
nick: editor.querySelector('input[name="nick"]') ? editor.querySelector('input[name="nick"]').value : '',
|
||||||
|
email: editor.querySelector('input[name="email"]') ? editor.querySelector('input[name="email"]').value : '',
|
||||||
|
link: editor.querySelector('input[name="link"]') ? editor.querySelector('input[name="link"]').value : '',
|
||||||
|
timestamp: Date.now()
|
||||||
|
};
|
||||||
|
if (fillData.nick || fillData.email || fillData.link) {
|
||||||
|
sessionStorage.setItem('artalk_autofill_data', JSON.stringify(fillData));
|
||||||
|
console.log('[ArtalkEnhancer] 评论提交后保存填充数据');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 兜底:定时检查(防止某些情况下事件未触发)
|
// 兜底:定时检查(防止某些情况下事件未触发)
|
||||||
var enhanceInterval = setInterval(function() {
|
var enhanceInterval = setInterval(function() {
|
||||||
enhanceEditorInputs();
|
enhanceEditorInputs();
|
||||||
|
restoreAutoFillData();
|
||||||
// 找到所有字段都已增强后停止
|
// 找到所有字段都已增强后停止
|
||||||
var editor = document.querySelector('.atk-editor');
|
var editor = document.querySelector('.atk-editor');
|
||||||
if (editor) {
|
if (editor) {
|
||||||
|
|||||||
+240
-350
@@ -8,281 +8,277 @@
|
|||||||
// 确保所有音频控件互斥播放,PJAX 切换时保存进度
|
// 确保所有音频控件互斥播放,PJAX 切换时保存进度
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
var AudioManager = {
|
// 持久化 AudioManager 对象本身(防止脚本重载时丢失方法)
|
||||||
currentPlaying: null,
|
// 第一次加载:定义 AudioManager
|
||||||
currentType: null,
|
// 后续加载(PJAX 切换):合并新方法到已存在的对象
|
||||||
savedStates: {},
|
if (!window.AudioManager) {
|
||||||
// 全局音乐播放器 - PJAX 持久化
|
window.AudioManager = {};
|
||||||
globalAudio: null,
|
}
|
||||||
globalMusicSrc: null,
|
|
||||||
globalMusicCard: null,
|
|
||||||
// Session storage key
|
|
||||||
STORAGE_KEY: 'amigo_music_state',
|
|
||||||
|
|
||||||
// 获取当前页面的存储 key(基于 URL path)
|
// 用一个 IIFE 来定义 AudioManager 的方法
|
||||||
_getPageKey: function() {
|
(function() {
|
||||||
return window.location.pathname;
|
var AM = window.AudioManager;
|
||||||
},
|
|
||||||
|
|
||||||
init: function() {
|
// 一次性定义所有方法
|
||||||
// 创建全局音频元素
|
AM.getAudioState = function() {
|
||||||
if (!this.globalAudio) {
|
if (!window.__amigoAudioState) {
|
||||||
this.globalAudio = new Audio();
|
window.__amigoAudioState = {
|
||||||
this.globalAudio.preload = 'metadata';
|
audio: null,
|
||||||
|
src: null,
|
||||||
// 监听全局音频事件
|
isPlaying: false,
|
||||||
this.globalAudio.addEventListener('timeupdate', this._onTimeUpdate.bind(this));
|
currentTime: 0,
|
||||||
this.globalAudio.addEventListener('ended', this._onEnded.bind(this));
|
attached: false
|
||||||
this.globalAudio.addEventListener('loadedmetadata', this._onLoadedMetadata.bind(this));
|
};
|
||||||
}
|
}
|
||||||
},
|
return window.__amigoAudioState;
|
||||||
|
|
||||||
// 保存当前播放状态到 sessionStorage(按页面保存)
|
|
||||||
saveToSession: function() {
|
|
||||||
if (!this.globalAudio || !this.globalMusicSrc) return;
|
|
||||||
|
|
||||||
var pageKey = this._getPageKey();
|
|
||||||
var allStates = this._loadAllStates();
|
|
||||||
|
|
||||||
allStates[pageKey] = {
|
|
||||||
src: this.globalMusicSrc,
|
|
||||||
currentTime: this.globalAudio.currentTime,
|
|
||||||
isPlaying: !this.globalAudio.paused,
|
|
||||||
name: this.globalMusicCard ? this.globalMusicCard.dataset.name : '',
|
|
||||||
artist: this.globalMusicCard ? this.globalMusicCard.dataset.artist : ''
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AM._getAudio = function() {
|
||||||
|
return this.getAudioState().audio;
|
||||||
|
};
|
||||||
|
|
||||||
|
AM._getSrc = function() {
|
||||||
|
return this.getAudioState().src;
|
||||||
|
};
|
||||||
|
|
||||||
|
AM._setSrc = function(src) {
|
||||||
|
this.getAudioState().src = src;
|
||||||
|
};
|
||||||
|
|
||||||
|
AM.init = function() {
|
||||||
|
var state = this.getAudioState();
|
||||||
|
if (!state.audio) {
|
||||||
|
state.audio = new Audio();
|
||||||
|
state.audio.preload = 'metadata';
|
||||||
|
if (!state.attached) {
|
||||||
|
state.audio.style.display = 'none';
|
||||||
|
state.audio.setAttribute('data-amigo-music', 'true');
|
||||||
|
document.body.appendChild(state.audio);
|
||||||
|
state.attached = true;
|
||||||
|
}
|
||||||
|
var self = this;
|
||||||
|
state.audio.addEventListener('timeupdate', function() { self._onTimeUpdate(); });
|
||||||
|
state.audio.addEventListener('ended', function() { self._onEnded(); });
|
||||||
|
state.audio.addEventListener('loadedmetadata', function() { self._onLoadedMetadata(); });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AM.saveToSession = function() {
|
||||||
|
var audio = this._getAudio();
|
||||||
|
var src = this._getSrc();
|
||||||
|
console.log('[AudioManager] saveToSession called, audio:', !!audio, 'src:', src, 'isPlaying:', audio ? !audio.paused : false);
|
||||||
|
if (!audio || !src) {
|
||||||
|
console.log('[AudioManager] saveToSession skipped - no audio or src');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var state = {
|
||||||
|
src: src,
|
||||||
|
currentTime: audio.currentTime,
|
||||||
|
isPlaying: !audio.paused,
|
||||||
|
name: this.globalMusicCard ? this.globalMusicCard.dataset.name : '',
|
||||||
|
artist: this.globalMusicCard ? this.globalMusicCard.dataset.artist : '',
|
||||||
|
savedAt: Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('[AudioManager] saving state:', JSON.stringify(state));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sessionStorage.setItem(this.STORAGE_KEY, JSON.stringify(allStates));
|
sessionStorage.setItem(this.STORAGE_KEY, JSON.stringify(state));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to save music state:', e);
|
console.warn('Failed to save music state:', e);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
// 加载所有页面的状态
|
AM.restoreFromSession = function() {
|
||||||
_loadAllStates: function() {
|
|
||||||
try {
|
try {
|
||||||
var stored = sessionStorage.getItem(this.STORAGE_KEY);
|
var stored = sessionStorage.getItem(this.STORAGE_KEY);
|
||||||
if (!stored) return {};
|
if (!stored) return null;
|
||||||
return JSON.parse(stored);
|
return JSON.parse(stored);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {};
|
return null;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
// 从 sessionStorage 恢复当前页面的播放状态
|
AM.clearSession = function() {
|
||||||
restoreFromSession: function() {
|
|
||||||
var pageKey = this._getPageKey();
|
|
||||||
var allStates = this._loadAllStates();
|
|
||||||
|
|
||||||
var state = allStates[pageKey];
|
|
||||||
if (!state || !state.src) return null;
|
|
||||||
|
|
||||||
return state;
|
|
||||||
},
|
|
||||||
|
|
||||||
// 清除当前页面的播放状态
|
|
||||||
clearSession: function() {
|
|
||||||
var pageKey = this._getPageKey();
|
|
||||||
var allStates = this._loadAllStates();
|
|
||||||
|
|
||||||
delete allStates[pageKey];
|
|
||||||
|
|
||||||
try {
|
|
||||||
sessionStorage.setItem(this.STORAGE_KEY, JSON.stringify(allStates));
|
|
||||||
} catch (e) {}
|
|
||||||
},
|
|
||||||
|
|
||||||
// 重置播放器到初始状态(刷新页面/非 PJAX 导航时调用)
|
|
||||||
reset: function() {
|
|
||||||
if (this.globalAudio) {
|
|
||||||
this.globalAudio.pause();
|
|
||||||
this.globalAudio.currentTime = 0;
|
|
||||||
this.globalAudio.src = '';
|
|
||||||
}
|
|
||||||
this.globalMusicSrc = null;
|
|
||||||
this.globalMusicCard = null;
|
|
||||||
sessionStorage.removeItem(this.STORAGE_KEY);
|
sessionStorage.removeItem(this.STORAGE_KEY);
|
||||||
},
|
};
|
||||||
|
|
||||||
// 恢复播放状态 - 在 PJAX 切换后调用
|
AM.reset = function() {
|
||||||
restorePlayingState: function() {
|
console.log('[AudioManager] reset called');
|
||||||
|
var audio = this._getAudio();
|
||||||
|
if (audio) {
|
||||||
|
audio.pause();
|
||||||
|
audio.currentTime = 0;
|
||||||
|
audio.src = '';
|
||||||
|
}
|
||||||
|
this._setSrc(null);
|
||||||
|
console.log('[AudioManager] reset done, src:', this._getSrc());
|
||||||
|
this.globalMusicCard = null;
|
||||||
|
this.clearSession();
|
||||||
|
};
|
||||||
|
|
||||||
|
AM.restorePlayingState = function() {
|
||||||
var state = this.restoreFromSession();
|
var state = this.restoreFromSession();
|
||||||
if (!state || !state.src) {
|
if (!state || !state.src) return;
|
||||||
// 当前页面没有保存的状态,保持当前播放状态(继续播放)
|
|
||||||
|
var audio = this._getAudio();
|
||||||
|
var currentSrc = this._getSrc();
|
||||||
|
|
||||||
|
if (currentSrc === state.src && audio && audio.src) {
|
||||||
|
this._syncCardUI(state.src, state.isPlaying);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (audio && !audio.paused && currentSrc !== state.src) {
|
||||||
|
audio.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
this._setSrc(state.src);
|
||||||
|
if (!audio.src || audio.src !== state.src) {
|
||||||
|
audio.src = state.src;
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetCard = this._findCardBySrc(state.src);
|
||||||
|
if (targetCard) {
|
||||||
|
this.globalMusicCard = targetCard;
|
||||||
|
this._updateUI(targetCard, state.isPlaying);
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var doRestore = function() {
|
||||||
// 找到对应的音乐卡片
|
if (state.currentTime > 0 && state.currentTime < audio.duration) {
|
||||||
var cards = document.querySelectorAll('.amigo-music-card');
|
audio.currentTime = state.currentTime;
|
||||||
var targetCard = null;
|
|
||||||
|
|
||||||
for (var i = 0; i < cards.length; i++) {
|
|
||||||
var card = cards[i];
|
|
||||||
if (card.dataset.src === state.src) {
|
|
||||||
targetCard = card;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!targetCard) {
|
|
||||||
// 当前页面没有这个音乐卡片,保持当前播放状态(继续播放)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置全局音频
|
|
||||||
this.globalMusicSrc = state.src;
|
|
||||||
this.globalMusicCard = targetCard;
|
|
||||||
this.globalAudio.src = state.src;
|
|
||||||
|
|
||||||
// 更新 UI(恢复原来的播放状态)
|
|
||||||
this._updateUI(targetCard, state.isPlaying);
|
|
||||||
|
|
||||||
// 等待元数据加载完成
|
|
||||||
this.globalAudio.addEventListener('loadedmetadata', function onLoaded() {
|
|
||||||
self.globalAudio.removeEventListener('loadedmetadata', onLoaded);
|
|
||||||
|
|
||||||
if (state.currentTime > 0 && state.currentTime < self.globalAudio.duration) {
|
|
||||||
self.globalAudio.currentTime = state.currentTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
self._onTimeUpdate();
|
self._onTimeUpdate();
|
||||||
|
if (state.isPlaying && audio.paused) {
|
||||||
// 如果之前在播放,继续播放
|
audio.play().catch(function() {});
|
||||||
if (state.isPlaying && self.globalAudio.paused) {
|
|
||||||
self.globalAudio.play().catch(function() {});
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (audio.readyState >= 1) {
|
||||||
|
doRestore();
|
||||||
|
} else {
|
||||||
|
audio.addEventListener('loadedmetadata', function onLoaded() {
|
||||||
|
audio.removeEventListener('loadedmetadata', onLoaded);
|
||||||
|
doRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.globalAudio.readyState >= 1) {
|
|
||||||
if (state.currentTime > 0 && state.currentTime < this.globalAudio.duration) {
|
|
||||||
this.globalAudio.currentTime = state.currentTime;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AM._findCardBySrc = function(src) {
|
||||||
|
var cards = document.querySelectorAll('.amigo-music-card');
|
||||||
|
for (var i = 0; i < cards.length; i++) {
|
||||||
|
if (cards[i].dataset.src === src) {
|
||||||
|
return cards[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
AM._syncCardUI = function(src, isPlaying) {
|
||||||
|
var card = this._findCardBySrc(src);
|
||||||
|
if (card) {
|
||||||
|
this.globalMusicCard = card;
|
||||||
|
this._updateUI(card, isPlaying);
|
||||||
this._onTimeUpdate();
|
this._onTimeUpdate();
|
||||||
// 如果之前在播放,继续播放
|
|
||||||
if (state.isPlaying && this.globalAudio.paused) {
|
|
||||||
this.globalAudio.play().catch(function() {});
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
},
|
|
||||||
|
|
||||||
// 播放指定音乐卡片
|
AM.playMusic = function(card) {
|
||||||
playMusic: function(card) {
|
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
|
|
||||||
var audioSrc = card.dataset.src;
|
var audioSrc = card.dataset.src;
|
||||||
if (!audioSrc) return;
|
if (!audioSrc) return;
|
||||||
|
|
||||||
// 如果是同一首歌,切换播放/暂停
|
console.log('[AudioManager] playMusic called:', audioSrc);
|
||||||
if (this.globalMusicSrc === audioSrc && this.globalAudio) {
|
|
||||||
if (this.globalAudio.paused) {
|
var audio = this._getAudio();
|
||||||
this.globalAudio.play().catch(function() {});
|
var currentSrc = this._getSrc();
|
||||||
|
|
||||||
|
if (currentSrc === audioSrc && audio) {
|
||||||
|
console.log('[AudioManager] Same song, toggling play/pause');
|
||||||
|
if (audio.paused) {
|
||||||
|
audio.play().catch(function() {});
|
||||||
this.globalMusicCard = card;
|
this.globalMusicCard = card;
|
||||||
this._updateUI(card, true);
|
this._updateUI(card, true);
|
||||||
} else {
|
} else {
|
||||||
this.globalAudio.pause();
|
audio.pause();
|
||||||
this._updateUI(card, false);
|
this._updateUI(card, false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 暂停其他所有音频
|
|
||||||
this.pauseAll();
|
this.pauseAll();
|
||||||
|
this._setSrc(audioSrc);
|
||||||
// 设置新的音频源
|
console.log('[AudioManager] set src:', audioSrc, 'state.src:', this._getSrc());
|
||||||
this.globalMusicSrc = audioSrc;
|
|
||||||
this.globalMusicCard = card;
|
this.globalMusicCard = card;
|
||||||
this.globalAudio.src = audioSrc;
|
audio.src = audioSrc;
|
||||||
|
|
||||||
// 更新 UI
|
|
||||||
this._updateUI(card, true);
|
this._updateUI(card, true);
|
||||||
|
|
||||||
// 尝试播放
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this.globalAudio.play().then(function() {
|
audio.play().then(function() {
|
||||||
// 保存状态
|
console.log('[AudioManager] Playback started, saving session');
|
||||||
self.saveToSession();
|
self.saveToSession();
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
console.warn('Play failed:', err);
|
console.warn('Play failed:', err);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
// 跳转到指定时间
|
AM.seekTo = function(time) {
|
||||||
seekTo: function(time) {
|
var audio = this._getAudio();
|
||||||
if (this.globalAudio) {
|
if (audio) {
|
||||||
this.globalAudio.currentTime = time;
|
audio.currentTime = time;
|
||||||
this.saveToSession();
|
this.saveToSession();
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
// 更新时间回调
|
AM._onTimeUpdate = function() {
|
||||||
_onTimeUpdate: function() {
|
var audio = this._getAudio();
|
||||||
if (!this.globalAudio || !this.globalMusicCard) return;
|
if (!audio || !this.globalMusicCard) return;
|
||||||
|
if (audio.__seeking) return;
|
||||||
// 如果正在拖动进度条,跳过 UI 更新
|
|
||||||
if (this.globalAudio.__seeking) return;
|
|
||||||
|
|
||||||
var currentTime = this.globalAudio.currentTime;
|
|
||||||
var duration = this.globalAudio.duration;
|
|
||||||
|
|
||||||
|
var currentTime = audio.currentTime;
|
||||||
|
var duration = audio.duration;
|
||||||
if (isNaN(duration) || duration === 0) return;
|
if (isNaN(duration) || duration === 0) return;
|
||||||
|
|
||||||
// 更新进度条
|
|
||||||
var progress = (currentTime / duration) * 100;
|
var progress = (currentTime / duration) * 100;
|
||||||
this.globalMusicCard.style.setProperty('--music-progress', progress + '%');
|
this.globalMusicCard.style.setProperty('--music-progress', progress + '%');
|
||||||
|
|
||||||
// 更新时间显示
|
|
||||||
var currentTimeEl = this.globalMusicCard.querySelector('.amigo-music-card__time--current');
|
var currentTimeEl = this.globalMusicCard.querySelector('.amigo-music-card__time--current');
|
||||||
if (currentTimeEl) {
|
if (currentTimeEl) currentTimeEl.textContent = formatTime(currentTime);
|
||||||
currentTimeEl.textContent = formatTime(currentTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新总时长(如果还没更新过)
|
|
||||||
var durationTimeEl = this.globalMusicCard.querySelector('.amigo-music-card__time--duration');
|
var durationTimeEl = this.globalMusicCard.querySelector('.amigo-music-card__time--duration');
|
||||||
if (durationTimeEl && durationTimeEl.textContent === '--:--') {
|
if (durationTimeEl && durationTimeEl.textContent === '--:--') {
|
||||||
durationTimeEl.textContent = formatTime(duration);
|
durationTimeEl.textContent = formatTime(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定期保存状态(每5秒)
|
|
||||||
if (Math.floor(currentTime) % 5 === 0) {
|
if (Math.floor(currentTime) % 5 === 0) {
|
||||||
this.saveToSession();
|
this.saveToSession();
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
// 加载完成回调
|
AM._onLoadedMetadata = function() {
|
||||||
_onLoadedMetadata: function() {
|
var audio = this._getAudio();
|
||||||
if (!this.globalAudio || !this.globalMusicCard) return;
|
if (!audio || !this.globalMusicCard) return;
|
||||||
|
var duration = audio.duration;
|
||||||
var duration = this.globalAudio.duration;
|
|
||||||
|
|
||||||
// 更新总时长显示
|
|
||||||
var durationTimeEl = this.globalMusicCard.querySelector('.amigo-music-card__time--duration');
|
var durationTimeEl = this.globalMusicCard.querySelector('.amigo-music-card__time--duration');
|
||||||
if (durationTimeEl) {
|
if (durationTimeEl) durationTimeEl.textContent = formatTime(duration);
|
||||||
durationTimeEl.textContent = formatTime(duration);
|
};
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// 播放结束回调
|
AM._onEnded = function() {
|
||||||
_onEnded: function() {
|
|
||||||
if (this.globalMusicCard) {
|
if (this.globalMusicCard) {
|
||||||
this._updateUI(this.globalMusicCard, false);
|
this._updateUI(this.globalMusicCard, false);
|
||||||
}
|
}
|
||||||
this.globalMusicCard = null;
|
this.globalMusicCard = null;
|
||||||
|
this._setSrc(null);
|
||||||
this.clearSession();
|
this.clearSession();
|
||||||
},
|
};
|
||||||
|
|
||||||
// 更新 UI 状态
|
AM._updateUI = function(card, isPlaying) {
|
||||||
_updateUI: function(card, isPlaying) {
|
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
|
|
||||||
card.setAttribute('data-playing', isPlaying ? 'true' : 'false');
|
card.setAttribute('data-playing', isPlaying ? 'true' : 'false');
|
||||||
|
|
||||||
var playBtn = card.querySelector('.amigo-music-card__play');
|
var playBtn = card.querySelector('.amigo-music-card__play');
|
||||||
if (playBtn) {
|
if (playBtn) playBtn.setAttribute('aria-pressed', isPlaying ? 'true' : 'false');
|
||||||
playBtn.setAttribute('aria-pressed', isPlaying ? 'true' : 'false');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
this.currentPlaying = card;
|
this.currentPlaying = card;
|
||||||
@@ -291,178 +287,52 @@ var AudioManager = {
|
|||||||
this.currentPlaying = null;
|
this.currentPlaying = null;
|
||||||
this.currentType = null;
|
this.currentType = null;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
pauseAll: function() {
|
AM.pauseAll = function() {
|
||||||
// Pause all voice bubbles
|
|
||||||
document.querySelectorAll('.amigo-voice-bubble.is-playing').forEach(function(bubble) {
|
document.querySelectorAll('.amigo-voice-bubble.is-playing').forEach(function(bubble) {
|
||||||
if (bubble.__audio) {
|
if (bubble.__audio) {
|
||||||
try {
|
try { bubble.__audio.pause(); bubble.__audio.currentTime = 0; } catch (e) {}
|
||||||
bubble.__audio.pause();
|
|
||||||
bubble.__audio.currentTime = 0;
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
bubble.classList.remove('is-playing');
|
bubble.classList.remove('is-playing');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pause global music
|
var audio = this._getAudio();
|
||||||
if (this.globalAudio && !this.globalAudio.paused) {
|
if (audio && !audio.paused) {
|
||||||
this.globalAudio.pause();
|
audio.pause();
|
||||||
if (this.globalMusicCard) {
|
if (this.globalMusicCard) {
|
||||||
this._updateUI(this.globalMusicCard, false);
|
this._updateUI(this.globalMusicCard, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause all live photos
|
|
||||||
document.querySelectorAll('.amigo-livephoto.is-playing').forEach(function(livePhoto) {
|
document.querySelectorAll('.amigo-livephoto.is-playing').forEach(function(livePhoto) {
|
||||||
var video = livePhoto.querySelector('.amigo-livephoto-video');
|
var video = livePhoto.querySelector('.amigo-livephoto-video');
|
||||||
if (video) {
|
if (video) { try { video.pause(); video.currentTime = 0; } catch (e) {} }
|
||||||
try { video.pause(); video.currentTime = 0; } catch (e) {}
|
|
||||||
}
|
|
||||||
livePhoto.classList.remove('is-playing');
|
livePhoto.classList.remove('is-playing');
|
||||||
});
|
});
|
||||||
|
|
||||||
this.currentPlaying = null;
|
this.currentPlaying = null;
|
||||||
this.currentType = null;
|
this.currentType = null;
|
||||||
},
|
};
|
||||||
|
|
||||||
registerPlay: function(element, type) {
|
AM.registerPlay = function(element, type) {
|
||||||
if (this.currentPlaying && this.currentPlaying !== element) {
|
if (this.currentPlaying && this.currentPlaying !== element) {
|
||||||
this.pauseAll();
|
// 触发其他播放的暂停
|
||||||
}
|
}
|
||||||
this.currentPlaying = element;
|
this.currentPlaying = element;
|
||||||
this.currentType = type;
|
this.currentType = type;
|
||||||
},
|
};
|
||||||
|
|
||||||
saveState: function() {
|
// 初始化基本字段
|
||||||
var states = [];
|
if (typeof AM.currentPlaying === 'undefined') AM.currentPlaying = null;
|
||||||
|
if (typeof AM.currentType === 'undefined') AM.currentType = null;
|
||||||
|
if (typeof AM.savedStates === 'undefined') AM.savedStates = {};
|
||||||
|
if (typeof AM.STORAGE_KEY === 'undefined') AM.STORAGE_KEY = 'amigo_music_state';
|
||||||
|
})();
|
||||||
|
|
||||||
// Save music card states
|
// 保留对 window.AudioManager 的引用
|
||||||
document.querySelectorAll('.amigo-music-card').forEach(function(card, index) {
|
var AudioManager = window.AudioManager;
|
||||||
var audio = card.__audio;
|
|
||||||
if (audio && audio.src) {
|
|
||||||
states.push({
|
|
||||||
type: 'music',
|
|
||||||
src: card.dataset.src,
|
|
||||||
currentTime: audio.currentTime,
|
|
||||||
isPlaying: card.getAttribute('data-playing') === 'true',
|
|
||||||
index: index
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Save live photo states
|
|
||||||
document.querySelectorAll('.amigo-livephoto').forEach(function(livePhoto, index) {
|
|
||||||
var video = livePhoto.querySelector('.amigo-livephoto-video');
|
|
||||||
if (video && video.src) {
|
|
||||||
states.push({
|
|
||||||
type: 'livephoto',
|
|
||||||
src: livePhoto.dataset.src,
|
|
||||||
currentTime: video.currentTime,
|
|
||||||
isPlaying: livePhoto.classList.contains('is-playing'),
|
|
||||||
index: index
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.savedStates[window.location.pathname] = states;
|
|
||||||
},
|
|
||||||
|
|
||||||
restoreState: function() {
|
|
||||||
var path = window.location.pathname;
|
|
||||||
var states = this.savedStates[path];
|
|
||||||
if (!states || states.length === 0) return;
|
|
||||||
|
|
||||||
states.forEach(function(state) {
|
|
||||||
if (state.type === 'music') {
|
|
||||||
var cards = document.querySelectorAll('.amigo-music-card');
|
|
||||||
var card = cards[state.index];
|
|
||||||
if (card && card.__audio && card.dataset.src === state.src) {
|
|
||||||
var audio = card.__audio;
|
|
||||||
var playBtn = card.querySelector('.amigo-music-card__play');
|
|
||||||
var seekInput = card.querySelector('.amigo-music-card__seek');
|
|
||||||
var currentTimeEl = card.querySelector('.amigo-music-card__time--current');
|
|
||||||
|
|
||||||
audio.addEventListener('loadedmetadata', function onLoaded() {
|
|
||||||
audio.currentTime = state.currentTime;
|
|
||||||
audio.removeEventListener('loadedmetadata', onLoaded);
|
|
||||||
|
|
||||||
if (currentTimeEl) {
|
|
||||||
currentTimeEl.textContent = formatTime(state.currentTime);
|
|
||||||
}
|
|
||||||
if (seekInput && audio.duration) {
|
|
||||||
var progress = (state.currentTime / audio.duration) * 100;
|
|
||||||
seekInput.value = (state.currentTime / audio.duration * 1000).toString();
|
|
||||||
card.style.setProperty('--music-progress', progress + '%');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.isPlaying) {
|
|
||||||
audio.play().catch(function() {});
|
|
||||||
card.setAttribute('data-playing', 'true');
|
|
||||||
if (playBtn) playBtn.setAttribute('aria-pressed', 'true');
|
|
||||||
AudioManager.currentPlaying = card;
|
|
||||||
AudioManager.currentType = 'music';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (audio.readyState >= 1) {
|
|
||||||
audio.currentTime = state.currentTime;
|
|
||||||
if (currentTimeEl) {
|
|
||||||
currentTimeEl.textContent = formatTime(state.currentTime);
|
|
||||||
}
|
|
||||||
if (seekInput && audio.duration) {
|
|
||||||
var progress = (state.currentTime / audio.duration) * 100;
|
|
||||||
seekInput.value = (state.currentTime / audio.duration * 1000).toString();
|
|
||||||
card.style.setProperty('--music-progress', progress + '%');
|
|
||||||
}
|
|
||||||
if (state.isPlaying) {
|
|
||||||
audio.play().catch(function() {});
|
|
||||||
card.setAttribute('data-playing', 'true');
|
|
||||||
if (playBtn) playBtn.setAttribute('aria-pressed', 'true');
|
|
||||||
AudioManager.currentPlaying = card;
|
|
||||||
AudioManager.currentType = 'music';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (state.type === 'livephoto') {
|
|
||||||
var photos = document.querySelectorAll('.amigo-livephoto');
|
|
||||||
var livePhoto = photos[state.index];
|
|
||||||
if (livePhoto && livePhoto.dataset.src === state.src) {
|
|
||||||
var video = livePhoto.querySelector('.amigo-livephoto-video');
|
|
||||||
if (video) {
|
|
||||||
var src = livePhoto.dataset.src || '';
|
|
||||||
if (src && !video.getAttribute('src')) {
|
|
||||||
video.setAttribute('src', src);
|
|
||||||
video.src = src;
|
|
||||||
}
|
|
||||||
|
|
||||||
video.addEventListener('loadedmetadata', function onLoaded() {
|
|
||||||
video.currentTime = state.currentTime;
|
|
||||||
video.removeEventListener('loadedmetadata', onLoaded);
|
|
||||||
|
|
||||||
if (state.isPlaying) {
|
|
||||||
video.play().catch(function() {});
|
|
||||||
livePhoto.classList.add('is-playing');
|
|
||||||
AudioManager.currentPlaying = livePhoto;
|
|
||||||
AudioManager.currentType = 'livephoto';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (video.readyState >= 1) {
|
|
||||||
video.currentTime = state.currentTime;
|
|
||||||
if (state.isPlaying) {
|
|
||||||
video.play().catch(function() {});
|
|
||||||
livePhoto.classList.add('is-playing');
|
|
||||||
AudioManager.currentPlaying = livePhoto;
|
|
||||||
AudioManager.currentType = 'livephoto';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Live Photo
|
// Live Photo
|
||||||
@@ -671,22 +541,25 @@ function initMusicCards() {
|
|||||||
// Seek - 使用 AudioManager
|
// Seek - 使用 AudioManager
|
||||||
if (seekInput) {
|
if (seekInput) {
|
||||||
seekInput.addEventListener('input', function() {
|
seekInput.addEventListener('input', function() {
|
||||||
if (AudioManager.globalAudio && AudioManager.globalAudio.duration) {
|
var audio = AudioManager._getAudio();
|
||||||
var time = (parseFloat(seekInput.value) / 1000) * AudioManager.globalAudio.duration;
|
if (audio && audio.duration) {
|
||||||
|
var time = (parseFloat(seekInput.value) / 1000) * audio.duration;
|
||||||
AudioManager.seekTo(time);
|
AudioManager.seekTo(time);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 拖动时暂停更新
|
// 拖动时暂停更新
|
||||||
seekInput.addEventListener('mousedown', function() {
|
seekInput.addEventListener('mousedown', function() {
|
||||||
if (AudioManager.globalAudio) {
|
var audio = AudioManager._getAudio();
|
||||||
AudioManager.globalAudio.__seeking = true;
|
if (audio) {
|
||||||
|
audio.__seeking = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
seekInput.addEventListener('mouseup', function() {
|
seekInput.addEventListener('mouseup', function() {
|
||||||
if (AudioManager.globalAudio) {
|
var audio = AudioManager._getAudio();
|
||||||
AudioManager.globalAudio.__seeking = false;
|
if (audio) {
|
||||||
|
audio.__seeking = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -758,7 +631,15 @@ function cleanupAllShortcodes() {
|
|||||||
// Initialize all shortcodes
|
// Initialize all shortcodes
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
|
// 防止 initAllShortcodes 在 PJAX 切换时被重复调用
|
||||||
|
var __shortcodesInitLock = false;
|
||||||
|
|
||||||
function initAllShortcodes() {
|
function initAllShortcodes() {
|
||||||
|
console.log('[AudioManager] initAllShortcodes called, lock:', __shortcodesInitLock);
|
||||||
|
// 防止重复初始化
|
||||||
|
if (__shortcodesInitLock) return;
|
||||||
|
__shortcodesInitLock = true;
|
||||||
|
|
||||||
// 初始化 AudioManager(创建全局音频元素)
|
// 初始化 AudioManager(创建全局音频元素)
|
||||||
AudioManager.init();
|
AudioManager.init();
|
||||||
|
|
||||||
@@ -766,17 +647,21 @@ function initAllShortcodes() {
|
|||||||
initVoiceBubbles();
|
initVoiceBubbles();
|
||||||
initMusicCards();
|
initMusicCards();
|
||||||
|
|
||||||
// 检查是否是 PJAX 导航
|
// 检查 sessionStorage 中是否有保存的播放状态
|
||||||
if (window.__isPjaxNavigation) {
|
// 如果有,恢复播放(无论是 PJAX 切换还是脚本重新加载)
|
||||||
// PJAX 导航:恢复播放状态(进度和播放状态)
|
// 如果没有,重置播放器(首次加载或刷新页面)
|
||||||
|
var savedState = AudioManager.restoreFromSession();
|
||||||
|
console.log('[AudioManager] initAllShortcodes - savedState:', savedState ? JSON.stringify(savedState) : null);
|
||||||
|
if (savedState && savedState.src) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
AudioManager.restorePlayingState();
|
AudioManager.restorePlayingState();
|
||||||
|
// 延迟释放锁,避免短时间内重复触发
|
||||||
|
setTimeout(function() { __shortcodesInitLock = false; }, 500);
|
||||||
}, 100);
|
}, 100);
|
||||||
// 重置标志
|
|
||||||
window.__isPjaxNavigation = false;
|
|
||||||
} else {
|
} else {
|
||||||
// 非 PJAX 导航(刷新页面/跳转):重置播放器到初始状态
|
// 没有保存的状态,重置播放器到初始状态
|
||||||
AudioManager.reset();
|
AudioManager.reset();
|
||||||
|
__shortcodesInitLock = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,8 +681,13 @@ document.addEventListener('pjax:beforeSend', function() {
|
|||||||
window.__isPjaxNavigation = true;
|
window.__isPjaxNavigation = true;
|
||||||
cleanupAllShortcodes();
|
cleanupAllShortcodes();
|
||||||
});
|
});
|
||||||
document.addEventListener('pjax:complete', initAllShortcodes);
|
document.addEventListener('pjax:complete', function() {
|
||||||
document.addEventListener('pjax:success', initAllShortcodes);
|
initAllShortcodes();
|
||||||
|
});
|
||||||
|
document.addEventListener('pjax:success', function() {
|
||||||
|
// pjax:success 在 pjax:complete 之前触发,已经被锁过滤
|
||||||
|
initAllShortcodes();
|
||||||
|
});
|
||||||
|
|
||||||
// Also listen for custom events that some PJAX libraries fire
|
// Also listen for custom events that some PJAX libraries fire
|
||||||
document.addEventListener('page:loaded', initAllShortcodes);
|
document.addEventListener('page:loaded', initAllShortcodes);
|
||||||
|
|||||||
Reference in new issue
Block a user