@ -57,14 +57,14 @@ function getPageVisited(){
}
}
}
}
function setDismiss ( ) {
function setDismiss LoginPrompt ( ) {
var time = Date . now ( ) / 1000 ;
var time = Date . now ( ) / 1000 ;
localStorage . setItem ( 'dismissLoginPrompt' , time . toFixed ( 0 ) ) ;
localStorage . setItem ( 'dismissLoginPrompt' , time . toFixed ( 0 ) ) ;
}
}
function shouldShow Prompt( ) {
function shouldShow Login Prompt( ) {
if ( ! mw . user . isAnon ( ) ) { //用户已登录
if ( ! mw . user . isAnon ( ) ) { //用户已登录
setDismiss ( ) ;
setDismiss LoginPrompt ( ) ;
return false ;
return false ;
}
}
@ -90,6 +90,29 @@ function shouldShowPrompt(){
return true ;
return true ;
}
}
function setDismissAdsPrompt ( ) {
var time = Date . now ( ) / 1000 ;
localStorage . setItem ( 'dismissAdsPrompt' , time . toFixed ( 0 ) ) ;
}
function shouldShowAdsPrompt ( ) {
if ( mw . config . get ( 'wgCanonicalNamespace' ) === 'Special' && mw . config . get ( 'wgAction' ) === 'view' ) { // 仅查看页面弹出
return false ;
}
var time = Date . now ( ) / 1000 ;
var expire = 86400 * 7 ; //7天内不提醒
var dismissTime = localStorage . getItem ( 'dismissAdsPrompt' ) ;
if ( dismissTime !== null ) {
dismissTime = parseInt ( dismissTime ) ;
if ( dismissTime + expire > time ) {
return false ;
}
}
return true ;
}
$ ( function ( ) {
$ ( function ( ) {
//锚链接偏移
//锚链接偏移
$ ( 'body' ) . on ( 'click' , 'a' , function ( ) {
$ ( 'body' ) . on ( 'click' , 'a' , function ( ) {
@ -122,6 +145,8 @@ $(function(){
// 初始化dialog
// 初始化dialog
var messageDialog = new OO . ui . MessageDialog ( ) ;
var messageDialog = new OO . ui . MessageDialog ( ) ;
var windowManager = new OO . ui . WindowManager ( ) ;
var windowManager = new OO . ui . WindowManager ( ) ;
window . _isekaiMessageDialog = messageDialog ;
window . _isekaiWindowManager = windowManager ;
$ ( 'body' ) . append ( windowManager . $element ) ;
$ ( 'body' ) . append ( windowManager . $element ) ;
windowManager . addWindows ( [ messageDialog ] ) ;
windowManager . addWindows ( [ messageDialog ] ) ;
@ -164,6 +189,7 @@ $(function(){
}
}
//显示登录引导框
//显示登录引导框
if ( shouldShowLoginPrompt ( ) ) {
var cancelBtn = new OO . ui . ActionWidget ( {
var cancelBtn = new OO . ui . ActionWidget ( {
action : 'cancel' ,
action : 'cancel' ,
label : mw . message ( 'isekai-login-prompt-btn-cancel' ) . text ( ) ,
label : mw . message ( 'isekai-login-prompt-btn-cancel' ) . text ( ) ,
@ -183,7 +209,7 @@ $(function(){
} ) ;
} ) ;
cancelBtn . on ( 'click' , function ( ) {
cancelBtn . on ( 'click' , function ( ) {
setDismiss ( ) ;
setDismissLoginPrompt ( ) ;
} ) ;
} ) ;
registerBtn . on ( 'click' , function ( ) {
registerBtn . on ( 'click' , function ( ) {
@ -194,13 +220,71 @@ $(function(){
location . href = mw . util . getUrl ( 'Special:Userlogin' , { returnto : mw . config . get ( 'wgPageName' ) } ) ;
location . href = mw . util . getUrl ( 'Special:Userlogin' , { returnto : mw . config . get ( 'wgPageName' ) } ) ;
} ) ;
} ) ;
if ( shouldShowPrompt ( ) ) {
windowManager . openWindow ( messageDialog , {
windowManager . openWindow ( messageDialog , {
message : mw . message ( 'isekai-login-prompt-content' ) . parse ( ) ,
message : mw . message ( 'isekai-login-prompt-content' ) . parse ( ) ,
actions : [ cancelBtn , loginBtn ] , // 去除注册按钮
actions : [ cancelBtn , loginBtn ] , // 去除注册按钮
} ) ;
} ) ;
}
}
// 广告存活检测
if ( mw . config . get ( 'wgIsekaiShowAds' ) ) {
setTimeout ( function ( ) {
if ( $ ( '#ad-dec-7kVsyacCEKVGBLOiLVQ' ) . length === 0 ) {
if ( shouldShowAdsPrompt ( ) ) {
//显示广告引导框
var cancelBtn = new OO . ui . ActionWidget ( {
action : 'cancel' ,
label : mw . message ( 'isekai-ads-prompt-btn-cancel' ) . text ( ) ,
active : true ,
flags : [ 'safe' , 'close' ] ,
} ) ;
cancelBtn . on ( 'click' , function ( ) {
setDismissAdsPrompt ( ) ;
} ) ;
windowManager . openWindow ( messageDialog , {
title : mw . message ( 'isekai-ads-prompt-title' ) . parse ( ) ,
message : '' ,
size : 'medium' ,
actions : [ cancelBtn ] ,
} ) ;
messageDialog . $body . find ( '> .oo-ui-messageDialog-container > .oo-ui-messageDialog-text > .oo-ui-messageDialog-message' )
. append ( mw . message ( 'isekai-ads-prompt-content' ) . parse ( ) ) ;
}
}
} , 500 ) ;
}
/ * 展 示 G o o g l e 的 A d b l o c k 提 示 , 但 是 在 大 陆 貌 似 没 有 用
if ( mw . config . get ( 'wgIsekaiShowAds' ) ) {
window . googlefc = window . googlefc || { } ;
window . googlefc . callbackQueue = window . googlefc . callbackQueue || [ ] ;
googlefc . controlledMessagingFunction = ( message ) => {
if ( shouldShowAdsPrompt ( ) ) {
message . proceed ( true ) ;
} else {
message . proceed ( false ) ;
}
} ;
function signalGooglefcPresent ( ) {
if ( ! window . frames [ 'googlefcPresent' ] ) {
if ( document . body ) {
const iframe = document . createElement ( 'iframe' ) ;
iframe . style = 'width: 0; height: 0; border: none; z-index: -1000; left: -1000px; top: -1000px;' ;
iframe . style . display = 'none' ;
iframe . name = 'googlefcPresent' ;
document . body . appendChild ( iframe ) ;
setDismissAdsPrompt ( ) ;
} else {
window . requestAnimationFrame ( signalGooglefcPresent ) ;
}
}
}
signalGooglefcPresent ( ) ;
} * /
// 显示用户头像
// 显示用户头像
if ( mw . config . get ( 'wgNamespaceNumber' ) === 2 && mw . config . get ( 'wgAvatarTemplate' ) ) {
if ( mw . config . get ( 'wgNamespaceNumber' ) === 2 && mw . config . get ( 'wgAvatarTemplate' ) ) {
$ ( '<div id="userHeading" class="user-heading"></div>' ) . insertAfter ( "#firstHeading" ) ;
$ ( '<div id="userHeading" class="user-heading"></div>' ) . insertAfter ( "#firstHeading" ) ;
@ -213,6 +297,7 @@ $(function(){
userHeading . append ( ` <img src=" ${ avatarUrl } " alt=" ${ avatarAlt } " class="user-avatar"> ` ) ;
userHeading . append ( ` <img src=" ${ avatarUrl } " alt=" ${ avatarAlt } " class="user-avatar"> ` ) ;
}
}
// 更改ContentTranslation的机器翻译名字
if ( mw . cx && mw . cx . MachineTranslationManager ) {
if ( mw . cx && mw . cx . MachineTranslationManager ) {
let _getProviderLabel = mw . cx . MachineTranslationManager . prototype . getProviderLabel ;
let _getProviderLabel = mw . cx . MachineTranslationManager . prototype . getProviderLabel ;
mw . cx . MachineTranslationManager . prototype . getProviderLabel = function ( provider ) {
mw . cx . MachineTranslationManager . prototype . getProviderLabel = function ( provider ) {