User:Utcursch/Migrate Infobox Indian Jurisdiction to Infobox settlement/main.js: Difference between revisions

Content deleted Content added
m dab
extract coords
Line 4:
* @author User:Utcursch
*/
 
// for coord
var latd = "";
var latm = "";
var lats = "";
var longd = "";
var longm = "";
var longs = "";
 
/**
Line 11 ⟶ 19:
// regular expression to parse Infobox Indian Jurisdiction
var regex = /{{Infobox Indian Jurisdiction[^{]*?({{[^}]*?}}[\s\S]*?)*}}/gmi
// regular expression to parse coord template
var regex_coord = /{{coord[^{]*?({{[^}]*?}}[\s\S]*?)*}}/gmi
 
// get the article content
var orig_article_text = document.getElementById("wpTextbox1").value;
 
 
// extract latitude and longitude information from the coord template
var arr_coord_text = orig_article_text.match(regex_coord);
// coord found
if (arr_coord_text != null) {
// get coord text
var coord_text = arr_coord_text[0];
 
var coord_params = coord_text.split("|");
if ((coord_params[2] == "N") || (coord_params[2] == "S")) {
// {{Coord|44.112|N|91|E|display=title}}
var latd = coord_params[1];
var longd = coord_params[3];
} else {
// {{coord|26|10|10|N|91|34|21|E|type:landmark_source:kolossus-itwiki|display=title}}
var latd = coord_params[1];
var latm = coord_params[2];
var lats = coord_params[3];
var longd = coord_params[6];
var longm = coord_params[6];
var longs = coord_params[7];
}
 
// replace original infobox with the new one
orig_article_text = orig_article_text.replace(regex_coord, "");
}
 
// get the infobox text
Line 372 ⟶ 409:
"| pushpin_map_alt = " + "\n" +
"| pushpin_map_caption = " + (orig_infobox_params["pushpin_map_caption"] ? orig_infobox_params["pushpin_map_caption"] : ("Location in " + pushpin_map_caption)) + "\n" +
"| latd = " + (orig_infobox_params["latd"] ? orig_infobox_params["latd"] : ""latd) + "\n" +
"| latm = " + (orig_infobox_params["latm"] ? orig_infobox_params["latm"] : ""latm) + "\n" +
"| lats = " + (orig_infobox_params["lats"] ? orig_infobox_params["lats"] : ""lats) + "\n" +
"| latNS = " + "N\n" +
"| longd = " + (orig_infobox_params["longd"] ? orig_infobox_params["longd"] : ""longd) + "\n" +
"| longm = " + (orig_infobox_params["longm"] ? orig_infobox_params["longm"] : ""longm) + "\n" +
"| longs = " + (orig_infobox_params["longs"] ? orig_infobox_params["longs"] : ""longs) + "\n" +
"| longEW = " + "E\n" +
/*