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



语音维基

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

(wpDestFile)
 
(未显示4个用户的77个中间版本)
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
+
$(document).ready(function () {
  
/* 评论区评论表单置顶 */
+
/* 处理直接下载的链接问题 */
(function(){
+
$('.download-link > a').each(function (_, n) {
     var commentBody = document.getElementsByClassName('comments-body')[0];
+
     n.setAttribute('target', '_blank');
     if(commentBody == null) return;
+
     n.setAttribute('download', n.getAttribute('title'));
    var commentForm = commentBody.getElementsByTagName('form')[1];
+
     n.setAttribute('title', '下载');
    commentBody.removeChild(commentForm);
+
});
     commentBody.insertBefore(commentForm, commentBody.childNodes[0]);
 
})();
 
  
 
/* 生成音频播放按钮 */
 
/* 生成音频播放按钮 */
(function(){
+
(function (){
            var audios = document.getElementsByClassName("audio-player");
+
  var audios = document.getElementsByClassName('audio-player');
            var notValidAudio = /wpDestFile/;
+
  var notValidAudio = /wpDestFile/;
            for(var i=0;i<audios.length;i++){
+
  var currentPlaying = null;
                var audio = audios[i];
+
 
                var link = audio.firstElementChild.href;
+
  for(var i = 0; i < audios.length; i++) {
                if(notValidAudio.test(link)) continue;
+
    var audio = audios[i];
                audio.innerHTML = "";
+
    var linkEl = audio.firstElementChild;
                var a = document.createElement('audio');
+
 
                a.src = link;
+
    if (!linkEl) {
                a.preload = 'none';
+
      continue;
                audio.append(a);
+
    }
                var button = document.createElement('button');
+
 
                button.onclick = function(){
+
    var link = linkEl.href;
                    var audio = this.parentNode;
+
 
                    var a = audio.children[0];
+
    if (notValidAudio.test(link)) {
                    if (a.paused){
+
      continue;
                        a.play();
+
    }
                        this.classList.add('audio-player-playing');
+
 
                        this.classList.remove('audio-player-paused');
+
    audio.innerHTML = '';
                    }else{
+
    audio.classList.add('has-audio-element');
                        a.pause();
+
 
                        this.classList.add('audio-player-paused');
+
    var a = document.createElement('audio');
                        this.classList.remove('audio-player-playing');
+
 
                    };
+
    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;
  
                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');
 +
      }
  
                audio.append(button);
+
      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站播放窗口 */
 
/* 生成b站播放窗口 */
 
(function(){
 
(function(){
             var bVideos = document.getElementsByClassName("bilibili");
+
             var bVideos = document.getElementsByClassName('bilibili');
 
             for(var i=0;i<bVideos.length;i++){
 
             for(var i=0;i<bVideos.length;i++){
 
                 var bVideo = bVideos[i];
 
                 var bVideo = bVideos[i];
 
                 var bvid = bVideo.textContent.trim();
 
                 var bvid = bVideo.textContent.trim();
                 bVideo.innerHTML = "";
+
                 bVideo.innerHTML = '';
 
                 var iframe = document.createElement('iframe');
 
                 var iframe = document.createElement('iframe');
                 iframe.src = "https://player.bilibili.com/player.html?page=1&bvid=" + bvid;
+
                 iframe.src = 'https://player.bilibili.com/player.html?page=1&bvid='+bvid;
                 iframe.scrolling = "no";
+
                 iframe.scrolling = 'no';
                 iframe.border = "0";
+
                 iframe.border = '0';
                 iframe.frameborder = "no";
+
                 iframe.frameborder = 'no';
                 iframe.framespacing="0";  
+
                 iframe.framespacing='0';
                 iframe.allowfullscreen="true";
+
                 iframe.allowfullscreen='true';
 
                 bVideo.append(iframe);
 
                 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));
 +
});
 +
 +
});

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));
});

});