User:FT2/scripts/previewrefs.js
Appearance
< User:FT2
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:FT2/scripts/previewrefs. |
/*=================================================================================================
[[Benutzer:ParaDox/VirtualReferences.js]] V0.02b
Firefox 2.0.0.12 tested
[[de:Benutzer:ParaDox/VirtualReferences.js]]
More info:
[[de:Benutzer_Diskussion:ParaDox/VirtualReferences.js]]
By [[Benutzer:ParaDox]]
[[de:Benutzer:ParaDox]]
---------------------------------------------------------------------------------------------------
Translation note:
"Vorschau zeigen" = "Show preview"
"Nur die folgenden 4 Zeilen in die eigene monobook.js einfügen:" =
"This is what you put in monobook.js to enable the script"
In English Wikipedia, add this to your monobook.js to use the ENWP version of the script:
importScript('User:FT2/scripts/previewrefs.js');
=================================================================================================*/
var VRefStr0 = '<!-- Start of Preview References -->';
var VRefStr = '\n' + VRefStr0 + '\n'
+ '<div id="PreviewReferences" style="border:1px solid red; background-color:#FFEEEE;padding:2px 5px 0 5px;">\n'
+ '<tt>Preview <nowiki><references/></nowiki></tt> '
+ '(based on [[:de:Benutzer:ParaDox/VirtualReferences.js|VirtualReferences.js]] by [[:de:Benutzer:ParaDox|:de:User:ParaDox]]):\n'
+ '<references/></div>\n';
var VRefBox, VRefLower, VRefOL;
var VRefPos1, VRefPos2;
window.addEventListener('click', function(event) {
if ( (event.target.value == 'Show preview') && ( event.target.id == 'wpPreview') ) {
if ( document.getElementById('wpTextbox1') ) {
VRefBox = document.getElementById('wpTextbox1');
VRefLower = VRefBox.value.toLowerCase();
VRefPos1 = VRefLower.indexOf('<ref>');
VRefPos2 = VRefLower.indexOf('<ref ');
if ( (VRefPos1 >= 0) || (VRefPos2 >= 0) ) {
if ( ( VRefLower.indexOf('<references/>') < 0 )
&& ( VRefLower.indexOf('<references />') < 0 )
)
{
VRefBox.value += VRefStr;
}
}
}
}
}, true);
window.addEventListener('load', function(event) {
if ( document.getElementById('wpTextbox1') ) {
VRefBox = document.getElementById('wpTextbox1');
VRefPos1 = VRefBox.value.indexOf(VRefStr0) - 1;
VRefPos2 = VRefBox.value.indexOf("var VRefStr0 = '" + VRefStr0);
/* Debug code and a bugfix workaround hack
alert("Page URL (NB using 2nd method): " + window.location + "\nand: " + self.location.href);
alert("Regex trial: " + self.location.href.match("title=.+\.js&action=(edit|submit)") );
alert("Full string search result: " + VRefBox.value.indexOf(VRefStr) );
alert("Start token searchresult: " + VRefBox.value.indexOf(VRefStr0) );
alert("Full text box contents on loading:\n\n>" + VRefBox.value + '<' );
if ( VRefBox.value.indexOf(VRefStr) >= 0 ) {
alert("Proposed writeback based on full string search:\n\n>" + VRefBox.value.substr(0, VRefBox.value.indexOf(VRefStr)) + "<" );
}
if ( VRefBox.value.indexOf(VRefStr0) >= 0 ) {
alert("Proposed writeback based on start token search:\n\n>" + VRefBox.value.substr(0, VRefBox.value.indexOf(VRefStr0)) + "<" );
}
// End of debug code */
if ( VRefPos1 >= 0 && VRefPos2 < 0 ) {
VRefBox.value = VRefBox.value.substr(0, VRefPos1);
if ( document.getElementById('PreviewReferences') ) {
VRefOL = document.getElementById('PreviewReferences').getElementsByTagName('OL');
if ( VRefOL.length < 1 ) {
document.getElementById('PreviewReferences').style.display = 'none';
} else {
if ( VRefOL[0].className == 'references' ) {
document.getElementById('PreviewReferences').style.backgroundColor = '#EEFFEE'
}
}
}
}
}
}, false);