最近初初再學習日文,在查詢 Forvo 網站的單字發音時,發現每個單字通常都有多位網友提供的音檔。如果需要一個一個手動點擊聆聽,實在缺乏效率且沒有耐心。
剛好試試網頁自動化的工具: 油猴 (篡改猴) ,寫完的 JS先在 Chrome 的 F12 Console 中測試,當時一切正常,音檔能夠一個接一個順利播放。但是從油猴執行時,腳本卻卡住不動。直到手動按下其中一個 Play 按鈕後才會開始啟動。
原來是近年 Chrome 為了防止網站載入時自動播放影音而影響使用者體驗,預設會阻擋未經手動互動的自動播放行為。
經過測試,從網路上找到最簡單的解法是直接將網站加入 Chrome 的音效白名單中。設定方式如下:
功能路徑: 在網址列輸入
chrome://settings/content/sound,即可將目標網站指定加入允許發出聲音的白名單中。
// ==UserScript==
// @name forvoAllPlay
// @namespace http://tampermonkey.net/
// @version 2026-08-04a
// @description Click all "Play" in the page
// @author E1 Taiwan
// @include https://zh.forvo.com/word/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=forvo.com
// @grant none
// ==/UserScript==
function anchorclick(node)
{
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var allowDefault = node.dispatchEvent(evt);
}
(function() {
'use strict';
// 詢問是否執行
if (!confirm('是否要開始自動點擊播放按鈕?')) {
console.log('使用者已取消執行。');
return;
}
console.log('將在 3 秒後開始執行...2');
// 等待網頁完全載入(含外部 JS 載入完成)
window.addEventListener('load', () => {
// 延遲 1.5 秒執行,確保 Forvo 官方的 Play 函數與音訊組件已完全初始化
setTimeout(async () => {
// 選擇頁面上所有發音按鈕
const playButtons = document.querySelectorAll('.play');
if (playButtons.length === 0) {
console.log("[Forvo Player] 網頁載入完成,但未找到任何發音按鈕。");
return;
}
console.log(`[Forvo Player] 偵測到 ${playButtons.length} 個發音,準備依序自動播放...`);
console.log("[Forvo Player] 提示:如果語音沒聲音,請滑鼠點擊網頁任意處以解除瀏覽器自動播放限制。");
// 依序播放每個發音
for (let i = 0; i < playButtons.length; i++) {
const btn = playButtons[i];
// 擷取並清洗 onclick 內的 JavaScript
let rawCode = btn.getAttribute('onclick');
if (!rawCode) continue;
let cleanCode = rawCode.replace(/return\s+false;?\s*$/, '');
console.log(`[Forvo Player] 正在播放 (${i + 1}/${playButtons.length})`);
try {
// 執行 Forvo 原生的播放函數
new Function(cleanCode)();
} catch (e) {
console.error("[Forvo Player] 播放執行失敗:", e);
}
// 每個發音間隔 4 秒,避免語音重疊(可根據需求調整此數值)
await new Promise(resolve => setTimeout(resolve, 3000));
}
console.log("[Forvo Player] 所有發音已播放完畢。");
}, 1500);
});
})();

