Site Notice
hello, world
MediaWiki:Js-new-discuss-notify.js
From Project-EPB Commons
Revision as of 00:09, 12 November 2019 by 机智的小鱼君 (talk | contribs) (Created page with "→* *『Wjghj Project Static』 * This _JavaScript_ code is from https://common.wjghj.cn * CC BY-NC-SA *: /** * New discuss notify * 近期当前页面有新讨论的...")
Invoke this: https://common.wjghj.cn/js/{{#replace:{{#replace:Js-new-discuss-notify.js|Js-|}}|.js|}}
Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
*『Wjghj Project Static』
* This _JavaScript_ code is from https://common.wjghj.cn
* CC BY-NC-SA
**/
/**
* New discuss notify
* 近期当前页面有新讨论的提醒
* Author: 机智的小鱼君(User:Xiaoyujun)
**/
$(function () {
if (!mw.config.get('wgIsArticle'))
return; // 不是文章页
var articleId = mw.config.get('wgArticleId');
new mw.Api().get({
action: 'query',
prop: 'info',
pageids: articleId,
inprop: 'talkid',
format: 'json'
}).done(function (query1) {
var talkId = query1.query.pages[articleId].talkid;
if (talkId === undefined) {
console.info('This page has no talk page ┓( ´∀` )┏');
return; // 不要再浪费流量发送两次请求了
}
console.info('This page\'s talk page id: '+talkId);
new mw.Api().get({
action: 'query',
prop: 'info',
pageids: talkId,
// inprop: 'timestamp',
format: 'json'
}).done(function (query2) {
var timestamp = query2.query.pages[talkId].touched;
console.info('Talk page\'s talk page recently edit at: '+new Date(timestamp));
var timestamp = new Date(timestamp).getTime(),
now = new Date().getTime(),
talkpage = query2.query.pages[talkId].title,
talklink = mw.config.get('wgArticlePath').replace('$1', talkpage);
console.info('Talk page title is: '+talkpage+'\nTalk page link: '+talklink);
if (now - timestamp < 1*24*60*60*1000 ) { // 一天之内(请计算毫秒数)
mw.notify($('<section class="has-new-discuss"><p style="font-size:18px">请检查最新讨论</p><p>在近一天内,有针对当前页面新的讨论,请<a href="javascript:;" class="has-new-discuss-link" target="_blank">点击这里</a>确认</p></section>'), {
autoHide: false
});
setTimeout(function () { // 给mw提示框播放动画的时间,照顾低配用户
$('.has-new-discuss-link').attr('href', talklink); // 替换链接地址
}, 500);
}
});
});
});