LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-HotCat-zh-core.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 |
||
第1行: | 第1行: | ||
$(function() { |
$(function() { |
||
const ns = mw.config.get('wgNamespaceNumber'); |
|||
nsIds = mw.config.get('wgNamespaceIds'); |
|||
if( ns < 0 || // Special pages; Special:Upload is handled differently |
|||
⚫ | |||
ns === 10 || // Templates |
|||
ns === 274 || // Widget |
|||
⚫ | |||
ns === 828 || // Module (Lua) |
|||
request2 = api.get({action:'query', titles:pageName, prop:'categories'}); |
|||
⚫ | |||
⚫ | |||
ns === 6 && !conf.wgArticleId || // Non-existing file pages |
|||
const wikitext = data1[0].parse.wikitext["*"], |
|||
ns === 2 || // User |
|||
ns % 2 === 1 || // Talk page |
|||
⚫ | |||
mw.config.get("wgPageContentModel") !== "wikitext" || |
|||
⚫ | |||
⚫ | |||
⚫ | |||
( ns === nsIds.creator || |
|||
ns === nsIds.timedtext || |
|||
var cat = 'Category:' + ele["*"].replace(/_/g, ' '), |
|||
ns === nsIds.institution ) ) { |
|||
⚫ | |||
return; |
|||
⚫ | |||
canonicalCats.splice(i,1); |
|||
⚫ | |||
⚫ | |||
var api = new mw.Api(), |
|||
⚫ | |||
}); |
|||
request2 = api.get({action:'query', titles:pageName, prop:'categories'}); |
|||
⚫ | |||
⚫ | |||
const obj1 = data1[0].parse.categories, |
|||
⚫ | |||
indexpageids:1, |
|||
var cats = obj1 ? Object.keys(obj1).map((key) => obj1[key]["*"]) : [], |
|||
titles:canonicalCats.join("|")}) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
api.get({action:'query', |
|||
⚫ | |||
inprop:'varianttitles', |
|||
⚫ | |||
⚫ | |||
⚫ | |||
const ids = data.query.pageids; |
const ids = data.query.pageids; |
||
ids.forEach(function(ele) { |
ids.forEach(function(ele) { |
||
第31行: | 第38行: | ||
const catVt = data.query.pages[ele].varianttitles, |
const catVt = data.query.pages[ele].varianttitles, |
||
catHans = catVt["zh-hans"].substring(3), |
catHans = catVt["zh-hans"].substring(3), |
||
catHant = catVt["zh-hant"].substring(3) |
catHant = catVt["zh-hant"].substring(3); |
||
⚫ | |||
regExp = new RegExp('\\[\\[(category|Category|分類|分类):(' + catHans.slice(0,1) + '|' + catHans.slice(0,1).toLowerCase() + ')' + '(' + catHans.substring(1) + '|' + catHant.substring(1) + ')\\]\\]', 'g'), |
|||
else { catlink.attr('title','Category:' + catHant); } |
|||
//mw.loader.load('/zh?title=mediawiki:gadget-HotCat.js&action=raw&ctype=text/javascript'); |
|||
if(isFind) { |
|||
$('<span class="metadata nopopups hotcatlink"><span> <a href="#catlinks" title="移除">(−)</a></span></span>').insertAfter(catlink); |
|||
⚫ | |||
else { catlink.attr('title','Category:' + catHant); } |
|||
catlink.next().find('a').data('wikitext', wikitext.replace(regExp, '')) |
|||
.on('click', function(e) { |
|||
e.preventDefault(); |
|||
localStorage.setItem('HotCatzh', $(e.target).data('wikitext')); |
|||
window.location.href = '/zh?title=' + pageName + '&action=submit'; |
|||
}); |
|||
⚫ | |||
}); |
}); |
||
}); |
}); |
||
}); |
|||
⚫ | |||
else if(mw.config.get('wgAction') == 'submit') { |
|||
const HotCatzh = localStorage.HotCatzh; |
|||
localStorage.removeItem('HotCatzh'); |
|||
if(HotCatzh) { |
|||
$('#wpTextbox1').val(HotCatzh); |
|||
$('#wpDiff').click(); |
|||
⚫ | |||
} |
|||
}); |
}); |
2020年8月22日 (六) 09:23的版本
$(function() { const ns = mw.config.get('wgNamespaceNumber'); nsIds = mw.config.get('wgNamespaceIds'); if( ns < 0 || // Special pages; Special:Upload is handled differently ns === 10 || // Templates ns === 274 || // Widget ns === 828 || // Module (Lua) ns === 8 || // MediaWiki ns === 6 && !conf.wgArticleId || // Non-existing file pages ns === 2 || // User ns % 2 === 1 || // Talk page mw.config.get("wgPageContentModel") !== "wikitext" || nsIds && ( ns === nsIds.creator || ns === nsIds.timedtext || ns === nsIds.institution ) ) { return; } const pageName = mw.config.get('wgPageName'); var api = new mw.Api(), request1 = api.get({action:'parse', page:pageName, prop:'categories'}), request2 = api.get({action:'query', titles:pageName, prop:'categories'}); $.when(request1, request2).done(function(data1, data2) { const obj1 = data1[0].parse.categories, obj2 = data2[0].query.pages[mw.config.get( 'wgArticleId' )].categories; var cats = obj1 ? Object.keys(obj1).map((key) => obj1[key]["*"]) : [], canonicalCats = obj2 ? Object.keys(obj2).map((key) => obj2[key].title) : []; if(canonicalCats.length === 0) { return; } api.get({action:'query', prop:'info', inprop:'varianttitles', indexpageids:1, titles:canonicalCats.join("|")}) .then(function(data) { const ids = data.query.pageids; ids.forEach(function(ele) { var catlink = $('#catlinks a[title="' + data.query.pages[ele].title + '"]'); const catVt = data.query.pages[ele].varianttitles, catHans = catVt["zh-hans"].substring(3), catHant = catVt["zh-hant"].substring(3); if(cats.includes(catHans)) { catlink.attr('title','Category:' + catHans); } else { catlink.attr('title','Category:' + catHant); } //mw.loader.load('/zh?title=mediawiki:gadget-HotCat.js&action=raw&ctype=text/javascript'); }); }); }); });