MediaWiki:Gadget-WikitextAutocompleter.js: Difference between revisions
From Zelda Wiki, the Zelda encyclopedia
MediaWiki:Gadget-WikitextAutocompleter.js (view source)
Revision as of 12:52, 5 May 2018
, 5 May 2018Pushed/Mainspaced sandbox changes - Fixed some bugs, added more templates:https://zelda.gamepedia.com/index.php?title=User%3AKokoroSenshi%2Fcommon.js&type=revision&diff=631054&oldid=630041
KokoroSenshi (talk | contribs) (Pushed/Mainspaced sandbox changes - More general, more functionality, though under simplified assumptions, not fully tested: https://zelda.gamepedia.com/index.php?title=User%3AKokoroSenshi%2Fcommon.js&type=revision&diff=630041&oldid=629917) |
KokoroSenshi (talk | contribs) m (Pushed/Mainspaced sandbox changes - Fixed some bugs, added more templates:https://zelda.gamepedia.com/index.php?title=User%3AKokoroSenshi%2Fcommon.js&type=revision&diff=631054&oldid=630041) |
||
Line 9: | Line 9: | ||
* mw.loader.load('https://unpkg.com/textcomplete@0.13.1/dist/textcomplete.min.js'); | * mw.loader.load('https://unpkg.com/textcomplete@0.13.1/dist/textcomplete.min.js'); | ||
* Bugs: | * Bugs: | ||
* | |||
* | |||
*/ | */ | ||
if (mw.config.get("wgAction") == 'edit') { | if (mw.config.get("wgAction") == 'edit') { | ||
Line 26: | Line 24: | ||
/** Store parameter options in instance variable */ | /** Store parameter options in instance variable */ | ||
self.params["1"] = | self.params["1"] = readArrayFromString(data); | ||
/** Callback */ | /** Callback */ | ||
Line 32: | Line 30: | ||
}); | }); | ||
var | var readArrayFromString = function(text) { | ||
var | var array = []; | ||
text.split("</includeonly>")[0] | text.split("</includeonly>")[0] | ||
.split("#switch:{{{1\|}}}")[1] | .split("#switch:{{{1\|}}}")[1] | ||
Line 39: | Line 37: | ||
.match(/\|[a-zA-Z0-9 ]*/g) | .match(/\|[a-zA-Z0-9 ]*/g) | ||
.forEach(function(value, index){ | .forEach(function(value, index){ | ||
var | var name = value.slice(1).trim(); | ||
array.push(name); | |||
}); | }); | ||
return | return array; | ||
}; | }; | ||
Line 62: | Line 60: | ||
} | } | ||
)); | )); | ||
Strategies.Templates.push(new TemplateStrategy( | |||
"Icon", | |||
function() { | |||
var self = this; | |||
$.get( "https://zelda.gamepedia.com/Template:Icon?action=raw", function( data ) { | |||
/** Store parameter options in instance variable */ | |||
self.params["1"] = readArrayFromString(data); | |||
/** Callback */ | |||
self.registerStrategies(); | |||
}); | |||
var readArrayFromString = function(text) { | |||
var array = []; | |||
text.split("</includeonly>")[0] | |||
.split("\|#default")[0] | |||
.match(/\n\|[a-zA-Z0-9-+ ]*/g) | |||
.forEach(function(value, index){ | |||
var name = value.slice(2).trim(); | |||
array.push(name); | |||
}); | |||
return array; | |||
}; | |||
} | |||
)); | |||
var readInitialismsArrayFromString = function(callback) { | |||
$.get( "https://zelda.gamepedia.com/Template:Zelda?action=raw", function( data ) { | |||
var initialismsArray = []; | |||
data.split("<noinclude>")[1] | |||
.match(/\|\|[a-zA-Z0-9-+& ]*\n/g) | |||
.forEach(function(value, index){ | |||
var name = value.slice(2).trim(); | |||
initialismsArray.push(name); | |||
}); | |||
callback(initialismsArray); | |||
}); | |||
}; | |||
readInitialismsArrayFromString(function(initialismsArray) { | |||
Strategies.Templates.push(new TemplateStrategy( | |||
"Exp Game", | |||
function() { | |||
var self = this; | |||
/** Store parameter options in instance variable */ | |||
self.params["1"] = initialismsArray; | |||
/** Callback */ | |||
self.registerStrategies(); | |||
} | |||
)); | |||
}); | |||
// Getting a list of every template in the wiki is non-trivial... | |||
/* Load Textcomplete then register the strategy/ies */ | /* Load Textcomplete then register the strategy/ies */ | ||
Line 137: | Line 194: | ||
precedingParamRegex += "\\|[^\\|]*"; | precedingParamRegex += "\\|[^\\|]*"; | ||
} | } | ||
var strategy = self.createStrategy( | var strategy = self.createStrategy( | ||
templateName, | templateName, | ||
paramName, | paramName, | ||
new RegExp("({{" + templateName + precedingParamRegex + "\\|)([^\\|]*)$"," | new RegExp("({{" + templateName + precedingParamRegex + "\\|)([^\\|]*)$",""), | ||
params[paramName], | params[paramName], | ||
function(name) { return name; }, | function(name) { return name; }, | ||
Line 147: | Line 203: | ||
); | ); | ||
strategies.push(strategy); | strategies.push(strategy); | ||
} | } | ||
} | } |