/**
* This gadget intercepts the Citoid results obtained from Zotero API and modifies them
* to follow the guidelines of the Polish Wikipedia.
*
* @author ]
*/
mw.hook('ve.activationComplete').add(function () {
var btr = ve.ui.CitoidInspector.prototype.buildTemplateResults;
if (!btr) {
console.error('ve.ui.CitoidInspector.prototype.buildTemplateResults not found');
return;
}
ve.ui.CitoidInspector.prototype.buildTemplateResults = function buildTemplateResults__plwiki(searchResults) {
// Fallback if we get an unexpected situation
if (arguments.length !== 1) {
console.error('buildTemplateResults called with unexpected number of arguments:', arguments);
return btr.apply(this, arguments);
}
// Search results pipeline
searchResults = searchResults
.map(stripPolishLanguage)
.map(stripLanguageVariant);
return btr.call(this, searchResults);
};
});
function stripPolishLanguage(searchResult) {
if (searchResult.language === 'pl') {
delete searchResult.language;
}
return searchResult;
}
function stripLanguageVariant(searchResult) {
if (searchResult.language) {
searchResult.language = searchResult.language.replace(/\w+$/, '');
}
return searchResult;
}
/*
Example searchResults (not all keys have to be present):
[
{
"key": "HCHI4J84",
"version": 0,
"itemType": "webpage",
"tags": ,
"date": "2024-10-28",
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply",
"title": "Function.prototype.apply() - JavaScript | MDN",
"abstractNote": "The apply() method of Function instances calls this function with a given this value, and arguments provided as an array (or an array-like object).",
"language": "en-US",
"accessDate": "2024-10-31",
"websiteTitle": "developer.mozilla.org",
"source": [
"Zotero"
]
}
]
*/