Community Central
Register
Community Central
Forums: Index Help desk Automatic text edit on page load?
Fandom's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.
Archive
Note: This topic has been unedited for 5385 days. It is considered archived - the discussion is over. Information in this thread may be out of date. Do not add to unless it really needs a response.

If one wanted to configure some JavaScript so that it would always first check if there was a piece of code in the wiki source, and if it is not present, plug it in on edit, how would one do that? For instance, when someone goes to "action=edit", check if the text box has "fooBar, Quok.", and if it doesn't, add it to the end of the page. What would the JavaScript for this look like? (sorry, every time I try scripting, I phail...) TimerootTCE 09:50, 30 June 2009 (UTC)

As starting point:
if (wgAction == 'edit' || wgAction == 'submit') {
	$(appendWikiText);
}

function appendWikiText(){
	var tb = document.getElementById('wpTextbox1');
	var text = "fooBar, Quok.";
	if (tb && tb.value.indexOf(text) == -1) {
		tb.value += text;
	}
}
--Ciencia Al Poder (talk) -WikiDex 18:18, 30 June 2009 (UTC)