微件:沙盒:修订间差异
来自NMWiki
更多操作
Smalllqiang(留言 | 贡献) |
Smalllqiang(留言 | 贡献) |
||
| 第2行: | 第2行: | ||
<script> | <script> | ||
$(function() { | $(function() { | ||
var server = mw.config.get('wgServer'); | if (document.cookie.includes('accept_time=True')) { | ||
window.location.href = server; | return; | ||
} | |||
mw.loader.using('oojs-ui').then(function() { | |||
var server = mw.config.get('wgServer'); | |||
const dialog = new OO.ui.MessageDialog(); | |||
const windowManager = new OO.ui.WindowManager(); | |||
$('body').append(windowManager.$element); | |||
windowManager.addWindows([dialog]); | |||
const message = $('<div>') | |||
.append('警告,本页面含有<!--{$agerank|escape:'html'}-->内容。'); | |||
windowManager.openWindow(dialog, { | |||
title: '年龄分级警告', | |||
message: message, | |||
actions: [{ | |||
action: 'accept', | |||
label: '我不在意且1天内不再提示', | |||
flags: 'primary' | |||
}, { | |||
action: 'return', | |||
label: '返回主页', | |||
}] | |||
}).closed.then(function(data) { | |||
if (data && data.action === 'accept') { | |||
const date = new Date(); | |||
date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000)); | |||
const expires = "expires=" + date.toUTCString(); | |||
document.cookie = "accept_time=True;" + expires + ";path=/"; | |||
} else if (data && data.action === 'return') { | |||
window.location.href = server; | |||
} | |||
}); | |||
}); | |||
}); | }); | ||
</script> | </script> | ||
</includeonly> | </includeonly> | ||