Site Notice
hello, world
Difference between revisions of "QuickGetWikiCode"
From Project-EPB Commons
m ([InPageEdit] 没有编辑摘要) |
|||
Line 1: | Line 1: | ||
− | < | + | <pre class="prettyprint">function getWikiCode() { |
− | |||
var preUrl = location.href.split('/'); | var preUrl = location.href.split('/'); | ||
preUrl = preUrl[0]+'/'+preUrl[1]+'/'+preUrl[2]+'/api.php'; | preUrl = preUrl[0]+'/'+preUrl[1]+'/'+preUrl[2]+'/api.php'; | ||
Line 11: | Line 10: | ||
url: url, | url: url, | ||
dataType: 'jsonp', | dataType: 'jsonp', | ||
− | type: ' | + | type: 'get', |
data: { | data: { | ||
page: title, | page: title, | ||
Line 31: | Line 30: | ||
} | } | ||
getWikiCode()</pre> | getWikiCode()</pre> | ||
− | |||
− | |||
− |
Latest revision as of 11:14, 23 November 2019
function getWikiCode() { var preUrl = location.href.split('/'); preUrl = preUrl[0]+'/'+preUrl[1]+'/'+preUrl[2]+'/api.php'; var url = prompt('Wiki url?',preUrl); if (url == null) return; var title = prompt('Pagename?',wgPageName); if (title == null) return; $.ajax({ url: url, dataType: 'jsonp', type: 'get', data: { page: title, action: 'parse', prop: 'wikitext', format: 'json' }, success: function(result) { var wikitext; if (result.parse !== undefined) { wikitext = result.parse.wikitext['*']; } else { wikitext = '错误:无法读取页面。' } alert(wikitext); console.info(wikitext); } }); } getWikiCode()