User:Guywan/Scripts/RefCruncher.js: Difference between revisions

Content deleted Content added
mNo edit summary
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 9:
if(debug) console.log("Running");
window.rc_refsCrunched = false;
window.rc_refs = [];
// Add key handler.
if(document.onkeyup !== null)
window.addEventListener("keydown", e =>
{
if(e.ctrlKey && e.altKey && e.which == 82)
var original = document.onkeyup;
document.onkeyup = function(e)
{
originalrun();
}
});
if(e.ctrlKey && e.altKey && e.which == 82)
{
run();
}
};
}
function run()
Line 31 ⟶ 25:
if(debug) console.log("Activate");
if(window.rc_refsCrunched)
{
rc_refsCrunched = uncrunchRefs();
window.rc_refsCrunched = false;
}
else
{
rc_refsCrunched = crunchRefs();
window.rc_refsCrunched = true;
}
}
Line 52 ⟶ 42:
var counter = 0;
text = text.replace(/(<ref.*?\/>)|(<ref.*?>(.|\s)*?<\/ref>)/g, function(match) =>
{
if(debug) console.log(match);
window.rc_refs.push(match);
return `{<ref# ${counter++}}/>`;
});
txtarea.value = text;
return true;
}
Line 70 ⟶ 62:
var text = txtarea.value;
text = text.replace(/\{<ref# (\d+)\}/>/g, function(match, p1) =>
{
if(debug) console.log(match);
return window.rc_refs[Number(p1)];
});
Line 80 ⟶ 72:
txtarea.value = text;
{
return false;
}
});