Jump to content

User:JPxG/TrackSum.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by JPxG (talk | contribs) at 22:35, 3 September 2021 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// 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) {
		cursor = tbox.indexOf("{{Tracklist");
		if (cursor == -1) {
			cursor = tbox.indexOf("{{tracklist");
		}	// If no "{{Tracklist", try to find a "{{tracklist".
		if (cursor == -1) {
			cursor = tbox.indexOf("{{Track listing");
		}	// If neither, try to find a "{{Track listing".
		if (cursor == -1) {
			cursor = tbox.indexOf("{{Track Listing");
		}	// If neither, try to find a "{{Track listing".
		if (cursor == -1) {
			cursor = tbox.indexOf("{{track listing");
		}	// Try to find an alternate.
		if (cursor == -1) {
			cursor = tbox.indexOf("{{Tracklisting");
		}	// Try to find an alternate.
		if (cursor == -1) {
			cursor = tbox.indexOf("{{tracklisting");
		}	// Try to find an alternate.
		if (cursor == -1) {
			cursor = tbox.indexOf("{{Soundtrack");
		}	// Try to find an alternate.
		if (cursor == -1) {
			cursor = tbox.indexOf("{{soundtrack");
		}	// Try to find an alternate.
		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>