I am using a simple script on Tampermonkey to change some value on a webpage.
in the webpage, there is a input value on a input box i.e "FPPUTHP1100000"
This is a material code, The material code structure is as followes:-
F stand for FRESH
PPUTHP stand for PPC
110 Stand For ACS
0000 Stand for MRP.
Material code is not Universal, this could be changed each time.
i want to record it in variables and push a merged text in a empty input box
like ACS-PPC-MRP-FRESH
There are many material code but the basic structure is as above only.
First letter can be F,C,P,D (FRESH,C&T,PDMG,DMG)
Next six letter can be
PPUTHP,PPUSLH,PPUFLH,43UTHP,53UTHP (PPC,SUPER,WP,OPC43,OPC53)
next three letter can be 110,111,112,113,114 (ACS,VCS,PGU,DGU,AGU)
Next four letter can be 0000 and 5000 (MRP,NON MRP)
Can anybody tell how to make this script.
2
Answers
first of all stor the value in variable by using document. getElementById()
like this…
now just apply substring functions on this string and save them into the variables like this…
now just apply conditions and make you string like this
now same apply if-else ladder and add the part to final_string accordingly..
Assuming that the input is always in the order and length you’ve given, and the conversions are always one of the values you’ve given, you could create an array with the delimiting points to
substring
the input and then another array with matching indices as a lookup dictionary. Something like this:And if you want the output in a different order than the input, you can just: