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

Content deleted Content added
mNo edit summary
mNo edit summary
 
(7 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 =>
{
var original = document.onkeyup;
document.onkeyup = function(e)
{
original(e);
handle(e);
};
}
else
{
document.onkeyup = handle;
}
function handle(e)
{
if(e.ctrlKey && e.altKey && e.which == 82)
Line 34 ⟶ 19:
run();
}
});
function run()
Line 40 ⟶ 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 61 ⟶ 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 79 ⟶ 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 89 ⟶ 72:
txtarea.value = text;
{
return false;
}
});