ညးလွပ်:Crowley666/js/import.js
(ကလေၚ်ထ္ၜး နူ ညးလွပ်:EdwardAlexanderCrowley/js/import.js)
တင်စၟတ်: ကြဴနူ မသီဂိုင်တုဲ တၞဟ်နမဂွံညာတ် အပြံင်အလှာဲ မၞးသ္ဒးကၟာတ်ထောအ် မုက်လိက်ဗြောဝ်သာဂှ်ရောင်။
- Firefox / Safari:မ္ဂး ဍဵုလဝ် Shift အဃောမဍဵု Reload၊ ဟွံသေင်မ္ဂး ဍဵု either Ctrl-F5 ဟွံသေင်မ္ဂး Ctrl-R (⌘-R သွက် Mac)
- Google Chrome:မ္ဂး ဍဵု Ctrl-Shift-R (⌘-Shift-R သွက် Mac)
- Internet Explorer / Edge:မ္ဂး ဍဵုလဝ် Ctrl အဃော မဍဵု Refresh, ဟွံသေင်မ္ဂး ဍဵု Ctrl-F5
- Opera: မ္ဂး ဍဵု Ctrl-F5။
// 见[[mw:Manual:CORS]]、[[mw:API:Cross-site requests]]
mw.loader.using('mediawiki.ForeignApi');
var pn = mw.config.get('wgPageName');
pn = pn.replace('ထာမ်ပလိက်:', 'Template:');
pn = pn.replace('ညးလွပ်:', 'User:');
pn = pn.replace('မဝ်ဂျူ:', 'Module:');
if (pn.startsWith('User:Qnm/') || // User:Qnm/9至99随便用
pn.startsWith('Template:') || pn.startsWith('Module:')) {
mw.util.addPortletLink('p-cactions', 'javascript:importpage()', '导入页面', 'ca-import-page',
'导入页面', '', document.getElementById('ca-history')); // 快捷键设为''
mw.util.addPortletLink('p-cactions', 'javascript:importdoc()', '导入文档', 'ca-import-doc',
'导入文档', '', document.getElementById('ca-history'));
mw.util.addPortletLink('p-cactions', 'javascript:importboth()', '导入两者', 'ca-import-both',
'导入两者', '', document.getElementById('ca-history'));
mw.util.addPortletLink('p-cactions', 'javascript:importedit()', '导入编辑区', 'ca-import-edit',
'导入编辑区', '', document.getElementById('ca-history'));
} else if (pn == 'Wiktionary:Sandbox' || pn == 'Wiktionary:沙盒') {
mw.util.addPortletLink('p-cactions', 'javascript:importsandbox()', '导入沙盒', 'ca-import-sandbox',
'导入沙盒', '', document.getElementById('ca-history'));
mw.util.addPortletLink('p-cactions', 'javascript:revertsandbox()', '复原沙盒', 'ca-revert-sandbox',
'复原沙盒', '', document.getElementById('ca-history'));
}
function importpage() {
var from = pn, to = pn;
importpagecore(from, to);
}
function importedit() {
if (document.forms.editform) {
var from = pn, to = pn;
// 这种方法对Module的编辑框无效,也对手机版无效
var txt = document.editform.wpTextbox1;
importpagecore(from, to, function(text, summary){ txt.value = text; });
}
}
function importdoc() {
var from = pn, to = pn;
if (!isdoc(from)) {
from = from + '/documentation';
to = to + '/documentation';
}
if (mw.config.get('wgWikibaseItemId')) {
link = $("a.interlanguage-link-target[lang='en']").attr('href');
if (link) {
from = decodeURI(link.split('/wiki/')[1]) + '/documentation';
}
}
importpagecore(from, to);
}
// 不支持在文档页面importboth
function importboth() {
var from = pn, to = pn;
if (isdoc(from)) {
from = from.replace('/documentation', '');
to = to.replace('/documentation', '');
}
[from, to] = importpagecore(from, to);
importpagecore(from + '/documentation', to + '/documentation');
}
function importsandbox() {
importpagecore('Wiktionary:Sandbox', 'Wiktionary:沙盒');
}
function revertsandbox() {
const api = new mw.ForeignApi('https://mnw.wiktionary.org/w/api.php');
api.postWithToken('csrf', {
action: 'edit',
title: 'Wiktionary:沙盒',
text: '{{sandbox}}',
summary: '复原沙盒'
}).fail(function(){ mw.notify('复原失败'); }).done(function(){ mw.notify('复原成功'); });
}
function importpagecore(from, to, modify) {
// 若有跨语言链接,使用跨语言链接的标题。
// 使用本地DOM数据是为了降低延迟。不适用手机版,若实在需要,应使用api获取
if (mw.config.get('wgWikibaseItemId')) {
link = $("a.interlanguage-link-target[lang='en']").attr('href');
if (link) {
from = decodeURI(link.split('/wiki/')[1]) + (isdoc(from) ? '/documentation' : '');
}
}
const apifrom = new mw.ForeignApi('https://en.wiktionary.org/w/api.php');
apifrom.get({
action: 'query',
titles: from,
prop: 'revisions|langlinks',
indexpageids: 1,
rvprop: 'content',
lllang: 'mnw'
}).then(function(result) {
result = result.query;
var rpage = result.pages[result.pageids[0]];
if (rpage.langlinks) {
to = rpage.langlinks[0]['*'];
}
var text = rpage.revisions[0]['*'];
var summary = '[[User:EdwardAlexanderCrowley/js/import.js|搬运]]自[[:en:' + from + ']]';
if (from == 'Wiktionary:Sandbox') text = '{{sandbox}}\n' + text;
if (modify != undefined) {
modify(text, summary);
return;
}
const apito = new mw.Api();
return apito.postWithToken('csrf', {
action: 'edit',
title: to,
text: text,
summary: summary,
}).fail(function() {
mw.notify('搬运失败');
}).then(function() {
mw.notify('搬运成功');
if (!rpage.langlinks && canlink(from)) {
const apidata = new mw.ForeignApi('https://www.wikidata.org/w/api.php');
apidata.postWithToken('csrf', {
action: 'wblinktitles',
fromsite: 'enwiktionary',
fromtitle: from,
tosite: 'mnwwiktionary',
totitle: to,
bot: 1
}).fail(function() {
mw.notify('链接失败,可能需要IPBE');
}).done(function() {
mw.notify('链接成功');
});
}
});
});
return [from, to];
}
function canlink(p) {
return !(p.endsWith('/documentation') || p.endsWith('/documentation')
|| p.endsWith('/testcase') || p.endsWith('/testcases')
|| p.startsWith('User:') ||p.startsWith('Module:User:'));
}
function isdoc(p) {
return p.endsWith('/documentation') || p.endsWith('/doc');
}