Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
var CatTools = {
modes: {
AND: '', //TODO
OR: '', //TODO
WITHOUT: '', //TODO
},
mode: CatTools.modes.AND,
cat1: '',
cat2: '',
suggestions: [],
continu: '',
cat1Results: [],
cat2Results: [],
results: [],
init: function(){
//TODO add EventListeners / MutationObservers to fill cat1, cat2, mode and to call suggest, existsFeedback, exec
},
suggest: function(phrase){
$.get(wgServer+wgScriptPath+'/api.php?action=opensearch&format=json&namespace=14&limit=10&search='+encodeURI(phrase), function(d){
if('string'==typeof d) d=JSON.parse(d);
d[1].forEach(function(v){
//TODO: display v.substring(10) as suggestion
});
}, 'json');
},
existsFeedback: function(inputID){
var exists;
$.get(wgServer+wgScriptPath+'/api.php?action=query&format=json&titles='+encodeURI($(inputID).val()), function(d){
if('string'==typeof d) d=JSON.parse(d);
if(d.query.pages.hasOwnProperty('-1')) exists = false;
else exists = true;
}, 'json');
$(inputID).css('background-color', (exists ? '#a7f4a7' : '#f4a7a7'));
},
exec: function(){
CatTools.getCatMembers(CatTools.cat1, 'cat1Results', '');
while(CatTools.continu.length){
CatTools.getCatMembers(CatTools.cat1, 'cat1Results', CatTools.continu);
}
CatTools.getCatMembers(CatTools.cat2, 'cat2Results', '');
while(CatTools.continu.length){
CatTools.getCatMembers(CatTools.cat2, 'cat2Results', CatTools.continu);
}
switch(CatTools.mode){
default:
case CatTools.modes.AND:
CatTools.cat1Results.forEach(function(v){
if(CatTools.cat2Results.includes(v)) results.push(v);
});
break;
case CatTools.modes.OR:
CatTools.cat1Results.forEach(function(v){
if(!CatTools.results.includes(v)) results.push(v);
});
CatTools.cat2Results.forEach(function(v){
if(!CatTools.results.includes(v)) results.push(v);
});
break;
case CatTools.modes.WITHOUT:
CatTools.cat1Results.forEach(function(v){
if(!CatTools.cat2Results.includes(v)) results.push(v);
});
}
CatTools.render();
},
getCatMembers: function(catName, storage, cont){
$.get(wgServer+wgScriptPath+'/api.php?action=query&list=categorymembers&cmtitle=Kategorie:'+encodeURI(catName)+'&cmlimit=max'+(cont.length ? '&cmcontinue='+cont : ''), function(d){
if('string'==typeof d) d=JSON.parse(d);
if(d['query-continue']) CatTools.continu = d['query-continue'].categorymembers.cmcontinue;
else CatTools.continu = '';
d.query.categorymembers.forEach(function(v){
CatTools[storage].push(v.title);
});
}, 'json');
},
render: function(){
CatTools.results.forEach(function(v){
$('#CatToolsResultWrapper').append($('<a>').attr('href','http://stargate-wiki.de/wiki/'+encodeURI(v)).attr('title',v).text(v));
});
}
};
$(CatTools.init);