MediaWiki:Gadget-convenientDiscussions.js

维基百科,自由的百科全书
跳转到导航 跳转到搜索
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
 * This configuration might get outdated as the script evolves, so it's best to keep it up to date
 * by checking for the generator script and documentation updates from time to time. See the
 * documentation at
 * https://commons.wikimedia.org/wiki/Special:MyLanguage/User:Jack_who_built_the_house/Convenient_Discussions#Configuring_for_a_wiki.
 *
 * This script is loaded by all ConvenientDiscussion users, including those who loads CD through 
 * loading the main script ([[c:User:Jack_who_built_the_house/convenientDiscussions.js]]) instead
 * of directly loading this script or enabling CD through local gadgets settings.
 *
 * Forked from [[User:BlackShadowG]]'s version ([[Special:Permalink/80398782]]);
 * maintained by [[User:1F616EMO]] in MediaWiki namespace.
 */

// <nowiki>

/* global convenientDiscussions:writable */

(function () {

	function unique(item, i, arr) {
		return arr.indexOf(item) === i;
	}

	function getStrings() {
		const requests = [mw.config.get('wgUserLanguage'), mw.config.get(
				'wgContentLanguage')]
			.filter(unique)
			.filter(function (lang) {
				return lang !== 'en';
			})
			.map(function (lang) {
				return mw.loader.getScript(
					'https://commons.wikimedia.org/w/index.php?title=User:Jack_who_built_the_house/convenientDiscussions-i18n/' +
					lang + '.js&action=raw&ctype=text/javascript');
			});

		// We assume it's OK to fall back to English if the translation is unavailable for any reason.
		return Promise.all(requests)
			.catch(function () {});
	}

	window.convenientDiscussions = window.convenientDiscussions || {};
	if (convenientDiscussions.config) return;

	/* BEGINNING OF THE CONFIGURATION */

	convenientDiscussions.config = {
		messages: {
			'sun': '日',
			'mon': '一',
			'tue': '二',
			'wed': '三',
			'thu': '四',
			'fri': '五',
			'sat': '六',
			'sunday': '星期日',
			'monday': '星期一',
			'tuesday': '星期二',
			'wednesday': '星期三',
			'thursday': '星期四',
			'friday': '星期五',
			'saturday': '星期六',
			'jan': '1月',
			'feb': '2月',
			'mar': '3月',
			'apr': '4月',
			'may': '5月',
			'jun': '6月',
			'jul': '7月',
			'aug': '8月',
			'sep': '9月',
			'oct': '10月',
			'nov': '11月',
			'dec': '12月',
			'january': '1月',
			'february': '2月',
			'march': '3月',
			'april': '4月',
			'may_long': '5月',
			'june': '6月',
			'july': '7月',
			'august': '8月',
			'september': '9月',
			'october': '10月',
			'november': '11月',
			'december': '12月',
			'january-gen': '1月',
			'february-gen': '2月',
			'march-gen': '3月',
			'april-gen': '4月',
			'may-gen': '5月',
			'june-gen': '6月',
			'july-gen': '7月',
			'august-gen': '8月',
			'september-gen': '9月',
			'october-gen': '10月',
			'november-gen': '11月',
			'december-gen': '12月',
			'parentheses': '($1)',
			'parentheses-start': '(',
			'parentheses-end': ')',
			'word-separator': '',
			'comma-separator': '、​',
			'colon-separator': ':​',
			'nextdiff': '下一版本→',
			'timezone-utc': 'UTC',
			'pagetitle': '$1 - 维基百科,自由的百科全书',
			'discussiontools-topicsubscription-button-subscribe': '订阅',
			'discussiontools-topicsubscription-button-subscribe-tooltip': '{{GENDER:|订阅}}以接收有关新留言的通知。',
			'discussiontools-topicsubscription-button-unsubscribe': '取消订阅',
			'discussiontools-topicsubscription-button-unsubscribe-tooltip': '{{GENDER:|取消订阅}}以停止接收有关新留言的通知。',
			'discussiontools-topicsubscription-notify-subscribed-title': '{{GENDER:|您}}已订阅!',
			'discussiontools-topicsubscription-notify-subscribed-body': '{{GENDER:|您}}会收到有关此话题内新留言的通知。',
			'discussiontools-topicsubscription-notify-unsubscribed-title': '{{GENDER:|您}}已取消订阅。',
			'discussiontools-topicsubscription-notify-unsubscribed-body': '您将不再收到“此话题下有新留言”的通知。',
			'discussiontools-newtopicssubscription-button-subscribe-label': '订阅',
			'discussiontools-newtopicssubscription-button-subscribe-tooltip': '订阅以在此页面上开始新话题时收到通知。',
			'discussiontools-newtopicssubscription-button-unsubscribe-label': '取消订阅',
			'discussiontools-newtopicssubscription-button-unsubscribe-tooltip': '取消订阅以停止在此页面上开始新话题时收到通知。',
			'discussiontools-newtopicssubscription-notify-subscribed-title': '{{GENDER:|您}}已订阅!',
			'discussiontools-newtopicssubscription-notify-subscribed-body': '{{GENDER:|您}}会在此页面上开始新话题时收到通知。',
			'discussiontools-newtopicssubscription-notify-unsubscribed-title': '{{GENDER:|您}}已取消订阅。',
			'discussiontools-newtopicssubscription-notify-unsubscribed-body': '{{GENDER:|您}}不再会在此页面上开始新话题时收到通知。',
			'visualeditor-educationpopup-dismiss': '好的,明白了'
		},
		substAliases: [
			'替代:',
			'替換:'
		],
		timezone: 'UTC',
		unsignedTemplates: [
			'Unsigned',
			'补上签名',
			'补充签名',
			'未签名',
			'签名',
			'补签名',
			'Nosign',
			'Unsigned2'
		],
		smallDivTemplates: [
			'smalldiv'
		],
		paragraphTemplates: [
			'pb',
			'Paragraph break',
			'Parabr',
			'Paragraph'
		],
		outdentTemplates: [
			'outdent',
			'Od',
			'反縮排',
			'┌┘',
			'Outdent1'
		],
		clearTemplates: [
			'Clear',
			'Clr',
			'Sectionbreak',
			'Clear both',
			'BrClear',
			'強制換行'
		],
		quoteFormatting (isMultiline, author, timestamp, dtId) {
			var pre = '';
			var post = '';
			if (isMultiline) {
				pre = '{{Talk quote block|text=';
				if (author) {
					post += '|by=' + author;
				}
				if (timestamp) {
					post += '|ts=' + timestamp;
				}
				if (dtId) {
					post += '|id=' + dtId;
				}
				post += '}}';
			} else {
				pre = '{{tq|1='
				post += '}}';
			}
			return [pre, post];
		},
		noSignatureTemplates: [
			'Moved discussion from',
			'Moved discussion to',
			'移動自',
			'移动自',
			'Movedfrom',
			'Savedfrom',
			'Archievedfrom',
			'Movefrom',
			'Savefrom',
			'MOVEDFROM',
			'Moved from',
			'Switchfrom',
			'移動至',
			'Movedto',
			'Moveto',
			'移動到',
			'已移動至',
			'Moved to',
			'移动至'
		],
		closedDiscussionTemplates: [
			[
				'Closed',
				'Discussion top',
				'Archive top',
				'Archive Top',
				'ArchiveH',
				'TalkendH',
				'ConvertH',
				'DelH',
				'ConverH',
				'Closereq',
				'Delh',
				'Talkendh',
				'DELH'
			],
			[
				'Archive bottom',
				'Archive Bottom',
				'Closed rfc bottom',
				'ArchiveF'
			]
		],
		defaultSignaturePrefix: '--',
		signatureEndingRegexp: /(留言)/,
		mentionRequiresLeadingSpace: false,
		rejectNode (node) {
			// 優良、典範條目投票期模板匹配
			if (
				node.nodeName.toUpperCase() === 'DL'
				&& node.innerText.match(/^投票期:.*\n下次可提名.*起/s)
			) {
				return true;
			}

			if ([
				'memo-rfcmakepublic', // RFC 公示模板
				'dykentry', // DYKC 投票元數據
				'notice', // [[T:存檔至]]等模板
			].some(cls => node.classList.contains(cls))) {
				return true;
			}

			// [[T:archive-top]] matching
			// We don't need that percision in the worker,
			// as we want notification when someone archives the entire discussion anyways
			// [[phab:T409653#11928226]]

			if ('matches' in node && node.matches(`
				div.archived.archive-top > dl:first-of-type,
				div.archived.archive-top > dl:first-of-type ~ hr
			`)) {
				return true;
			}

			return false;
		},
		pageBlacklist: [
			/^WikiProject:[^/]+\/成[員员]$/,
			/^Wikipedia:公告欄\/存檔\//, // 部分人事公告誤判爲簽名
			/^Wikipedia:中文維基百科之最$/,
		],
		getMoveSourcePageCode: function (targetPageWikilink, signature) {
			// Timestamp is the timestamp of first comment, not what we want in the template
			return `{{移動至|1=${targetPageWikilink}|sign=${signature}}}`;
		},
		getMoveTargetPageCode: function (targetPageWikilink, signature) {
			return `{{移動自|1=${targetPageWikilink}|sign=${signature}}}`;
		},
	};

	/* END OF THE CONFIGURATION */


	if (!convenientDiscussions.isRunning) {
		convenientDiscussions.getStringsPromise = getStrings();
		mw.loader.getScript(
				'https://commons.wikimedia.org/w/index.php?title=User:Jack_who_built_the_house/convenientDiscussions.js&action=raw&ctype=text/javascript'
			)
			.catch(function (e) {
				console.warn('Couldn\'t load Convenient Discussions.', e);
			});
	}

}());

// </nowiki>