User:JPxG/TrackSum.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:JPxG/TrackSum. |
// If you are editing a page, this script gives you a button to click and automatically sum up all the track lengths in [[Template:Tracklist]] to provide a total length.
// Skeleton of this code forked from Wikipedia:WikiProject User scripts/Scripts/Quick wikify
// - JPxG, 2021 September 3
function doTracksum() {
tbox = document.editform.wpTextbox1.value;
// Get the text from the edit box and store it as "tbox".
var cursor = 0;
// Set cursor to zero.
while(cursor != -1) {
cursore = tbox.indexOf("{{Tracklist", (cursor+1));
if (cursore == -1) {
cursore = tbox.indexOf("{{tracklist", (cursor+1));
} // If no "{{Tracklist", try to find a "{{tracklist".
if (cursore == -1) {
cursore = tbox.indexOf("{{Track listing", (cursor+1));
} // If neither, try to find a "{{Track listing".
if (cursore == -1) {
cursore = tbox.indexOf("{{Track Listing", (cursor+1));
} // If neither, try to find a "{{Track listing".
if (cursore == -1) {
cursore = tbox.indexOf("{{track listing", (cursor+1));
} // Try to find an alternate.
if (cursore == -1) {
cursore = tbox.indexOf("{{Tracklisting", (cursor+1));
} // Try to find an alternate.
if (cursore == -1) {
cursore = tbox.indexOf("{{tracklisting", (cursor+1));
} // Try to find an alternate.
if (cursore == -1) {
cursore = tbox.indexOf("{{Soundtrack", (cursor+1));
} // Try to find an alternate.
if (cursore == -1) {
cursore = tbox.indexOf("{{soundtrack", (cursor+1));
} // Try to find an alternate.
if (cursore == -1) {
cursor = cursore
} // Store the search cursor as the cursor.
document.editform.wpTextbox1.value = "Found one at" + cursor.toString();
// console.log("Found one at" + cursor.toString());
} // Close block to execute while cursor isn't -1
// document.editform.wpTextbox1.value = '{' + '{' + 'Wikify|date=' + '{' + '{' + 'subst:CURRENTMONTHNAME}} ' + '{' + '{' + 'subst:CURRENTYEAR}}}}\n\n' + document.editform.wpTextbox1.value;
document.editform.wpSummary.value = "Automatically summed track lengths [script-assisted: JPxG's [[User:JPxG/tracksum.js|TrackSum]] V0.1]";
document.editform.wpMinoredit.checked = true;
//document.editform.submit();
}
addOnloadHook(function() {
if (document.editform) {
addPortletLink("p-cactions", "javascript:doTracksum()", "Tracksum", "ca-tracksum", "Sum up track lengths in tracklist template", "");
}
});
// by [[User:Raylu|raylu]]
// </nowiki></pre>