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



语音维基

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

(建立内容为“→‎这里的任何JavaScript将为所有用户在每次页面载入时加载。 (function(window, $, mw) { 'use strict'; //Load Protection if (window.OggPla…”的新页面
 
 
(未显示4个用户的97个中间版本)
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
+
$(document).ready(function () {
(function(window, $, mw) {
+
 
'use strict';
+
/* 处理直接下载的链接问题 */
//Load Protection
+
$('.download-link > a').each(function (_, n) {
if (window.OggPlayerLoaded) return;
+
    n.setAttribute('target', '_blank');
window.OggPlayerLoaded = true;
+
    n.setAttribute('download', n.getAttribute('title'));
//Load Localization
+
    n.setAttribute('title', '下载');
importArticle({type: 'script',article: 'u:dev:MediaWiki:I18n-js/code.js'});
+
});
//Load Style
+
 
importArticle({type: 'style',article: 'u:dev:MediaWiki:OggPlayer.css'})
+
/* 生成音频播放按钮 */
+
(function (){
//Default Setting
+
  var audios = document.getElementsByClassName('audio-player');
if(typeof window.oggPlayerButtonOnly == 'undefined') window.oggPlayerButtonOnly = false;
+
  var notValidAudio = /wpDestFile/;
+
  var currentPlaying = null;
function init(i18n) {
+
 
var OggPlayer = {
+
  for(var i = 0; i < audios.length; i++) {
support: '',
+
    var audio = audios[i];
allButtons: $([]),
+
    var linkEl = audio.firstElementChild;
monit: function($elem) {
+
 
if(!window.oggPlayerButtonOnly) $elem.find('.audio-button .ogg_player,.mediaContainer').each(OggPlayer.prepPlayer);
+
    if (!linkEl) {
$elem.find('.audio-button').each(OggPlayer.prepButton);
+
      continue;
},
+
    }
init: function() {
+
 
//Test Audio Support
+
    var link = linkEl.href;
OggPlayer.support = document.createElement('audio').canPlayType('audio/ogg');
+
 
OggPlayer.monit($(document));
+
    if (notValidAudio.test(link)) {
mw.hook('wikipage.content').add(OggPlayer.monit);
+
      continue;
},
+
    }
prepPlayer: function() {
+
 
var player = $(this);
+
    audio.innerHTML = '';
if(player.data('url')) return;
+
    audio.classList.add('has-audio-element');
var button = player.find('button[onclick]');
+
 
if(button.length) {
+
    var a = document.createElement('audio');
var onclick = button[0].onclick.toString();
+
 
+
    a.src = link;
var match, url, width, height, isVideo;
+
    a.preload = 'none';
if(match = onclick.match(/"videoUrl":"((?:\\.|[^"\\])+)"/)) url = match[1].replace('\\x26', '&');
+
 
if(match = onclick.match(/"width":([0-9]+)/)) width = match[1];
+
    a.onended = function () {
if(match = onclick.match(/"height":([0-9]+)/)) height = match[1];
+
      currentPlaying = null;
if(match = onclick.match(/"isVideo":(true|false)/)) isVideo = match[1] == 'true';
+
      this.parentNode.classList.remove('audio-player-playing');
+
    };
if(isVideo) {
+
 
OggPlayer.video(player, url, width, height);
+
    var button = document.createElement('button');
} else {
+
 
OggPlayer.audio(player, url, width);
+
    button.classList.add('audio-player-button');
}
+
    button.append(a);
} else {
+
    button.onclick = function () {
var p = player.find('audio[src], video[src], source[src]');
+
      var a = this.firstElementChild;
player.closest(".audio-button")
+
 
.data('src', p.attr('src'))
+
      if (currentPlaying != null && currentPlaying != a) {
.empty()//We know this is an audio-button class, so empty contents
+
        currentPlaying.pause();
.append(p);
+
        currentPlaying.currentTime = 0;
}
+
        currentPlaying.parentNode.classList.remove('audio-player-playing');
player.removeClass(['ogg_player','mediaContainer']).addClass('ogg-player').removeAttr('id');
+
      }
},
+
 
prepButton: function() {
+
      if (a.paused) {
var button = $(this);
+
        a.play();
if(button.prop('tagName') == 'A' || button.hasClass('no-audio')) return;
+
        currentPlaying = a;
var src = button.data('src'),
+
        this.classList.add('audio-player-playing');
sources = button.find('audio, video, button[onclick], img, a.internal');
+
        this.classList.remove('audio-player-paused');
if(OggPlayer.support === '') {
+
      }
button.attr('title', i18n.msg('no-support').plain()).addClass('no-audio').empty();
+
      else {
return;
+
        a.pause();
}
+
        this.classList.add('audio-player-paused');
+
        this.classList.remove('audio-player-playing');
if(typeof src == 'undefined' || !OggPlayer.isValid(src)) {
+
      };
sources.each(function(i, v) {
+
    };
v = $(v);
+
   
if(v.prop('tagName') == 'A') {
+
    audio.append(button);
src = v.attr('href');
+
  };
} else if(v.prop('tagName') == 'BUTTON') {
+
})();
var match, onclick = v[0].onclick.toString();
+
 
if(match = onclick.match(/"videoUrl":"((?:\\.|[^"\\])+)"/)) src = match[1];
+
/* 生成b站播放窗口 */
} else {
+
(function(){
src = v.attr('src');
+
            var bVideos = document.getElementsByClassName('bilibili');
}
+
            for(var i=0;i<bVideos.length;i++){
if(OggPlayer.isValid(src)) return false;
+
                var bVideo = bVideos[i];
src = false;
+
                var bvid = bVideo.textContent.trim();
});
+
                bVideo.innerHTML = '';
if(!src) {
+
                var iframe = document.createElement('iframe');
button.addClass('no-audio').empty().attr('title', i18n.msg('no-audio').plain());
+
                iframe.src = 'https://player.bilibili.com/player.html?page=1&bvid='+bvid;
return;
+
                iframe.scrolling = 'no';
}
+
                iframe.border = '0';
}
+
                iframe.frameborder = 'no';
var link = $('<a />', {
+
                iframe.framespacing='0';
'class': button.attr('class'),
+
                iframe.allowfullscreen='true';
'style': button.attr('style'),
+
                bVideo.append(iframe);
'data-src': button.data('src'),
+
            }
'title': i18n.msg('play').plain(),
+
})();
'href': src,
+
 
'click':function(e) {
+
/* 补齐丢失的MediaWiki快捷键 */
e.preventDefault();
+
$('#ca-edit').attr('accesskey','e');
var audio = $(this).find('audio');
+
$('#ca-edit').attr('title','编辑本页[alt-shift-e]');
if(audio.prop('paused')) {
+
$('#ca-talk').attr('accesskey','t');
OggPlayer.stopAllButtons();
+
$('#ca-talk').attr('title','关于内容页面的讨论[alt-shift-t]');
audio.trigger('play');
+
 
} else {
+
/* 右上角添加强制刷新按钮 */
audio.trigger('pause');
+
$('.wds-button-group #p-more .wds-list:not(.ns--1 .wds-list)').append('<li id="m-page-purge"><a href="?action=purge">强制刷新</a></li>');
}
+
 
return false;
+
/* 重新布局评论区 */
}
+
/*
});
+
(function () {
button.replaceWith(link);
+
  $('#allcomments .c-item').each(function(_, c) {
+
    var $commentItem = $(c);
if(link.hasClass('click-parent')) {
+
    var $score = $commentItem.find('.c-score');
if(!link.parent().hasClass('audio-button-parent')) {
+
 
link.parent().addClass('audio-button-parent').click(function(e) {
+
    $commentItem.prepend($score);
$(this).find('.click-parent').click();
+
    $commentItem.addClass('c-layout');
});
+
  });
} else {
+
})();
link.removeClass('click-parent');
+
*/
}
+
 
}
+
/* 使用占位图来代替受损图像链接(基本是图还没上传的) */
+
$('a.new').each(function(_, n) {
var audio = $('<audio />', {
+
  var href = n.getAttribute('href');
src: src,
+
  var isImage = /\.(png|jpe?g|svg|gif)$/.test(href);
preload: 'none',
+
 
}).appendTo(link).on('play', function(e) {
+
  if (isImage) {
$(this).parent().addClass('now-playing');
+
    // 将这个链接加上一个 class
}).on('pause', function(e) {
+
    n.classList.add('unresolved-image');
$(this).parent().removeClass('now-playing');
+
 
this.currentTime = 0;
+
    // 其文本内容则是设置的宽高
}).on('ended', function(e) {
+
    n.style.width = n.textContent;
$(this).trigger('pause');
+
    n.style.height = n.textContent;
}).on('error', function(e) {
+
  }
$(this).parent().addClass('no-audio').removeClass('now-playing').empty().attr('title', 'err' + i18n.msg('no-audio').plain());
+
});
});
+
 
OggPlayer.allButtons = OggPlayer.allButtons.add(audio);
+
/* 移除渲染延迟 Cloak */
},
+
$('.template-render-cloak').each(function(_, n) {
stopAllButtons: function() {
+
  n.classList.remove('template-render-cloak');
OggPlayer.allButtons.trigger('pause');
+
});
},
+
 
isValid: function(url) {
+
/* 生成音频播放-s按钮 */
if(url === undefined) return false;
+
(function (){
url = url.replace(/\?.*$/, '');
+
  var audios = document.getElementsByClassName('audio-player-s');
if(url.search(/(?:https?:)?(?:\/\/)(?:images|img|static|vignette)\d*\.wikia\.(?:nocookie\.)?(?:net|com)/) < 0 && url.search(/(?:https?:)?(?:\/\/)upload\.wikimedia\.org/) < 0) return false; // Wikia and Wikimedia only
+
  var notValidAudio = /wpDestFile/;
url = url.replace(/(vignette.*?)(\/revision.*$)/, '$1');
+
  var currentPlaying = null;
if(url.search(/\.(ogg|oga|ogv)$/) < 0) return false;
+
 
return true;
+
  for(var i = 0; i < audios.length; i++) {
},
+
    var audio = audios[i];
video: function(player, url, width, height) {
+
    var linkEl = audio.firstElementChild;
if(!url) return;
+
 
var a = player.find('a.image');
+
    if (!linkEl) {
player.addClass('ogg-video-player')
+
      continue;
.data('url', url)
+
    }
.empty()
+
 
.append(
+
    var link = linkEl.href;
$('<video />', {
+
 
controls : 'controls',
+
    if (notValidAudio.test(link)) {
width: width,
+
      continue;
height: height,
+
    }
src: url,
+
 
preload: 'metadata'
+
    audio.innerHTML = '';
})
+
    audio.classList.add('has-audio-element');
.click(function(){
+
 
this.paused ? this.play() : this.pause();
+
    var a = document.createElement('audio');
})
+
 
.dblclick(function(){
+
    a.src = link;
if(document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled) {
+
    a.preload = 'none';
if(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {
+
 
if(document.exitFullscreen) {
+
    a.onended = function () {
document.exitFullscreen();
+
      currentPlaying = null;
} else if(document.webkitExitFullscreen) {
+
      this.parentNode.classList.remove('audio-player-playing-s');
document.webkitExitFullscreen();
+
    };
} else if(document.mozCancelFullScreen) {
+
 
document.mozCancelFullScreen();
+
    var button = document.createElement('button');
} else if(document.msExitFullscreen) {
+
 
document.msExitFullscreen();
+
    button.classList.add('audio-player-button-s');
}
+
    button.append(a);
} else {
+
    button.onclick = function () {
if(this.requestFullscreen) {
+
      var a = this.firstElementChild;
this.requestFullscreen();
+
 
} else if(this.webkitRequestFullscreen) {
+
      if (currentPlaying != null && currentPlaying != a) {
this.webkitRequestFullscreen();
+
        currentPlaying.pause();
} else if(this.mozRequestFullScreen) {
+
        currentPlaying.currentTime = 0;
this.mozRequestFullScreen();
+
        currentPlaying.parentNode.classList.remove('audio-player-playing-s');
} else if(this.msRequestFullscreen) {
+
      }
this.msRequestFullscreen();
+
 
}
+
      if (a.paused) {
}
+
        a.play();
}
+
        currentPlaying = a;
})
+
        this.classList.add('audio-player-playing-s');
)
+
        this.classList.remove('audio-player-paused-s');
.append($('<a></a>').addClass('info-icon').attr({
+
      }  
href: a.attr('href'),
+
      else {
title: a.attr('title')
+
        a.pause();
}));
+
        this.classList.add('audio-player-paused-s');
},
+
        this.classList.remove('audio-player-playing-s');
audio: function(player, url, width) {
+
      };
if(!url) return;
+
    };
var a = player.find('a.image');
+
   
player.addClass('ogg-audio-player')
+
    audio.append(button);
.data('url', url)
+
  };
.empty()
+
})();
.append($('<audio>', {
+
 
controls : 'controls',
+
document.addEventListener('copy', function(e) {
src: url,
+
    var currentDate = new Date().toLocaleDateString();
preload: 'metadata'
+
    var alertCount = localStorage.getItem('alertCount');
}).css('width', width))
+
    if (!alertCount || JSON.parse(alertCount).date !== currentDate) {
.append($('<a>').addClass('info-icon').attr({
+
        alertCount = { date: currentDate, count: 1 };
href: a.attr('href'),
+
    } else {
title: a.attr('title')
+
        alertCount = JSON.parse(alertCount);
}));
+
        if (alertCount.count >= 1) {
}
+
            return; // 已经提醒了三次,不再提醒
};
+
        }
//If not fandom legacy
+
        alertCount.count++;
if (mw.config.get('wgVersion') !== '1.19.24')
+
    }
OggPlayer = {
+
 
constRef:{
+
    var remainingAlerts = 1 - alertCount.count; // 剩余提醒次数
wrapper:"audio-button",
+
    var alertMessage = "当您使用本维基中的文本作为创作素材时,请务必在您的作品简介或评论区明确标注出处。\n今日还会提醒" + remainingAlerts + "次。";
noSupport:"no-support",
+
 
noAudio:"no-audio",
+
    e.preventDefault();
nowPlaying:"now-playing",
+
    var copiedText = window.getSelection().toString();
OggAudio:"OggPlayer-Audio",
+
    alert(alertMessage);
play:"play"
+
    localStorage.setItem('alertCount', JSON.stringify(alertCount));
},
+
});
init: function() {
+
 
//Test Audio Support
+
});
var support = document.createElement('audio').canPlayType('audio/ogg');
 
if (support === "") return OggPlayer.noSupport();
 
mw.hook('wikipage.content').add(OggPlayer.monitor);
 
},
 
noSupport: function() {
 
$('.audio-button:not(.ready)').attr('title',i18n.msg(OggPlayer.constRef.noSupport).plain()).addClass(OggPlayer.constRef.noAudio);
 
},
 
monitor: function($elem) {
 
$elem.find('.audio-button').each(OggPlayer.eachInstance);
 
},
 
eachInstance: function() {
 
var instance = $(this);
 
//Normalize embed data to instance
 
if (instance.children().length) {
 
var focus = instance.find("a[href][class=internal],audio[src],video[src],source[src]");
 
instance.data("src",focus.attr("href")||focus.attr("src"));
 
}
 
//Create Button from instance src
 
OggPlayer.createButton(instance);
 
},
 
createButton: function(target) {
 
if (!OggPlayer.isValid(target.data('src')))
 
return OggPlayer.errorPlayer(target);
 
var audioObj = $('<audio>',{
 
src:target.data('src'),
 
preload:'none',
 
class:OggPlayer.constRef.OggAudio,
 
on:{
 
playing:function(){
 
$(this).parent().addClass(OggPlayer.constRef.nowPlaying);
 
},
 
pause:OggPlayer.stopThis,
 
ended:OggPlayer.stopThis,
 
error: function(){
 
OggPlayer.errorPlayer($(this).parent());
 
}
 
}
 
});
 
target.click(OggPlayer.clickButton).append(audioObj).attr('title',i18n.msg(OggPlayer.constRef.play).plain());
 
},
 
clickButton: function(){
 
var focusDom = $(this).find("audio."+OggPlayer.constRef.OggAudio).get(0);
 
var toPlay = false;
 
if (!focusDom.currentTime) toPlay = true;
 
OggPlayer.pauseAll();
 
if (toPlay) {
 
focusDom.preload="auto";
 
focusDom.play();
 
}
 
},
 
pauseAll: function(){
 
$("."+OggPlayer.constRef.nowPlaying+" audio."+OggPlayer.constRef.OggAudio).trigger("pause");
 
},
 
errorPlayer: function(player){
 
player.addClass(OggPlayer.constRef.noAudio).attr('title', i18n.msg(OggPlayer.constRef.noAudio).plain());
 
},
 
stopThis: function(){
 
$(this).parent().removeClass(OggPlayer.constRef.nowPlaying);
 
this.currentTime = 0;
 
},
 
isValid: function(url) {
 
if(url === undefined) return false;
 
url = url.replace(/\?.*$/, '');
 
if(url.search(/(?:https?:)?(?:\/\/)(?:images|img|static|vignette)\d*\.wikia\.(?:nocookie\.)?(?:net|com)/) < 0 && url.search(/(?:https?:)?(?:\/\/)upload\.wikimedia\.org/) < 0) return false; // Wikia and Wikimedia only
 
url = url.replace(/(vignette.*?)(\/revision.*$)/, '$1');
 
if(url.search(/\.(ogg|oga|ogv)/) < 0) return false; //Removed the ending tag ($) from previous author's vesion since regex strip didn't work too well
 
return true;
 
}
 
};
 
 
OggPlayer.init();
 
}
 
 
mw.hook('dev.i18n').add(function(i18n) {
 
i18n.loadMessages('OggPlayer').then(init);
 
});
 
})(this,jQuery, mediaWiki);
 

2024年4月5日 (五) 00:03的最新版本

$(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/;
  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');
    };

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

    button.classList.add('audio-player-button');
    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');
      }

      if (a.paused) {
        a.play();
        currentPlaying = a;
        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);
  };
})();

/* 生成b站播放窗口 */
(function(){
            var bVideos = document.getElementsByClassName('bilibili');
            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);
            }
})();

/* 补齐丢失的MediaWiki快捷键 */
$('#ca-edit').attr('accesskey','e');
$('#ca-edit').attr('title','编辑本页[alt-shift-e]');
$('#ca-talk').attr('accesskey','t');
$('#ca-talk').attr('title','关于内容页面的讨论[alt-shift-t]');

/* 右上角添加强制刷新按钮 */
$('.wds-button-group #p-more .wds-list:not(.ns--1 .wds-list)').append('<li id="m-page-purge"><a href="?action=purge">强制刷新</a></li>');

/* 重新布局评论区 */
/*
(function () {
  $('#allcomments .c-item').each(function(_, c) {
    var $commentItem = $(c);
    var $score = $commentItem.find('.c-score');

    $commentItem.prepend($score);
    $commentItem.addClass('c-layout');
  });
})();
*/

/* 使用占位图来代替受损图像链接(基本是图还没上传的) */
$('a.new').each(function(_, n) {
  var href = n.getAttribute('href');
  var isImage = /\.(png|jpe?g|svg|gif)$/.test(href);

  if (isImage) {
    // 将这个链接加上一个 class
    n.classList.add('unresolved-image');

    // 其文本内容则是设置的宽高
    n.style.width = n.textContent;
    n.style.height = n.textContent;
  }
});

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

/* 生成音频播放-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);
  };
})();

document.addEventListener('copy', function(e) {
    var currentDate = new Date().toLocaleDateString();
    var alertCount = localStorage.getItem('alertCount');
    if (!alertCount || JSON.parse(alertCount).date !== currentDate) {
        alertCount = { date: currentDate, count: 1 };
    } else {
        alertCount = JSON.parse(alertCount);
        if (alertCount.count >= 1) {
            return; // 已经提醒了三次,不再提醒
        }
        alertCount.count++;
    }

    var remainingAlerts = 1 - alertCount.count; // 剩余提醒次数
    var alertMessage = "当您使用本维基中的文本作为创作素材时,请务必在您的作品简介或评论区明确标注出处。\n今日还会提醒" + remainingAlerts + "次。";

    e.preventDefault();
    var copiedText = window.getSelection().toString();
    alert(alertMessage);
    localStorage.setItem('alertCount', JSON.stringify(alertCount));
});

});