MediaWiki:Common.js
From KAYŌ 💖 DAY
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
// Google Tag Manager
// (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
// new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
// j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
// 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
// })(window,document,'script','dataLayer','GTM-N5T4RZK');
// 计算运行天数
var now = new Date().getTime()
var then = new Date('2007-07-27 22:19').getTime()
var runningDays = Math.ceil((now - then) / 1000 / 86400)
var runningYears = (runningDays / 365).toFixed(1)
$('#running-days').text(runningDays)
$('#running-years').text(runningYears)
if (runningDays && runningYears) {
$('#running').show().css('display', 'block')
}
// 引用播放器代码
$('head').append($("<script>").attr({
type: 'text/javascript',
src: 'https://cdn.jsdelivr.net/npm/mediaelement@4.2.14/build/mediaelement-and-player.min.js'
}))
// 导航加随机背景图
var pipingUrl
if ($('.image').length > 0) {
var selectedImage = $('.image')[Math.ceil(Math.random() * $('.image').length) - 1].href
$.get(selectedImage, function (data) {
pipingUrl = $(data).find('.fullImageLink a').attr('href')
// if ($('.piping').length === 0) {
// $('#page-content').before('<div class="piping"></div>')
// $('footer').after('<div class="piping"></div>')
// }
$('.top-bar').css({
// 'height': $('.top-bar').height(),
'background': 'linear-gradient(to right, #000 20%, transparent 50%), url(' + pipingUrl + ') 100% center / 80% auto no-repeat',
})
})
};
// 删除 tagline
$('#tagline').remove()
$('#sitesub').remove()
// 厂牌如果为空,删除十字架符号
$('.record-label').each(function () {
if ($(this).text() === '†') {
$(this).remove()
}
});
// 清除“监视本页”选中状态
if (window.location.href.toLowerCase().indexOf('edit') ||
window.location.href.toLowerCase().indexOf('special')) {
$('#wpWatchthis').removeAttr('checked')
$('#wpIgnoreWarning').attr('checked', true)
};
// 播放器
$('.btn-play-audio:not([data-file="none"])').addClass('show')
$('*[data-file="none"]').remove()
var playerCode = '<div id="player"><p class="track-title"> </p></div>'
$('body').append(playerCode)
if ($.fn.mediaelementplayer) {
$('video, audio').mediaelementplayer({
pluginPath: 'https://cdnjs.com/libraries/mediaelement/',
shimScriptAccess: 'always',
})
}
$('.btn-play-audio').on('click', function () {
if ($.fn.mediaelementplayer) {
$('video, audio').mediaelementplayer({
pluginPath: 'https://cdnjs.com/libraries/mediaelement/',
shimScriptAccess: 'always',
})
}
var url = '/audio/' + $(this).attr('data-file') + '.mp3'
var title = $(this).attr('data-file').split('-')[$(this).attr('data-file').split('-').length - 1]
$('.btn-play-audio').removeClass('playing')
$(this).addClass('playing')
$('#player').addClass('show')
$('#player .track-title').text(title)
$('#player audio').attr('src', url)
$('#player audio')[0].volume = 0.6
$('#player audio')[0].play()
// if ($('#player audio')[0].paused) {
// $('.btn-play-audio').removeClass('playing')
// } else {
// $('.btn-play-audio').removeClass('playing')
// }
})
}())
