User:FT2/scripts/previewrefs.js

/*================================================================================================= 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 = ''; var VRefStr = '\n' + VRefStr0 + '\n' + ' \n' + 'Preview  ' + '(based on VirtualReferences.js by de:User:ParaDox):\n' + ' \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(' ');            VRefPos2  = VRefLower.indexOf('= 0) || (VRefPos2 >= 0) ) {                if ( ( VRefLower.indexOf(' ')  < 0 ) && ( VRefLower.indexOf(' ') < 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);