zurück zur Startseite
  


Zurück XHTMLforum > Webentwicklung (außer XHTML und CSS) > Javascript & Ajax
Seite neu laden Debuggen von JavaScript in Chrome DevTools

Antwort
 
LinkBack Themen-Optionen Ansicht
  #1 (permalink)  
Alt 24.04.2018, 18:36
Erfahrener Benutzer
XHTMLforum-Mitglied
Thread-Ersteller
 
Registriert seit: 12.11.2010
Ort: Bad Langensalza
Beiträge: 733
gabischatz ist in Verruf geraten
Standard Debuggen von JavaScript in Chrome DevTools

hi ich habe mir in den DevTools den nachstehenden Code erstellt. Dieser soll in einer Css-Datei die Color-namen in Hex-werte und umgekehrt austauschen, sodass der kürzere Name/Wert eingetragen ist.
Nun macht mich aber die Ausgabe etwas stutzig. Habe ich da etwa einen Denkfehler?
MfG Lutz
Code:
var colors=["Black","#000","#000080","Navy","#00008B","DarkBlue","#0000CD","MediumBlue","Blue","#00F","#006400","DarkGreen","#008000","Green","#008080","Teal","DarkCyan","#008B8B","DeepSkyBlue","#00BFFF","DarkTurquoise","#00CED1","MediumSpringGreen","#00FA9A","Lime","#0F0","SpringGreen","#00FF7F","Aqua","#0FF","Cyan","#0FF","MidnightBlue","#191970","DodgerBlue","#1E90FF","LightSeaGreen","#20B2AA","ForestGreen","#228B22","SeaGreen","#2E8B57","DarkSlateGray","#2F4F4F","DarkSlateGrey","#2F4F4F","LimeGreen","#32CD32","MediumSeaGreen","#3CB371","Turquoise","#40E0D0","RoyalBlue","#4169E1","SteelBlue","#4682B4","DarkSlateBlue","#483D8B","MediumTurquoise","#48D1CC","#4B0082","Indigo","DarkOliveGreen","#556B2F","CadetBlue","#5F9EA0","CornflowerBlue","#6495ED","RebeccaPurple","#663399","MediumAquaMarine","#66CDAA","DimGray","#696969","DimGrey","#696969","SlateBlue","#6A5ACD","OliveDrab","#6B8E23","SlateGray","#708090","SlateGrey","#708090","LightSlateGray","#789","LightSlateGrey","#789","MediumSlateBlue","#7B68EE","LawnGreen","#7CFC00","Chartreuse","#7FFF00","Aquamarine","#7FFFD4","#800000","Maroon","#800080","Purple","#808000","Olive","#808080","Gray","Grey","#808080","SkyBlue","#87CEEB","LightSkyBlue","#87CEFA","BlueViolet","#8A2BE2","DarkRed","#8B0000","DarkMagenta","#8B008B","SaddleBrown","#8B4513","DarkSeaGreen","#8FBC8F","LightGreen","#90EE90","MediumPurple","#9370DB","DarkViolet","#9400D3","PaleGreen","#98FB98","DarkOrchid","#9932CC","YellowGreen","#9ACD32","#A0522D","Sienna","#A52A2A","Brown","DarkGrey","#A9A9A9","LightBlue","#ADD8E6","GreenYellow","#ADFF2F","PaleTurquoise","#AFEEEE","LightSteelBlue","#B0C4DE","PowderBlue","#B0E0E6","FireBrick","#B22222","DarkGoldenRod","#B8860B","MediumOrchid","#BA55D3","RosyBrown","#BC8F8F","DarkKhaki","#BDB76B","Silver","#C0C0C0","MediumVioletRed","#C71585","IndianRed","#CD5C5C","#CD853F","Peru","Chocolate","#D2691E","#D2B48C","Tan","LightGray","#D3D3D3","Thistle","#D8BFD8","#DA70D6","Orchid","GoldenRod","#DAA520","PaleVioletRed","#DB7093","Crimson","#DC143C","Gainsboro","#DCDCDC","#DDA0DD","Plum","BurlyWood","#DEB887","LightCyan","#E0FFFF","Lavender","#E6E6FA","DarkSalmon","#E9967A","#EE82EE","Violet","PaleGoldenRod","#EEE8AA","LightCoral","#F08080","#F0E68C","Khaki","AliceBlue","#F0F8FF","HoneyDew","#F0FFF0","#F0FFFF","Azure","SandyBrown","#F4A460","#F5DEB3","Wheat","#F5F5DC","Beige","WhiteSmoke","#F5F5F5","MintCream","#F5FFFA","GhostWhite","#F8F8FF","#FA8072","Salmon","AntiqueWhite","#FAEBD7","#FAF0E6","Linen","LightGoldenRodYellow","#FAFAD2","OldLace","#FDF5E6","#FF0000","Red","Fuchsia","#F0F","Magenta","#F0F","DeepPink","#FF1493","OrangeRed","#FF4500","#FF6347","Tomato","HotPink","#FF69B4","#FF7F50","Coral","DarkOrange","#FF8C00","LightSalmon","#FFA07A","#FFA500","Orange","LightPink","#FFB6C1","#FFC0CB","Pink","#FFD700","Gold","PeachPuff","#FFDAB9","NavajoWhite","#FFDEAD","Moccasin","#FFE4B5","#FFE4C4","Bisque","MistyRose","#FFE4E1","BlanchedAlmond","#FFEBCD","PapayaWhip","#FFEFD5","LavenderBlush","#FFF0F5","SeaShell","#FFF5EE","Cornsilk","#FFF8DC","LemonChiffon","#FFFACD","FloralWhite","#FFFAF0","#FFFAFA","Snow","Yellow","#FF0","LightYellow","#FFFFE0","#FFFFF0","Ivory","White","#FFF"];
var input_text="DarkSlateBlue";
	  for(c=0; c<colors.length; c++){
		var _c= new RegExp(colors[c],"i");
		++c;
		out_text= input_text.replace(_c,colors[c]);
		console.log(out_text);
	  }
Mit Zitat antworten
Sponsored Links
  #2 (permalink)  
Alt 25.04.2018, 06:59
Benutzerbild von protonenbeschleuniger
Verbesserer
XHTMLforum-Kenner
 
Registriert seit: 06.09.2007
Beiträge: 4.868
protonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblick
Standard

Das Array ist falsch aufgebaut.
Mit Zitat antworten
Sponsored Links
  #3 (permalink)  
Alt 25.04.2018, 07:12
Erfahrener Benutzer
XHTMLforum-Mitglied
Thread-Ersteller
 
Registriert seit: 12.11.2010
Ort: Bad Langensalza
Beiträge: 733
gabischatz ist in Verruf geraten
Standard

Zitat:
Zitat von protonenbeschleuniger Beitrag anzeigen
Das Array ist falsch aufgebaut.
Ok guten Morgen.
Ist es so besser?
Code:
var colors=["^Black$", "#000",
 "^#000080$", "Navy",
 "^#00008B$", "DarkBlue",
 "^#0000CD$", "MediumBlue",
 "^Blue$", "#00F",
 "^#006400$", "DarkGreen",
 "^#008000$", "Green",
 "^#008080$", "Teal",
 "^DarkCyan$", "#008B8B",
 "^DeepSkyBlue$", "#00BFFF",
 "^DarkTurquoise$", "#00CED1",
 "^MediumSpringGreen$", "#00FA9A",
 "^Lime$", "#0F0",
 "^SpringGreen$", "#00FF7F",
 "^Aqua$", "#0FF",
 "^Cyan$", "#0FF",
 "^MidnightBlue$", "#191970",
 "^DodgerBlue$", "#1E90FF",
 "^LightSeaGreen$", "#20B2AA",
 "^ForestGreen$", "#228B22",
 "^SeaGreen$", "#2E8B57",
 "^DarkSlateGray$", "#2F4F4F",
 "^DarkSlateGrey$", "#2F4F4F",
 "^LimeGreen$", "#32CD32",
 "^MediumSeaGreen$", "#3CB371",
 "^Turquoise$", "#40E0D0",
 "^RoyalBlue$", "#4169E1",
 "^SteelBlue$", "#4682B4",
 "^DarkSlateBlue$", "#483D8B",
 "^MediumTurquoise$", "#48D1CC",
 "^#4B0082$", "Indigo",
 "^DarkOliveGreen$", "#556B2F",
 "^CadetBlue$", "#5F9EA0",
 "^CornflowerBlue$", "#6495ED",
 "^RebeccaPurple$", "#663399",
 "^MediumAquaMarine$", "#66CDAA",
 "^DimGray$", "#696969",
 "^DimGrey$", "#696969",
 "^SlateBlue$", "#6A5ACD",
 "^OliveDrab$", "#6B8E23",
 "^SlateGray$", "#708090",
 "^SlateGrey$", "#708090",
 "^LightSlateGray$", "#789",
 "^LightSlateGrey$", "#789",
 "^MediumSlateBlue$", "#7B68EE",
 "^LawnGreen$", "#7CFC00",
 "^Chartreuse$", "#7FFF00",
 "^Aquamarine$", "#7FFFD4",
 "^#800000$", "Maroon",
 "^#800080$", "Purple",
 "^#808000$", "Olive",
 "^#808080$", "Gray",
 "^Grey$", "#808080",
 "^SkyBlue$", "#87CEEB",
 "^LightSkyBlue$", "#87CEFA",
 "^BlueViolet$", "#8A2BE2",
 "^DarkRed$", "#8B0000",
 "^DarkMagenta$", "#8B008B",
 "^SaddleBrown$", "#8B4513",
 "^DarkSeaGreen$", "#8FBC8F",
 "^LightGreen$", "#90EE90",
 "^MediumPurple$", "#9370DB",
 "^DarkViolet$", "#9400D3",
 "^PaleGreen$", "#98FB98",
 "^DarkOrchid$", "#9932CC",
 "^YellowGreen$", "#9ACD32",
 "^#A0522D$", "Sienna",
 "^#A52A2A$", "Brown",
 "^DarkGrey$", "#A9A9A9",
 "^LightBlue$", "#ADD8E6",
 "^GreenYellow$", "#ADFF2F",
 "^PaleTurquoise$", "#AFEEEE",
 "^LightSteelBlue$", "#B0C4DE",
 "^PowderBlue$", "#B0E0E6",
 "^FireBrick$", "#B22222",
 "^DarkGoldenRod$", "#B8860B",
 "^MediumOrchid$", "#BA55D3",
 "^RosyBrown$", "#BC8F8F",
 "^DarkKhaki$", "#BDB76B",
 "^Silver$", "#C0C0C0",
 "^MediumVioletRed$", "#C71585",
 "^IndianRed$", "#CD5C5C",
 "^#CD853F$", "Peru",
 "^Chocolate$", "#D2691E",
 "^#D2B48C$", "Tan",
 "^LightGray$", "#D3D3D3",
 "^Thistle$", "#D8BFD8",
 "^#DA70D6$", "Orchid",
 "^GoldenRod$", "#DAA520",
 "^PaleVioletRed$", "#DB7093",
 "^Crimson$", "#DC143C",
 "^Gainsboro$", "#DCDCDC",
 "^#DDA0DD$", "Plum",
 "^BurlyWood$", "#DEB887",
 "^LightCyan$", "#E0FFFF",
 "^Lavender$", "#E6E6FA",
 "^DarkSalmon$", "#E9967A",
 "^#EE82EE$", "Violet",
 "^PaleGoldenRod$", "#EEE8AA",
 "^LightCoral$", "#F08080",
 "^#F0E68C$", "Khaki",
 "^AliceBlue$", "#F0F8FF",
 "^HoneyDew$", "#F0FFF0",
 "^#F0FFFF$", "Azure",
 "^SandyBrown$", "#F4A460",
 "^#F5DEB3$", "Wheat",
 "^#F5F5DC$", "Beige",
 "^WhiteSmoke$", "#F5F5F5",
 "^MintCream$", "#F5FFFA",
 "^GhostWhite$", "#F8F8FF",
 "^#FA8072$", "Salmon",
 "^AntiqueWhite$", "#FAEBD7",
 "^#FAF0E6$", "Linen",
 "^LightGoldenRodYellow$", "#FAFAD2",
 "^OldLace$", "#FDF5E6",
 "^#FF0000$", "Red",
 "^Fuchsia$", "#F0F",
 "^Magenta$", "#F0F",
 "^DeepPink$", "#FF1493",
 "^OrangeRed$", "#FF4500",
 "^#FF6347$", "Tomato",
 "^HotPink$", "#FF69B4",
 "^#FF7F50$", "Coral",
 "^DarkOrange$", "#FF8C00",
 "^LightSalmon$", "#FFA07A",
 "^#FFA500$", "Orange",
 "^LightPink$", "#FFB6C1",
 "^#FFC0CB$", "Pink",
 "^#FFD700$", "Gold",
 "^PeachPuff$", "#FFDAB9",
 "^NavajoWhite$", "#FFDEAD",
 "^Moccasin$", "#FFE4B5",
 "^#FFE4C4$", "Bisque",
 "^MistyRose$", "#FFE4E1",
 "^BlanchedAlmond$", "#FFEBCD",
 "^PapayaWhip$", "#FFEFD5",
 "^LavenderBlush$", "#FFF0F5",
 "^SeaShell$", "#FFF5EE",
 "^Cornsilk$", "#FFF8DC",
 "^LemonChiffon$", "#FFFACD",
 "^FloralWhite$", "#FFFAF0",
 "^#FFFAFA$", "Snow",
 "^Yellow$", "#FF0",
 "^LightYellow$", "#FFFFE0",
 "^#FFFFF0$", "Ivory",
 "^White$", "#FFF"];
    var input_text = "b { color: lightyellow; border-color: LavenderBlush; color: #999999; } cite { color: PapayaWhip; color: White; text-shadow: -2px -2px 10px goldenrod; } ";
	console.log(input_text);
	for (c = 0; c < colors.length; c++) {
        var _c = new RegExp((colors[c]),"gim");
        ++c;console.log(_c);
        input_text = input_text.replace(_c, colors[c]);
		console.log(colors[c]);
    }   console.log(input_text);
Mit Zitat antworten
  #4 (permalink)  
Alt 25.04.2018, 07:31
Benutzerbild von protonenbeschleuniger
Verbesserer
XHTMLforum-Kenner
 
Registriert seit: 06.09.2007
Beiträge: 4.868
protonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblick
Standard

Nein. Der Name und der Hexcode müssen immer in der gleichen Abfolge sein.
Mit Zitat antworten
  #5 (permalink)  
Alt 25.04.2018, 14:36
Erfahrener Benutzer
XHTMLforum-Mitglied
Thread-Ersteller
 
Registriert seit: 12.11.2010
Ort: Bad Langensalza
Beiträge: 733
gabischatz ist in Verruf geraten
Standard

So ich habe es jetzt.
In der Console geht es zwar nicht, aber als Script.
In der Console wird aus \b ein Hieroglyph.
Code:
var colors=[
 "(\bMediumSpringGreen\b)", "#00FA9A",
 "(\bMediumAquaMarine\b)", "#66CDAA",
 "(\bMediumTurquoise\b)", "#48D1CC",
 "(\bMediumVioletRed\b)", "#C71585",
 "(\bMediumSeaGreen\b)", "#3CB371",
 "(\bMediumOrchid\b)", "#BA55D3",
 "(\bDarkOliveGreen\b)", "#556B2F",
 "(\bDarkTurquoise\b)", "#00CED1",
 "(\bDarkGoldenRod\b)", "#B8860B",
 "(\bDarkSlateGray\b)", "#2F4F4F",
 "(\bSlateGrey\b)", "#708090",
 "(\bDarkSlateBlue\b)", "#483D8B",
 "(\bDarkSeaGreen\b)", "#8FBC8F",
 "(\bDarkMagenta\b)", "#8B008B",
 "(\bDarkViolet\b)", "#9400D3",
 "(\bDarkOrchid\b)", "#9932CC",
 "(\bDarkSalmon\b)", "#E9967A",
 "(\bDarkOrange\b)", "#FF8C00",
 "(\bDarkKhaki\b)", "#BDB76B",
 "(\bDarkCyan\b)", "#008B8B",
 "(\bDarkGrey\b)", "#A9A9A9",
 "(\bDarkRed\b)", "#8B0000",
 "(\bLightGoldenRodYellow\b)", "#FAFAD2",
 "(\bLightSteelBlue\b)", "#B0C4DE",
 "(\bLightSeaGreen\b)", "#20B2AA",
 "(\bLightSkyBlue\b)", "#87CEFA",
 "(\bLightSlateGrey\b)", "#789",
 "(\bLightYellow\b)", "#FFFFE0",
 "(\bLightSalmon\b)", "#FFA07A",
 "(\bLightCoral\b)", "#F08080",
 "(\bLightGreen\b)", "#90EE90",
 "(\bLightBlue\b)", "#ADD8E6",
 "(\bLightCyan\b)", "#E0FFFF",
 "(\bLightPink\b)", "#FFB6C1",
 "(\bLightGray\b)", "#D3D3D3",
 "(\bBlack\b)", "#000",
 "(\bLime\b)", "#0F0",
 "(\bSpringGreen\b)", "#00FF7F",
 "(\bAqua\b)", "#0FF",
 "(\bCyan\b)", "#0FF",
 "(\bForestGreen\b)", "#228B22",
 "(\bSeaGreen\b)", "#2E8B57",
 "(\bLimeGreen\b)", "#32CD32",
 "(\bTurquoise\b)", "#40E0D0",
 "(\bRebeccaPurple\b)", "#663399",
 "(\bDimGrey\b)", "#696969",
 "(\bOliveDrab\b)", "#6B8E23",
 "(\bLawnGreen\b)", "#7CFC00",
 "(\bChartreuse\b)", "#7FFF00",
 "(\bAquamarine\b)", "#7FFFD4",
 "(\bGrey\b)", "#808080",
 "(\bSaddleBrown\b)", "#8B4513",
 "(\bMediumPurple\b)", "#9370DB",
 "(\bPaleGreen\b)", "#98FB98",
 "(\bPaleTurquoise\b)", "#AFEEEE",
 "(\bFireBrick\b)", "#B22222",
 "(\bRosyBrown\b)", "#BC8F8F",
 "(\bSilver\b)", "#C0C0C0",
 "(\bIndianRed\b)", "#CD5C5C",
 "(\bChocolate\b)", "#D2691E",
 "(\bThistle\b)", "#D8BFD8",
 "(\bGoldenRod\b)", "#DAA520",
 "(\bPaleVioletRed\b)", "#DB7093",
 "(\bCrimson\b)", "#DC143C",
 "(\bGainsboro\b)", "#DCDCDC",
 "(\bBurlyWood\b)", "#DEB887",
 "(\bLavender\b)", "#E6E6FA",
 "(\bPaleGoldenRod\b)", "#EEE8AA",
 "(\bHoneyDew\b)", "#F0FFF0",
 "(\bSandyBrown\b)", "#F4A460",
 "(\bMintCream\b)", "#F5FFFA",
 "(\bOldLace\b)", "#FDF5E6",
 "(\bFuchsia\b)", "#F0F",
 "(\bMagenta\b)", "#F0F",
 "(\bDeepPink\b)", "#FF1493",
 "(\bOrangeRed\b)", "#FF4500",
 "(\bHotPink\b)", "#FF69B4",
 "(\bPeachPuff\b)", "#FFDAB9",
 "(\bMoccasin\b)", "#FFE4B5",
 "(\bMistyRose\b)", "#FFE4E1",
 "(\bBlanchedAlmond\b)", "#FFEBCD",
 "(\bPapayaWhip\b)", "#FFEFD5",
 "(\bLavenderBlush\b)", "#FFF0F5",
 "(\bSeaShell\b)", "#FFF5EE",
 "(\bCornsilk\b)", "#FFF8DC",
 "(\bLemonChiffon\b)", "#FFFACD",
 "(\bRoyalBlue\b)", "#4169E1",
 "(\bSteelBlue\b)", "#4682B4",
 "(\bSlateBlue\b)", "#6A5ACD",
 "(\bMediumSlateBlue\b)", "#7B68EE",
 "(\bPowderBlue\b)", "#B0E0E6",
 "(\bMidnightBlue\b)", "#191970",
 "(\bDodgerBlue\b)", "#1E90FF",
 "(\bDeepSkyBlue\b)", "#00BFFF",
 "(\bSkyBlue\b)", "#87CEEB",
 "(\bCornflowerBlue\b)", "#6495ED",
 "(\bCadetBlue\b)", "#5F9EA0",
 "(\bAliceBlue\b)", "#F0F8FF",
 "(\bBlueViolet\b)", "#8A2BE2",
 "(\bBlue\b)", "#00F",
 "(\bYellowGreen\b)", "#9ACD32",
 "(\bGreenYellow\b)", "#ADFF2F",
 "(\bYellow\b)", "#FF0",
 "(\bAntiqueWhite\b)", "#FAEBD7",
 "(\bFloralWhite\b)", "#FFFAF0",
 "(\bGhostWhite\b)", "#F8F8FF",
 "(\bNavajoWhite\b)", "#FFDEAD",
 "(\bWhiteSmoke\b)", "#F5F5F5",
 "(\bWhite\b)", "#FFF",
 "(\b#CD853F\b)", "Peru",
 "(\b#D2B48C\b)", "Tan",
 "(\b#DA70D6\b)", "Orchid",
 "(\b#DDA0DD\b)", "Plum",
 "(\b#EE82EE\b)", "Violet",
 "(\b#F0E68C\b)", "Khaki",
 "(\b#F0FFFF\b)", "Azure",
 "(\b#F5DEB3\b)", "Wheat",
 "(\b#F5F5DC\b)", "Beige",
 "(\b#FA8072\b)", "Salmon",
 "(\b#FAF0E6\b)", "Linen",
 "(\b#FF6347\b)", "Tomato",
 "(\b#FFA500\b)", "Orange",
 "(\b#FF0000\b)", "Red",
 "(\b#FF7F50\b)", "Coral",
 "(\b#FFC0CB\b)", "Pink",
 "(\b#FFD700\b)", "Gold",
 "(\b#FFE4C4\b)", "Bisque",
 "(\b#FFFAFA\b)", "Snow",
 "(\b#FFFFF0\b)", "Ivory",
 "(\b#000080\b)", "Navy",
 "(\b#00008B\b)", "DarkBlue",
 "(\b#0000CD\b)", "MediumBlue",
 "(\b#006400\b)", "DarkGreen",
 "(\b#008000\b)", "Green",
 "(\b#008080\b)", "Teal",
 "(\b#800000\b)", "Maroon",
 "(\b#4B0082\b)", "Indigo",
 "(\b#800080\b)", "Purple",
 "(\b#808000\b)", "Olive",
 "(\b#808080\b)", "Gray",
 "(\b#A0522D\b)", "Sienna",
 "(\b#A52A2A\b)", "Brown"];
  var input_text = "Black Blue DarkCyan DeepSkyBlue DarkTurquoise MediumSpringGreen Lime SpringGreen Aqua Cyan MidnightBlue DodgerBlue LightSeaGreen ForestGreen SeaGreen DarkSlateGray DarkSlateGrey LimeGreen MediumSeaGreen Turquoise RoyalBlue SteelBlue DarkSlateBlue MediumTurquoise DarkOliveGreen CadetBlue CornflowerBlue RebeccaPurple MediumAquaMarine DimGray DimGrey SlateBlue OliveDrab SlateGray SlateGrey LightSlateGray LightSlateGrey MediumSlateBlue LawnGreen Chartreuse Aquamarine Grey SkyBlue LightSkyBlue BlueViolet DarkRed DarkMagenta SaddleBrown DarkSeaGreen LightGreen MediumPurple DarkViolet PaleGreen DarkOrchid YellowGreen DarkGrey LightBlue GreenYellow PaleTurquoise LightSteelBlue PowderBlue FireBrick DarkGoldenRod MediumOrchid RosyBrown DarkKhaki Silver MediumVioletRed IndianRed Chocolate LightGray Thistle GoldenRod PaleVioletRed Crimson Gainsboro BurlyWood LightCyan Lavender DarkSalmon PaleGoldenRod LightCoral AliceBlue HoneyDew SandyBrown WhiteSmoke MintCream GhostWhite AntiqueWhite LightGoldenRodYellow OldLace Fuchsia Magenta DeepPink OrangeRed HotPink DarkOrange LightSalmon LightPink PeachPuff NavajoWhite Moccasin MistyRose BlanchedAlmond PapayaWhip LavenderBlush SeaShell Cornsilk LemonChiffon FloralWhite Yellow LightYellow White";
	console.log(input_text);
	for (c = 0; c < colors.length; c++) {
        var _c = new RegExp((colors[c]),"gi");
        ++c;
   console.log("input_text.replace("+_c+", "+colors[c]+");");
        input_text = input_text.replace(_c, colors[c]);
    }   console.log(input_text);

Nun wollte ich noch alle Hex-Codes(6 Digits) umwandeln in (3 Digits).
Beispiel: #6688aa=>#68a usw.
Hier habe ich bestimmt wieder so einen blöden Denkfehler.
Code:
for(r=0; r<16; r++){
		/* var r_ = new RegExp("\b#"+rgb[r]+rgb[r]+"0000\b", "i"); */
		var r_ = new RegExp("#"+rgb[r]+rgb[r]+"0000", "i");
	 	var _r = "#"+rgb[r]+"00";
	    p3 = p3.replace(r_,_r);
		console.log(r_);
	    for(g=0; g<16; g++){
	 		/* var g_ = new RegExp("\b#"+rgb[r]+rgb[r]+rgb[g]+rgb[g]+"00\b", "i"); */
	 		var g_ = new RegExp("#"+rgb[r]+rgb[r]+rgb[g]+rgb[g]+"00", "i");
	 		var _g = "#"+rgb[r]+rgb[g]+"0";
		 	p3 = p3.replace(g_,_g);
		console.log(g_);

	    	for(b=0; b<16; b++){
	 			/* var b_ = new RegExp("\b#"+rgb[r]+rgb[r]+rgb[y]+rgb[y]+rgb[b]+rgb[b]+"\b", "i"); */
	 			var b_ = new RegExp("#"+rgb[r]+rgb[r]+rgb[g]+rgb[g]+rgb[b]+rgb[b], "i");
	 			var _b = "#"+rgb[r]+rgb[g]+rgb[b];
				p3 = p3.replace(b_,_b);
		console.log(b_);
	    	}
	    }
	}

Geändert von gabischatz (25.04.2018 um 14:43 Uhr) Grund: Consolen-Ausgabe hinzugefügt
Mit Zitat antworten
  #6 (permalink)  
Alt 25.04.2018, 16:23
Benutzerbild von protonenbeschleuniger
Verbesserer
XHTMLforum-Kenner
 
Registriert seit: 06.09.2007
Beiträge: 4.868
protonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblick
Standard

Ui, du machst es dir aber umständlich. Das Problem ist, dass in deinem Array die Abfolge nicht stimmen, du tauscht die Platzierung oder hat das einen Grund?

Normalerweise würde man das mit einem Objet machen. In etwa so:

Code:
var Color = (function(){
	var colors= {
	 "MediumSpringGreen" : "#00FA9A",
	 "MediumAquaMarine":  "#66CDAA",
	 "MediumTurquoise" :  "#48D1CC",
	 "MediumVioletRed":  "#C71585",
	 "MediumSeaGreen":  "#3CB371",
	};
	return {
		name2hex: function(name) {
		return colors[name];
		},
		hex2name: function(hex) {
			var ret = null;
			Object.keys(colors).forEach(function(item) {
				if(colors[item] === hex) ret = item;
			});
			return ret;
		}
	};

})()

console.log('MediumSpringGreen' +'='+ Color.name2hex('MediumSpringGreen'));
console.log('#00FA9A' +'='+ Color.hex2name('#00FA9A'));
Die doppelten Farbwerte kürzen ginge, vermutlich mit einem regulären Ausdruck ich krieg den aber nicht hin.

such mal https://duckduckgo.com/?q=reg+exp+hexcolor+shorten
Mit Zitat antworten
  #7 (permalink)  
Alt 25.04.2018, 20:14
Erfahrener Benutzer
XHTMLforum-Mitglied
Thread-Ersteller
 
Registriert seit: 12.11.2010
Ort: Bad Langensalza
Beiträge: 733
gabischatz ist in Verruf geraten
Standard

Zitat:
Zitat von protonenbeschleuniger Beitrag anzeigen
Das Problem ist, dass in deinem Array die Abfolge nicht stimmen, du tauscht die Platzierung oder hat das einen Grund?
Ja hat es z.B. Tan ist kürzer als #D2B48C.
Deinen Vorschlag schaue ich mir aber trotztem an.
Danke
Mit Zitat antworten
  #8 (permalink)  
Alt 25.04.2018, 20:43
Benutzerbild von protonenbeschleuniger
Verbesserer
XHTMLforum-Kenner
 
Registriert seit: 06.09.2007
Beiträge: 4.868
protonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblick
Standard

Zitat:
Zitat von gabischatz Beitrag anzeigen
Ja hat es z.B. Tan ist kürzer als #D2B48C.
Ich meinte eigentlich das:
Code:
..
 "(\bGhostWhite\b)", "#F8F8FF",
 "(\bNavajoWhite\b)", "#FFDEAD",
 "(\bWhiteSmoke\b)", "#F5F5F5",
 "(\bWhite\b)", "#FFF",
 "(\b#CD853F\b)", "Peru",
 "(\b#D2B48C\b)", "Tan",
 "(\b#DA70D6\b)", "Orchid",
 "(\b#DDA0DD\b)", "Plum",
..
Hier steht erst der Name, dann der Hexcode, bis zum Eintrag Peru, da wechselst du die Reihenfolge.
Mit Zitat antworten
  #9 (permalink)  
Alt 26.04.2018, 09:09
Erfahrener Benutzer
XHTMLforum-Mitglied
Thread-Ersteller
 
Registriert seit: 12.11.2010
Ort: Bad Langensalza
Beiträge: 733
gabischatz ist in Verruf geraten
Standard

Ja das ist doch richtig, es geht doch nicht um Hex-Code und Name sondern um Lange- und Kurz-Bezeichnung. Links also lang und rechts kurz.
Damit kann ich jetzt in einer Schleife alle alle Langen-Bezeichnungen abfragen und durch die entsp. Kurz-Bezeichnung ersetzen.
Code:
input_text = input_text.replace(Lang,Kurz);
Mit Zitat antworten
Sponsored Links
  #10 (permalink)  
Alt 26.04.2018, 09:34
Benutzerbild von protonenbeschleuniger
Verbesserer
XHTMLforum-Kenner
 
Registriert seit: 06.09.2007
Beiträge: 4.868
protonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblickprotonenbeschleuniger ist ein wunderbarer Anblick
Standard

Zitat:
Zitat von gabischatz Beitrag anzeigen
Ja das ist doch richtig, es geht doch nicht um Hex-Code und Name sondern um Lange- und Kurz-Bezeichnung. Links also lang und rechts kurz.
Damit kann ich jetzt in einer Schleife alle alle Langen-Bezeichnungen abfragen und durch die entsp. Kurz-Bezeichnung ersetzen.
Code:
input_text = input_text.replace(Lang,Kurz);
Jetzt verstehe ich du willst die kürzere Zeichenkette ermitteln. Darf man fragen wieso?
Mit Zitat antworten
Sponsored Links
Antwort

Stichwörter
chrome devtools, debuggen, javascript

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
CSS debuggen in FF oder Chrome - hover finden Krischu CSS 3 01.09.2016 08:00
Chrome und Firefox Ignoriert Quelltext Formatierung =( BamiGorengo (X)HTML 4 07.12.2013 14:15
Software Engineer JavaScript Framework (m/w) itchristian Jobs 0 09.01.2012 17:27
Wort in Javascript Code einfügen; dann Javascript Code ausgeben Sp33dy G0nz4l3s Javascript & Ajax 1 23.05.2008 09:37
Impressumsaufruf mit Javascript Sinclair Javascript & Ajax 6 19.05.2008 15:41


Alle Zeitangaben in WEZ +2. Es ist jetzt 11:50 Uhr.