avatar
匿名用户
×
创建一个新的页面
输入页面标题:
目前语音维基上有2062个页面。 在上方输入您想创建的页面名称或单击以下标题之一,即可开始撰写!



语音维基

“MediaWiki:Mobile.js”的版本间的差异

标签移动网页编辑 移动版编辑
 
(未显示3个用户的12个中间版本)
第3行: 第3行:
 
/* 加载Mobile.css */
 
/* 加载Mobile.css */
 
mw.loader.using('mobile.site.styles');
 
mw.loader.using('mobile.site.styles');
 +
$(document).ready(function () {
 +
/* 处理直接下载的链接问题 */
 +
$('.download-link > a').each(function (_, n) {
 +
    n.setAttribute('target', '_blank');
 +
    n.setAttribute('download', n.getAttribute('title'));
 +
    n.setAttribute('title', '下载');
 +
});
  
/* 评论区评论表单置顶 */
+
/* 生成音频播放按钮 */
 
(function(){
 
(function(){
    var commentBody = document.getElementsByClassName('comments-body')[0];
+
var audios = document.getElementsByClassName('audio-player');
     if(commentBody == null) return;
+
var notValidAudio = /wpDestFile/;
    var commentForm = commentBody.getElementsByTagName('form')[1];
+
for(var i=0;i<audios.length;i++){
    commentBody.removeChild(commentForm);
+
var audio = audios[i];
    commentBody.insertBefore(commentForm, commentBody.childNodes[0]);
+
                var linkEl = audio.firstElementChild;
 +
      
 +
                if (!linkEl) {
 +
                  continue;
 +
                }
 +
 
 +
var link = linkEl.href;
 +
 
 +
if(notValidAudio.test(link)) continue;
 +
audio.innerHTML = '';
 +
                audio.classList.add('has-audio-element');
 +
               
 +
var a = document.createElement('audio');
 +
a.src = link;
 +
a.preload = 'none';
 +
a.onended = function(){
 +
this.parentNode.classList.remove('audio-player-playing');
 +
};
 +
var button = document.createElement('button');
 +
button.classList.add('audio-player-button');
 +
button.append(a);
 +
button.onclick = function(){
 +
var a = this.firstElementChild;
 +
if (a.paused){
 +
a.play();
 +
this.classList.add('audio-player-playing');
 +
this.classList.remove('audio-player-paused');
 +
}else{
 +
a.pause();
 +
this.classList.add('audio-player-paused');
 +
this.classList.remove('audio-player-playing');
 +
};
 +
};
 +
audio.append(button);
 +
};
 
})();
 
})();
  
/* section全展开 */
+
/* 生成音频播放-s按钮 */
(function(){
+
(function (){
    var collapsible = document.getElementsByClassName('collapsible-heading');
+
  var audios = document.getElementsByClassName('audio-player-s');
    for(var i=0;i<collapsible.length;i++)  
+
  var notValidAudio = /wpDestFile/;
        collapsible[i].classList.add('open-block');
+
  var currentPlaying = null;
     var collapsible = document.getElementsByClassName('ollapsible-block');
+
 
     for(var i=0;i<collapsible.length;i++)  
+
  for(var i = 0; i < audios.length; i++) {
        collapsible[i].classList.add('open-block');
+
    var audio = audios[i];
})();
+
    var linkEl = audio.firstElementChild;
 +
 
 +
    if (!linkEl) {
 +
      continue;
 +
    }
 +
 
 +
    var link = linkEl.href;
 +
 
 +
    if (notValidAudio.test(link)) {
 +
      continue;
 +
    }
 +
 
 +
    audio.innerHTML = '';
 +
    audio.classList.add('has-audio-element');
 +
 
 +
     var a = document.createElement('audio');
 +
 
 +
     a.src = link;
 +
    a.preload = 'none';
 +
 
 +
    a.onended = function () {
 +
      currentPlaying = null;
 +
      this.parentNode.classList.remove('audio-player-playing-s');
 +
    };
 +
 
 +
    var button = document.createElement('button');
  
/* 生成音频播放按钮 */
+
    button.classList.add('audio-player-button-s');
(function(){
+
    button.append(a);
            var audios = document.getElementsByClassName("audio-player");
+
    button.onclick = function () {
            var notValidAudio = /wpDestFile/;
+
      var a = this.firstElementChild;
            for(var i=0;i<audios.length;i++){
 
                var audio = audios[i];
 
                var link = audio.firstElementChild.href;
 
                if(notValidAudio.test(link)) continue;
 
                audio.innerHTML = "";
 
                var a = document.createElement('audio');
 
                a.src = link;
 
                a.preload = 'none';
 
                audio.append(a);
 
                var button = document.createElement('button');
 
                button.onclick = function(){
 
                    var audio = this.parentNode;
 
                    var a = audio.children[0];
 
                    if (a.paused){
 
                        a.play();
 
                        this.classList.add('audio-player-playing');
 
                        this.classList.remove('audio-player-paused');
 
                    }else{
 
                        a.pause();
 
                        this.classList.add('audio-player-paused');
 
                        this.classList.remove('audio-player-playing');
 
                    };
 
                };
 
  
                a.onended = function(){
+
      if (currentPlaying != null && currentPlaying != a) {
                    this.parentNode.children[1].classList.remove('audio-player-playing');
+
        currentPlaying.pause();
                };
+
        currentPlaying.currentTime = 0;
 +
        currentPlaying.parentNode.classList.remove('audio-player-playing-s');
 +
      }
  
                audio.append(button);
+
      if (a.paused) {
            };
+
        a.play();
 +
        currentPlaying = a;
 +
        this.classList.add('audio-player-playing-s');
 +
        this.classList.remove('audio-player-paused-s');
 +
      }
 +
      else {
 +
        a.pause();
 +
        this.classList.add('audio-player-paused-s');
 +
        this.classList.remove('audio-player-playing-s');
 +
      };
 +
    };
 +
   
 +
    audio.append(button);
 +
  };
 
})();
 
})();
  
/* 生成b站播放窗口 */
+
/* 移除渲染延迟 Cloak */
(function(){
+
$('.template-render-cloak').each(function(_, n) {
            var bVideos = document.getElementsByClassName("bilibili");
+
  n.classList.remove('template-render-cloak');
            for(var i=0;i<bVideos.length;i++){
+
});
                var bVideo = bVideos[i];
+
});
                var bvid = bVideo.textContent.trim();
 
                bVideo.innerHTML = "";
 
                var iframe = document.createElement('iframe');
 
                iframe.src = "https://player.bilibili.com/player.html?page=1&bvid=" + bvid;
 
                iframe.scrolling = "no";
 
                iframe.border = "0";
 
                iframe.frameborder = "no";
 
                iframe.framespacing="0";
 
                iframe.allowfullscreen="true";
 
                bVideo.append(iframe);
 
            }
 
})();
 

2023年12月18日 (一) 21:14的最新版本

/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */

/* 加载Mobile.css */
mw.loader.using('mobile.site.styles');
$(document).ready(function () {
/* 处理直接下载的链接问题 */
$('.download-link > a').each(function (_, n) {
    n.setAttribute('target', '_blank');
    n.setAttribute('download', n.getAttribute('title'));
    n.setAttribute('title', '下载');
});

/* 生成音频播放按钮 */
(function(){
	var audios = document.getElementsByClassName('audio-player');
	var notValidAudio = /wpDestFile/;
	for(var i=0;i<audios.length;i++){
		var audio = audios[i];
                var linkEl = audio.firstElementChild;
    
                if (!linkEl) {
                  continue;
                }

		var link = linkEl.href;

		if(notValidAudio.test(link)) continue;
		audio.innerHTML = '';
                audio.classList.add('has-audio-element');
                
		var a = document.createElement('audio');
		a.src = link;
		a.preload = 'none';
		a.onended = function(){
			this.parentNode.classList.remove('audio-player-playing');
		};
		var button = document.createElement('button');
		button.classList.add('audio-player-button');
		button.append(a);
		button.onclick = function(){
			var a = this.firstElementChild;
			if (a.paused){
				a.play();
				this.classList.add('audio-player-playing');
				this.classList.remove('audio-player-paused');
			}else{
				a.pause();
				this.classList.add('audio-player-paused');
				this.classList.remove('audio-player-playing');
			};
		};
		audio.append(button);
	};
})();

/* 生成音频播放-s按钮 */
(function (){
  var audios = document.getElementsByClassName('audio-player-s');
  var notValidAudio = /wpDestFile/;
  var currentPlaying = null;

  for(var i = 0; i < audios.length; i++) {
    var audio = audios[i];
    var linkEl = audio.firstElementChild;

    if (!linkEl) {
      continue;
    }

    var link = linkEl.href;

    if (notValidAudio.test(link)) {
      continue;
    }

    audio.innerHTML = '';
    audio.classList.add('has-audio-element');

    var a = document.createElement('audio');

    a.src = link;
    a.preload = 'none';

    a.onended = function () {
      currentPlaying = null;
      this.parentNode.classList.remove('audio-player-playing-s');
    };

    var button = document.createElement('button');

    button.classList.add('audio-player-button-s');
    button.append(a);
    button.onclick = function () {
      var a = this.firstElementChild;

      if (currentPlaying != null && currentPlaying != a) {
        currentPlaying.pause();
        currentPlaying.currentTime = 0;
        currentPlaying.parentNode.classList.remove('audio-player-playing-s');
      }

      if (a.paused) {
        a.play();
        currentPlaying = a;
        this.classList.add('audio-player-playing-s');
        this.classList.remove('audio-player-paused-s');
      } 
      else {
        a.pause();
        this.classList.add('audio-player-paused-s');
        this.classList.remove('audio-player-playing-s');
      };
    };
    
    audio.append(button);
  };
})();

/* 移除渲染延迟 Cloak */
$('.template-render-cloak').each(function(_, n) {
  n.classList.remove('template-render-cloak');
});
});