User:Ohconfucius/test/MOSNUM utils.js: Difference between revisions

Content deleted Content added
formatted, JSHint fixes
change ohc_regex to work on the input text instead of the DOM
Line 5:
*/
mw.loader.load('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js');
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Pathoschild/Scripts/Regex_menu_framework.js&action=raw&ctype=text/javascript');
 
/** ------------------------------------------------------------------------- */
Line 11 ⟶ 10:
 
function ohc_regex_to_string(s) {
str =return s.toString();
str = str .replace(/^\//, "");
str = str .replace(/\/[^\/]*$/, "");
return str;
}
 
function ohc_alert_error(s, reg) { //reg can be undefined
var message = "DATES SCRIPT:\n" + s;
if (reg !== undefined) {
message += "\n\nRegex" + reg;
}
message += "\n\nPlease report the name of the article to [????]";
alert(message);
Line 169 ⟶ 166:
should return true if the replacement should be done, false otherwise.
*/
function ohc_regex(text, rg, sub, func) {
var reg = ohc_regex_to_string(rg);
var debug_reg = reg;
Line 307 ⟶ 304:
param_desc.sort(function(a,b) {return a.index - b.index;});
 
//replace magic strings with proper matchsmatches
for (var i = 0; i < Formats.length; i++) {
reg = reg.split(Formats[i].magic).join(ohc_regex_to_string(Formats[i].match));
Line 633 ⟶ 630:
var rg = new RegExp(reg,'gi');
 
var editbox = $('#wpTextbox1'), text = editbox.val();
if (simple_regex == true)
text = text.replace(rg, sub);
else
text = text.replace(rg, regex_worker);
editbox.val(text);
 
var aa_reg = debug_reg; //place for a breakpoint for debugging