Content deleted Content added
Epicgenius (talk | contribs) test |
Epicgenius (talk | contribs) fix |
||
Line 1:
/*
The main script page is [[User:Epicgenius/sortcategories.js]].
*/
$(function($) {
/*
Line 25 ⟶ 29:
// Categories to check
var category = "[[Category:";
var categoryEnd = "]]"; // This might match both categories and links
var categoryA = category+"A ";
var categoryAn = category+"An ";
var categoryThe = category+"The ";
var categoryEponymous = category+mw.config.get("wgTitle");
// var defaultSort = "{{DEFAULTSORT:";
var stubTag = "-stub}}";
// Get the text up to the start of the categories, and then all of the text with the categories.
var categoriesStart = wpTextbox1_V.indexOf(category);
var categoriesEnd = wpTextbox1_V.lastIndexOf(categoryEnd);
var textBeforeCategories = wpTextbox1_V.substr(0, categoriesStart).trim();
var textWithCategories = wpTextbox1_V.substr(categoriesStart,categoriesEnd-categoriesStart+2).trim();
var textAfterCategories = wpTextbox1_V.substr(categoriesEnd+2).trim();
// Categories should be on new lines, so split by new line, sort alphabetically with a few checks, then join again with new lines.
Line 39 ⟶ 48:
var splitCategories = textWithCategories.split("\n");
splitCategories.sort(function(a, b) {
if (a.substr(0, categoryEponymous.length) == categoryEponymous) return -1e8;
if (b.substr(0, categoryEponymous.length) == categoryEponymous) return 1e8;
Line 53 ⟶ 63:
return a.localeCompare(b);
});
textWithCategories = splitCategories.join("\n");
if (wpTextbox1_V.indexOf(stubTag) < 0) {
textWithCategories = textWithCategories;
} else {
textWithCategories = textWithCategories+"\n\n\n";
}
// Merge pre-category text back with the sorted and joined category text, place back in textbok and add summary.
wpTextbox1.value = textBeforeCategories+"
setoptions(minor = 'true');
setreason('sorted categories alphabetically via [[User:Epicgenius/sortcategories.js|script]]', 'append');
|