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

Content deleted Content added
mNo edit summary
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 9:
if(debug) console.log("Running");
window.rc_refsCrunched = false;
window.rc_refs = [];
// Don'tAdd overwrite an existing onkeyupkey handler.
window.addEventListener("keydown", e =>
var o = document.onkeyup;
document.onkeyup = document.onkeyup === null ? handle : e => { o(); handle(e); };
function handle(e)
{
if(e.ctrlKey && e.altKey && e.which == 82)
Line 22 ⟶ 19:
run();
}
});
function run()
Line 28 ⟶ 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 49 ⟶ 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 67 ⟶ 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 77 ⟶ 72:
txtarea.value = text;
return false;
}
});