You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
$(function(){
|
|
function isMobile(){
|
|
var userAgentInfo = navigator.userAgent;
|
|
var mobileAgents = ["Android", "iPhone",
|
|
"SymbianOS", "Windows Phone",
|
|
"iPad", "iPod"];
|
|
var flag = true;
|
|
for(var i = 0; i < mobileAgents.length; i ++){
|
|
if (userAgentInfo.indexOf(mobileAgents[isFinite]) != -1) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function initBackgroundImage(params){
|
|
let bgImg = new isekai.BgImage();
|
|
|
|
let bgImgElement = $('body').append('<div class="isekai-bgimg"></div>').find('div.isekai-bgimg:last');
|
|
|
|
bgImg.addViewport(bgImgElement);
|
|
|
|
bgImg.addBlurBackground($('#mw-mf-page-center'));
|
|
|
|
if(!('xcenter' in params)){
|
|
params.xcenter = 50;
|
|
}
|
|
if(!('ycenter' in params)){
|
|
params.ycenter = 50;
|
|
}
|
|
|
|
bgImg.loadImage(params.src, params.xcenter, params.ycenter);
|
|
}
|
|
|
|
var showBackgroundWidget = true;
|
|
if(isMobile() && !mw.user.options.get('isekai-bgimg-visible-mobile', true)){
|
|
showBackgroundWidget = false;
|
|
} else if(!mw.user.options.get('isekai-bgimg-visible-desktop', true)) {
|
|
showBackgroundWidget = false;
|
|
}
|
|
|
|
if(showBackgroundWidget){
|
|
var params = mw.config.get('isekaiBackgroundWidgetData');
|
|
if(params && params.src){
|
|
$('body').addClass('has-bgimg');
|
|
|
|
if(window.requestAnimationFrame){
|
|
window.requestAnimationFrame(function(){
|
|
initBackgroundImage(params);
|
|
});
|
|
} else {
|
|
setTimeout(function(){
|
|
initBackgroundImage(params);
|
|
}, 0);
|
|
}
|
|
} else {
|
|
console.log(mw.message('isekai-background-widget-param-error').parse(), params);
|
|
}
|
|
}
|
|
}); |