跳转到内容

User:Peacearth/purgebutton.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*** From [[Special:Permalink/67433559]], special thanks to [[User:AnYiLin]]. ***/

(($, mw) => {
	const fn = async () => {
		if (mw.config.get('wgAction') === 'view' && mw.config.get('wgIsArticle') && mw.config.get('wgCurRevisionId') !== 0 && mw.config.get('wgRevisionId') !== 0 && mw.config.get('wgCurRevisionId') === mw.config.get('wgRevisionId')) {
			await mw.loader.using(['ext.gadget.ding', 'ext.gadget.site-lib', 'mediawiki.api', 'mediawiki.user']);
			let pos = 'p-cactions';
			if (mw.config.get('skin') === 'minerva') {
				pos = 'p-tb';
				mw.loader.addStyleTag('#ca-purge a:before{background:url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2220%22 height=%2220%22 viewBox=%220 0 20 20%22%3E%3Cg fill=%22%2354595d%22%3E%3Cpath d=%22M7 0a2 2 0 00-2 2h9a2 2 0 012 2v12a2 2 0 002-2V2a2 2 0 00-2-2z%22/%3E%3Cpath d=%22M13 20H4a2 2 0 01-2-2V5a2 2 0 012-2h9a2 2 0 012 2v13a2 2 0 01-2 2zm-6.5-3.5l.41-1.09L8 15l-1.09-.41-.41-1.09-.41 1.09L5 15l1.09.41.41 1.09zm2.982-.949l.952-2.561 2.53-.964-2.53-.964L9.482 8.5l-.952 2.562-2.53.964 2.53.964.952 2.561zM6 10.5l.547-1.453L8 8.5l-1.453-.547L6 6.5l-.547 1.453L4 8.5l1.453.547L6 10.5z%22/%3E%3C/g%3E%3C/svg%3E")}')
			}
			mw.util.addPortletLink(pos, '#', wgULS('清除缓存', '清除快取'), 'ca-purge', wgULS('更新服务器缓存', '更新伺服器快取')).addEventListener('click', e => {
				e.preventDefault();
				window.bldkDingExposedInterface('正在清除…', 'default', 'long');
				new mw.Api().post({
					action: 'purge',
					format: 'json',
					forcelinkupdate: true,
					titles: mw.config.get('wgPageName')
				}).then(() => window.location.reload(true))
			})
		}
	}
	$(fn)
})(jQuery, mediaWiki);