打开/关闭菜单
Toggle preferences menu
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Gadget-dicenteries.js:修订间差异

MediaWiki界面页面
(创建页面,内容为“function addSound(){ c = 0 $('.word_entries_container').each(function(){ btn = $('<button id="soundBtn-'+c+'" class="sound_button" onclick="autoPlay()" style="display:inline-block;">' +' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"' +' class="bi bi-play-circle" viewBox="0 0 16 16">' +'<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0…”)
 
无编辑摘要
 
(未显示同一用户的7个中间版本)
第1行: 第1行:
function addSound(){
function addSound(){
     c = 0
     var c = 0
     $('.word_entries_container').each(function(){
     $('.word_entries_container').each(function(){
     btn = $('<button id="soundBtn-'+c+'" class="sound_button" onclick="autoPlay()" style="display:inline-block;">'
     btn = $('<button id="soundBtn-'+c+'" class="sound_button" style="display:inline-block;">'
                   +' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"'
                   +' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"'
                         +' class="bi bi-play-circle" viewBox="0 0 16 16">'
                         +' class="bi bi-play-circle" viewBox="0 0 16 16">'
第10行: 第10行:
                     +'</svg></button>')
                     +'</svg></button>')
     var en = $(this).children('.sub_container').children('.word_name').children('.word_en').text()
     var en = $(this).children('.sub_container').children('.word_name').children('.word_en').text()
     $('<audio src="https://dict.youdao.com/dictvoice?audio='+en+'" id=sound-"'+c+'" controls="controls" hidden="true">').appendTo($(this))
    console.log(en)
     $('<audio src="https://dict.youdao.com/dictvoice?audio='+en+'" id="sound-'+c+'" controls="controls" hidden="true">').appendTo($(this))
     $(this).children('.sub_container').children('.sound').append(btn)
     $(this).children('.sub_container').children('.sound').append(btn)
     $('#soundBtn-'+c).bind("click",function (){
     $('#soundBtn-'+c).bind("click",{c:c},autoPlay)
    autoPlay('sound-'+c)
    })
     c+=1
     c+=1
     })
     })
第20行: 第19行:
}
}


function autoPlay(id) {
function autoPlay(event) {
     var myAuto = document.getElementById(id);
console.log(event.data.c)
     var myAuto = document.getElementById('sound-'+event.data.c);
     myAuto.play();
     myAuto.play();
}
}


addSound()
addSound()

2022年11月29日 (二) 10:24的最新版本

function addSound(){
	
    var c = 0
    $('.word_entries_container').each(function(){
    	btn = $('<button id="soundBtn-'+c+'" class="sound_button" style="display:inline-block;">'
                   +' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"'
                        +' class="bi bi-play-circle" viewBox="0 0 16 16">'
                        +'<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>'
                        +'<path d="M6.271 5.055a.5.5 0 0 1 .52.038l3.5 2.5a.5.5 0 0 1 0 .814l-3.5 2.5A.5.5 0 0 1 6 10.5v-5a.5.5 0 0 1 .271-.445z"/>'
                    +'</svg></button>')
    	var en = $(this).children('.sub_container').children('.word_name').children('.word_en').text()
	    console.log(en)
    	$('<audio src="https://dict.youdao.com/dictvoice?audio='+en+'" id="sound-'+c+'" controls="controls" hidden="true">').appendTo($(this))
    	$(this).children('.sub_container').children('.sound').append(btn)
    	$('#soundBtn-'+c).bind("click",{c:c},autoPlay)
    	c+=1
    })
    
}

function autoPlay(event) {
	console.log(event.data.c)
    var myAuto = document.getElementById('sound-'+event.data.c);
    myAuto.play();
}

addSound()