function alphabetizeImgTags(imgtags){ var imageTagsArray = imgtags.split('.gif'); var enteredCardNameTags = imgtags.split('>'); // get just image names var cardNameToTag = {} for (index = 0; index < imageTagsArray.length-1; index++){ // get card name for key var firstLetter = imageTagsArray[index].lastIndexOf('/') + 1; var cardName = imageTagsArray[index].substring(firstLetter, imageTagsArray[index].length); // get original img tag for value; var currentTag = enteredCardNameTags[index]; var imgTag = currentTag.substring(currentTag.indexOf("<", currentTag.length)) + '>'; // handle duplicates if ( cardName in cardNameToTag){ cardNameToTag[cardName].push(imgTag); } else{ cardNameToTag[cardName] = [imgTag]; } } // sort card names var cardNamesArray = Object.keys(cardNameToTag); cardNamesArray.sort(); // make sorted list of tags var sortedTags = []; cardNamesArray.forEach( cardName => { cardNameToTag[cardName].forEach( imgTag => { sortedTags.push(imgTag.trim()); }) }) // return sorted return sortedTags.toString().replaceAll(',', ''); } async function sortColorsTCGData(){ colorSeriesData = await fetch('Colors TCG.html') .then(data => { return data.text() }) .then( data => { var tableBeginning = data.indexOf('') var tableEnding = data.lastIndexOf("") var dataRows = data.substring(tableBeginning, tableEnding).split(""); dataRows.splice(0,1); dataRows.pop(); // remove text around data for (index = 0; index < dataRows.length; index++){ dataRows[index] = dataRows[index].trim() dataRows[index] = dataRows[index].replaceAll("", ''); dataRows[index] = dataRows[index].replaceAll(""); // index 0, 1, and 3 newDataRow[0] = newDataRow[0].replaceAll("
", ''); var newDataRow = dataRows[index].split("
", ''); newDataRow[1] = newDataRow[1].replaceAll("
", ''); newDataRow[3] = newDataRow[3].replaceAll('', ''); // index 2, make deck name var endOfLinkIndex = newDataRow[2].lastIndexOf('">') newDataRow[2] = newDataRow[2].substring(endOfLinkIndex+2, newDataRow[2].length).replaceAll("",'').replaceAll(" ", '').toLowerCase(); newDataRow.pop(); dataRows[index] = newDataRow; } var testDictionary = {}; // create deck color dictionary global variable for (index = 0; index < dataRows.length; index++){ dataRow = dataRows[index]; // assign deck name series and color testDictionary[dataRow[2].trim()] = [dataRow[0], dataRow[3]]; } return testDictionary; }) return colorSeriesData; }