Site Notice

hello, world

Difference between revisions of "User:机智的小鱼君/common.js"

From Project-EPB Commons
([InPageEdit] 没有编辑摘要)
([InPageEdit] 没有编辑摘要)
Line 31: Line 31:
 
           talkpage = query2.query.pages[talkId].title,
 
           talkpage = query2.query.pages[talkId].title,
 
           talklink = mw.config.get('wgArticlePath').replace('$1', talkpage);
 
           talklink = mw.config.get('wgArticlePath').replace('$1', talkpage);
 +
      console.info('Talk page title is: '+talkpage+'\nTalk page link: '+talklink);
 
       if (now - timestamp < 86400000) { // 一天之内有新讨论
 
       if (now - timestamp < 86400000) { // 一天之内有新讨论
 
         mw.notify($('<section class="has-new-discuss"><p style="font-size:18px">请检查最新讨论</p><p>在近一天内,有针对当前页面新的讨论,请<a href="javascript:;" class="has-new-discuss-link">点击这里</a>确认</p></section>'), {
 
         mw.notify($('<section class="has-new-discuss"><p style="font-size:18px">请检查最新讨论</p><p>在近一天内,有针对当前页面新的讨论,请<a href="javascript:;" class="has-new-discuss-link">点击这里</a>确认</p></section>'), {
Line 37: Line 38:
 
         setTimeout(function () {
 
         setTimeout(function () {
 
           $('.has-new-discuss-link').attr('href', talklink);
 
           $('.has-new-discuss-link').attr('href', talklink);
         }, 100);
+
         }, 500);
 
       }
 
       }
 
     });
 
     });
 
   });
 
   });
 
});
 
});

Revision as of 23:52, 11 November 2019

mw.loader.load('https://common.wjghj.cn/js/InPageEdit-v2');
/** 
 * 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;
    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 < 86400000) { // 一天之内有新讨论
        mw.notify($('<section class="has-new-discuss"><p style="font-size:18px">请检查最新讨论</p><p>在近一天内,有针对当前页面新的讨论,请<a href="javascript:;" class="has-new-discuss-link">点击这里</a>确认</p></section>'), {
          autoHide: false
        });
        setTimeout(function () {
          $('.has-new-discuss-link').attr('href', talklink);
        }, 500);
      }
    });
  });
});