我試圖創建一個的Greasemonkey腳本,將檢查頁面標記後的<a>
標籤的MP3,並與HTML5的<audio>
標籤替換它們。但我無法理解如何做到這一點。有人能指出我在這裏出錯的地方嗎?謝謝。與<audio tags>更換<a>標籤時,文件類型匹配
<html><body>
<!-- tags, might ir might not have ids -->
<a id="myid" href="mp3/basic.phrases.1.mp3">Some mp3 file1.mp3</a><br />
<a href="mp3/basic.phrases.2.mp3">Some mp3 file2.mp3</a><br />
<script language="JavaScript">
var findAtags = document.getElementsByTagName('a');
for(var i = 0; i < findAtags.length; i++) {
var audioTag = document.createElement("audio");
var ext = findAtags[i].getAttribute("href").split('.').pop();
if(ext == "mp3") {
document.write(findAtags[i] + '[' + i + '] == ' + ext + '<br>');
document.body.replaceChild(audioTag, findAtags[0]);
// I would need to replace the <a href="..." ></a> with '<audio> <source src="' + findAtags[i] + '" type="audio/mp3" /> </audio>';
};
}
</script>
</body></html>
的可能重複的[檢測並修改MP3鏈接的javaScript](http://stackoverflow.com/questions/8586386/detecting-and-changing-mp3-links-javascript) – Incognito 2011-12-23 21:47:45