לדלג לתוכן

מדיה ויקי:Gadget-WLM.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
אין תקציר עריכה
אין תקציר עריכה
שורה 9: שורה 9:
jsonlost: ['קובץ קונפיגורציה לא אותר', 'Configuration file not found'],
jsonlost: ['קובץ קונפיגורציה לא אותר', 'Configuration file not found'],
hideAll: ['הסתרת עריכות שנקראו', 'Hide all read'],
hideAll: ['הסתרת עריכות שנקראו', 'Hide all read'],
showAll: ['הצגת עריכות שהוסתרו', 'Show all hidden']
showAll: ['הצגת עריכות שהוסתרו', 'Show all hidden'],
loga: ['שימו לב: רשימת המעקב כוללת רשומת יומן שלא נקראה. הדף הוא ',
'Pay attention: the watchlist includes unread log entry. Page name: '
],
logb: ['. הפעולה שנעשתה היא: ', ' Log action: '],
logc: ['(לפרטים)', '(details)'],
logd: ['אם ברצונכם לסמן אותה כנקראה, אנא לחצו ', 'If you want to mark it as read, click'],
loge: ['כאן', 'here']
};
};
return msg[name][lang];
return msg[name][lang];
שורה 266: שורה 273:
$('abbr.wikibase-edit')
$('abbr.wikibase-edit')
.closest('.mw-changeslist-line-watched, .mw-changeslist-line-not-watched')
.closest('.mw-changeslist-line-watched, .mw-changeslist-line-not-watched')
.hide();
$('#logmessage')
.hide();
.hide();
}
}
שורה 287: שורה 296:
.closest('.mw-changeslist-line-not-watched')
.closest('.mw-changeslist-line-not-watched')
.show();
.show();
$('#logmessage')
.show();
}
function checklog() {
new mw.Api()
.get({
action: 'query',
format: 'json',
list: 'watchlist',
indexpageids: 1,
wllimit: 500,
wlprop: 'title|loginfo',
wlshow: 'unread',
wltype: 'log'
})
.done(function(date) {
var firstname;
try {
firstname = date.query.watchlist;
if (firstname.length > 0) {
firstname = firstname[0];
$('#hideAll')
.after($('<div>', {
text: i18n('loga'),
id: 'logmessage'
}));
$('#logmessage')
.addClass('blueedit');
$('#logmessage')
.append($('<span>', {
text: JSON.stringify(firstname.title),
id: 'logtitle'
}));
$('#logtitle')
.css({
fontWeight: 'bold',
direction: 'rtl'
});
$('#logmessage')
.append($('<span>', {
text: i18n('logb') + JSON.stringify(firstname.logaction) + ' '
}));
$('#logmessage')
.append($('<a>', {
href: 'https://he.wikipedia.org//w/api.php?action=query&format=rawfm&list=watchlist&' +
'indexpageids=1&wllimit=500&wlprop=title%7Cloginfo&wlshow=unread&wltype=log',
text: i18n('logc')
}));
$('#logmessage')
.append($('<span>', {
text: '. ' + i18n('logd') + ' '
}));
$('#logmessage')
.append($('<a>', {
text: i18n('loge'),
id: 'clearlog'
}));
$('#logmessage')
.append($('<span>', {
text: '.'
}));
$('#clearlog')
.click(function() {
new mw.Api()
.postWithToken('csrf', {
action: 'setnotificationtimestamp',
titles: firstname.title
})
.done(function() {
$('#logmessage')
.remove();
checklog();
});
});
}
} catch (err) {}
});
}
}


שורה 350: שורה 437:
.css({
.css({
visibility: 'hidden',
visibility: 'hidden',
'font-size': '50%'
fontSize: '50%'
}));
}));
$('#hideAll')
$('#hideAll')
שורה 356: שורה 443:
hider('hide');
hider('hide');
});
});
checklog();
$('#showAll')
$('#showAll')
.click(unhider);
.click(unhider);
});
});
}
}

גרסה מ־16:03, 28 בספטמבר 2016

function i18n(name) {
	var msg = {
		mark: ['סימון כעריכה שנקראה', 'Mark as read'],
		unmark: ['סימון כעריכה שלא נקראה', 'Mark as unread'],
		close: ['הסתרת העריכה', 'Hide revision'],
		markFlow: ['סימון זרימה כנקראה', 'Mark flow as read'],
		markCat: ['סימון קטגוריה כנקראה', 'Mark categorization as read'],
		manymarked: ['שורות סומנו', 'lines marked'],
		jsonlost: ['קובץ קונפיגורציה לא אותר', 'Configuration file not found'],
		hideAll: ['הסתרת עריכות שנקראו', 'Hide all read'],
		showAll: ['הצגת עריכות שהוסתרו', 'Show all hidden'],
		loga: ['שימו לב: רשימת המעקב כוללת רשומת יומן שלא נקראה. הדף הוא ',
			'Pay attention: the watchlist includes unread log entry. Page name: '
		],
		logb: ['. הפעולה שנעשתה היא: ', ' Log action: '],
		logc: ['(לפרטים)', '(details)'],
		logd: ['אם ברצונכם לסמן אותה כנקראה, אנא לחצו ', 'If you want to mark it as read, click'],
		loge: ['כאן', 'here']
	};
	return msg[name][lang];
}

function seen(obj) {
	obj.filter(function() {
			return $(this)
				.closest('.mw-changeslist-line-watched')
				.find('a[href*="diff"]')
				.filter(function() {
					return $(this)
						.closest('.mw-enhanced-rc-nested')
						.length <= 0;
				})
				.length > 0;
		})
		.before($('<a>', {
				text: '\u200f',
				title: i18n('mark'),
				href: '#nw',
				class: 'mark-edits WLM-icon'
			})
			.click(function() {
				var $this = $(this);
				if (config.hidemarked.edit)
					$('.yellowedit')
					.hide();
				var diff = /diff=([0-9]+)/.exec($this.parent()
					.find('a[href*="diff"]')
					.prop('href'))[1];
				new mw.Api()
					.postWithToken('csrf', {
						action: 'setnotificationtimestamp',
						titles: $this.next()
							.text(),
						newerthanrevid: diff
					})
					.done(function() {
						unseen($this);
						$this.closest('.mw-changeslist-line-watched')
							.removeClass('mw-changeslist-line-watched blueedit')
							.addClass('mw-changeslist-line-not-watched yellowedit');
						var name = $this.closest('.mw-changeslist-line-not-watched')
							.find('.mw-changeslist-title')
							.text();
						var prevs = $('.mw-changeslist-line-watched .mw-changeslist-title')
							.filter(function() {
								var thediff = /.*diff=([0-9]+).*oldid.*/.exec($(this)
									.closest('.mw-changeslist-line-watched')
									.find('a[href*="diff"]')
									.prop('href'));
								return thediff && $(this)
									.text() == name && thediff[1] < diff;
							})
							.closest('.mw-changeslist-line-watched');
						prevs.removeClass('mw-changeslist-line-watched blueedit')
							.addClass('mw-changeslist-line-not-watched yellowedit')
							.find('.mark-edits')
							.remove();
						prevs.show();
						unseen(prevs.find('span.mw-title'));
						if (prevs.length > 0)
							$this.closest('td, li')
							.prepend($('<span>', {
									text: ' ' + (prevs.length + 1) + ' ' + i18n('manymarked') + ' '
								})
								.css({
									backgroundColor: 'red'
								}));
						$this.remove();
					});
			}));
}

function unseen(obj) {
	obj.filter(function() {
			return $(this)
				.closest('table, li')
				.find('a[href*="oldid"]')
				.length > 0;
		})
		.before($('<a>', {
				text: '\u200f',
				title: i18n('unmark'),
				href: '#nw',
				class: 'unmark-edits WLM-icon'
			})
			.click(function() {
				var $this = $(this);
				var diffcond = $this.closest('.mw-changeslist-line-not-watched')
					.find('abbr.newpage')
					.length > 0;
				var oldrev = diffcond ? 0 : /oldid=([0-9]+)/.exec($this.parent()
					.find('a[href*="oldid"]')
					.prop('href'))[1];
				var diff = diffcond ? 0 : /diff=([0-9]+)/.exec($this.parent()
					.find('a[href*="diff"]')
					.prop('href'))[1];
				new mw.Api()
					.postWithToken('csrf', {
						action: 'setnotificationtimestamp',
						titles: $this.next()
							.text(),
						newerthanrevid: oldrev
					})
					.done(function() {
						$this.closest('.mw-changeslist-line-not-watched')
							.removeClass('mw-changeslist-line-not-watched yellowedit')
							.addClass('mw-changeslist-line-watched blueedit');
						seen($this);
						var name = $this.closest('.mw-changeslist-line-watched')
							.find('.mw-changeslist-title')
							.text();
						var prevs = $('.mw-changeslist-line-not-watched .mw-changeslist-title')
							.filter(function() {
								var thediff = /.*diff=([0-9]+).*oldid.*/.exec($(this)
									.closest('.mw-changeslist-line-not-watched')
									.find('a[href*="diff"]')
									.prop('href'));
								return thediff && $(this)
									.text() == name && thediff[1] > diff;
							})
							.closest('.mw-changeslist-line-not-watched');
						prevs.removeClass('mw-changeslist-line-not-watched yellowedit')
							.addClass('mw-changeslist-line-watched blueedit')
							.find('.unmark-edits')
							.remove();
						prevs.show();
						seen(prevs.find('span.mw-title'));
						$this.remove();
					});
			}));
}

function flowseen() {
	$('.mw-changeslist-line-watched a.mw-title')
		.before($('<a>', {
				text: '\u200f',
				title: i18n('markFlow'),
				href: '#nw',
				class: 'mark-all-flow-edits WLM-icon'
			})
			.click(function() {
				var $this = $(this);
				var topic = 'נושא:' + /title=[^:]*:(.+)&/.exec($this.parent()
					.find('a[href*="fromnotif"]')
					.prop('href'));
				var page = $this.parent()
					.find('a.mw-title')
					.prop('title');
				var titles = topic ? topic[1] + '|' + page : page;
				new mw.Api()
					.postWithToken('csrf', {
						action: 'setnotificationtimestamp',
						titles: titles,
					})
					.done(function() {
						$this.closest('.mw-changeslist-line-watched')
							.removeClass('mw-changeslist-line-watched blueedit')
							.addClass('mw-changeslist-line-not-watched yellowedit');
						if (config.hidemarked.flow)
							$this.closest('.mw-changeslist-line-not-watched')
							.hide();
						$this.remove();
					});
			}));
}

function categoryseen() {
	$('.mw-changeslist-line-watched span.mw-title')
		.filter(function() {
			return $(this)
				.closest('.mw-changeslist-line-watched')
				.find('a[href*="diff"]')
				.length <= 0 && $(this)
				.closest('.mw-changeslist-line-watched')
				.find('abbr.newpage')
				.length <= 0;
		})
		.before($('<a>', {
				text: '\u200f',
				title: i18n('markCat'),
				href: '#nw',
				class: 'mark-cat-edits WLM-icon'
			})
			.click(function() {
				var $this = $(this);
				var page = $this.parent()
					.find('a.mw-changeslist-title')
					.prop('title');
				new mw.Api()
					.postWithToken('csrf', {
						action: 'setnotificationtimestamp',
						titles: page,
					})
					.done(function() {
						$this.closest('.mw-changeslist-line-watched')
							.removeClass('mw-changeslist-line-watched blueedit')
							.addClass('mw-changeslist-line-not-watched yellowedit');
						if (config.hidemarked.categorization)
							$this.closest('.mw-changeslist-line-not-watched')
							.hide();
						$this.remove();
					});
			}));
}

function closeedit() {
	var button = $('<a>', {
		text: 'x\u200f',
		title: i18n('close'),
		href: '#nw',
		class: 'close-edit'
	});
	var click = function() {
		$(this)
			.closest('.mw-changeslist-line-not-watched, .mw-changeslist-line-watched')
			.hide();
	};
	$('li span.mw-changeslist-date')
		.parent()
		.prepend(button
			.click(click));
	$('td.mw-enhanced-rc')
		.parent()
		.filter(function() {
			return $(this)
				.find('td.mw-enhanced-rc-nested')
				.length <= 0;
		})
		.prepend($('<td>', {
				html: button
			})
			.click(click));
	$('td.mw-enhanced-rc')
		.parent()
		.find('td.mw-enhanced-rc-nested')
		.prev()
		.before($('<td>'));
}

function hider(state) {
	if (config.edit[state])
		$('.mw-changeslist-line-not-watched')
		.filter(function() {
			return $(this)
				.find('abbr.wikibase-edit')
				.length <= 0;
		})
		.hide();
	if (config.log[state])
		$('[class*="mw-changeslist-log"]')
		.hide();
	if (config.wikidata[state])
		$('abbr.wikibase-edit')
		.closest('.mw-changeslist-line-watched, .mw-changeslist-line-not-watched')
		.hide();
	$('#logmessage')
		.hide();
}

function unhider() {
	$('.mw-changeslist-line-watched')
		.show();
	if (config.edit.show)
		$('.mw-changeslist-line-not-watched')
		.filter(function() {
			return $(this)
				.find('abbr.wikibase-edit')
				.length <= 0;
		})
		.show();
	if (config.log.show)
		$('[class*="mw-changeslist-log"]')
		.show();
	if (config.wikidata.show)
		$('abbr.wikibase-edit')
		.closest('.mw-changeslist-line-not-watched')
		.show();
	$('#logmessage')
		.show();
}

function checklog() {
	new mw.Api()
		.get({
			action: 'query',
			format: 'json',
			list: 'watchlist',
			indexpageids: 1,
			wllimit: 500,
			wlprop: 'title|loginfo',
			wlshow: 'unread',
			wltype: 'log'
		})
		.done(function(date) {
			var firstname;
			try {
				firstname = date.query.watchlist;
				if (firstname.length > 0) {
					firstname = firstname[0];
					$('#hideAll')
						.after($('<div>', {
							text: i18n('loga'),
							id: 'logmessage'
						}));
					$('#logmessage')
						.addClass('blueedit');
					$('#logmessage')
						.append($('<span>', {
							text: JSON.stringify(firstname.title),
							id: 'logtitle'
						}));
					$('#logtitle')
						.css({
							fontWeight: 'bold',
							direction: 'rtl'
						});
					$('#logmessage')
						.append($('<span>', {
							text: i18n('logb') + JSON.stringify(firstname.logaction) + ' '
						}));
					$('#logmessage')
						.append($('<a>', {
							href: 'https://he.wikipedia.org//w/api.php?action=query&format=rawfm&list=watchlist&' +
								'indexpageids=1&wllimit=500&wlprop=title%7Cloginfo&wlshow=unread&wltype=log',
							text: i18n('logc')
						}));
					$('#logmessage')
						.append($('<span>', {
							text: '. ' + i18n('logd') + ' '
						}));
					$('#logmessage')
						.append($('<a>', {
							text: i18n('loge'),
							id: 'clearlog'
						}));
					$('#logmessage')
						.append($('<span>', {
							text: '.'
						}));
					$('#clearlog')
						.click(function() {
							new mw.Api()
								.postWithToken('csrf', {
									action: 'setnotificationtimestamp',
									titles: firstname.title
								})
								.done(function() {
									$('#logmessage')
										.remove();
									checklog();
								});
						});
				}
			} catch (err) {}
		});
}

function main() {
	seen($('.mw-changeslist-line-watched span.mw-title'));
	unseen($('.mw-changeslist-line-not-watched span.mw-title'));
	flowseen();
	categoryseen();
	closeedit();
	hider('starthidden');
}

if (mw.config.get('wgCanonicalSpecialPageName') == 'Watchlist') {
	$('.mw-body-content')
		.addClass((typeof window.orientation == 'undefined') ? 'WLM-desktop' : 'WLM-mobile');
	importStylesheet('מדיה ויקי:WLM.css');
	importStylesheet('משתמש:' + mw.config.get('wgUserName') + '/WLM.css');
	var lang = mw.user.options.get('language') == 'he' ? 0 : 1;
	var config;
	$.get(mw.util.wikiScript(), {
			title: 'מדיה ויקי:WLM.json',
			action: 'raw'
		})
		.done(function(data) {
			config = JSON.parse(data);
			$.get(mw.util.wikiScript(), {
					title: 'משתמש:' + mw.config.get('wgUserName') + '/WLM.json',
					action: 'raw'
				})
				.done(function(data1) {
					config = JSON.parse(data1);
					main();
				})
				.fail(function() {
					main();
				});
		})
		.fail(function() {
			alert(i18n('jsonlost'));
		});
	mw.loader.using('mediawiki.util')
		.done(function() {
			$('#mw-watchlist-form')
				.after($('<input>', {
					value: i18n('hideAll'),
					id: 'hideAll',
					type: 'submit'
				}))
				.after($('<span>', {
						text: 'place',
						id: 'placeholder'
					})
					.css('visibility', 'hidden'))
				.after($('<input>', {
					value: i18n('showAll'),
					id: 'showAll',
					type: 'submit'
				}))
				.after($('<div>', {
						text: 'place',
						id: 'placeline'
					})
					.css({
						visibility: 'hidden',
						fontSize: '50%'
					}));
			$('#hideAll')
				.click(function() {
					hider('hide');
				});
			checklog();
			$('#showAll')
				.click(unhider);
		});
}