- 致编者:请牢记我们的域名wiki.mcbe-dev.net!
- 致编者:欢迎加入本Wiki的官方交流QQ群或Discord服务器!
- 基岩版1.19.31现已发布!(了解更多)
- Inner Core现已支持Xbox模组联机!(了解更多)
- 如果您是第一次来到本Wiki,欢迎注册一个账户
- 点击顶部的“编辑”或“编辑源代码”按钮即可编辑当前页面
- 请知悉:在不登录时也可以编辑和新建页面,但是您当前的IP地址会记录在编辑历史中
MediaWiki:Gadget-shortURL.js
来自Minecraft基岩版开发Wiki
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/**
* @name Short URL
* @author 机智的小鱼君
*
* @description Get the "fake" short link provided by MediaWiki.
* Solve the very long link of the pages that name contain non-ASCII words.
*/
// Originated from [https://github.com/Wjghj-Project/wjghj-wiki/blob/master/gadgets/Share-btn/script.js here].
(function () {
var i18n = {
shareDescription: '您还可以通过此链接分享页面:',
copy: '复制',
copied: '已复制!',
};
// 对周报页面进行特别处理
var isWeekly = $('body').hasClass("rootpage-Minecraft基岩版开发Wiki_内核周报") || $('body').hasClass("rootpage-Minecraft基岩版开发Wiki_技术周报");
if (isWeekly) {
console.log("短链接将尝试添加到周报页眉。");
}
window.shortUrl = window.shortUrl || '';
// 缓存 mw 变量
var config = mw.config.get();
// 判断是否存在文章ID
if (config.wgArticleId > 0) {
shortUrl = config.wgServer + '/-/' + config.wgArticleId;
// 插入短链接
var shortURLParagraph = $('<div>', { class: 'shortUrl-block', style: 'margin: 5px 12px;' }).append(
$('<span>', { class: 'shortUrl-description' }).append(
$('<span>', { text: i18n.shareDescription }),
$('<br>'),
$('<strong>', { text: shortUrl + '' }),
$('<br>'),
$('<a>', { href: 'javascript:;', text: i18n.copy }).on('click', function () {
var $this = $(this);
navigator.clipboard.writeText(shortUrl).then(function () {
$this.text(i18n.copied);
setTimeout(function () {
$this.text(i18n.copy);
}, 1500);
});
})
)
);
// A PopupButtonWidget.
var popupButton = new OO.ui.PopupButtonWidget({
icon: 'link',
flags: isWeekly ? ['progressive'] : [],
framed: false,
label: 'Short URL',
invisibleLabel: true,
popup: {
label: 'Short URL',
$content: shortURLParagraph,
padded: true,
align: 'center',
}
});
// Append the button to the DOM.
if (isWeekly) {
$('.weekly-header-navigation').after(popupButton.$element);
} else {
$('#ca-view').after(popupButton.$element);
}
}
// 将短链接替换进文章
$('.shortUrl').text(shortUrl);
$('.shortUrl-link').html($('<a>', { href: shortUrl, text: shortUrl }));
})();