User blog:Penguin-Pal/Self-destructive code

Hi there,

If you're looking for a way of creating a script that not only uses conditions to decide whether or not to apply it but are also looking for a method of completely removing it from a certain script page, maybe you'd find this useful.

Basically the syntax of this code isn't too long. It's made of: When and if the condition is true, it then would use $.getJSON to get the content of the JS page on which the code is found, remove the requested "anchor" from it- containing the code and the if condition- and then use MediaWiki's API to save the changes.
 * A function to begine with, to make it work.
 * Wrapping "tags" to be used as some sort of anchors, to determine what part of the code to remove.
 * A certain code to do, placed between the wrapping tags.
 * A condition, also trapped between the "anchors". If it's true then trigger the self-destruction code.

Here's an example for a syntax for the basic code: Then all there's left is to create the "anchor". For this example, the anchor should look like this: On the example above: On this example, 1 < 2 will always be true, but using another condition, say, So suppose you put it in MediaWiki:Wikia.js:
 * Line 1 is the anchor's opening. Line 8 is its closing.
 * foo123 is the name of the anchor that is used.
 * User:Penguin-Pal/wikia.js is just my personal JS page, but of ourse any JS page can be used.
 * Line 3 contains the actual wanted code (on this example, make text on page red).
 * Lines 5-7 contain the condition.

Before: After: There's no reason why this shouldn't work in applying changes on multiple pages. I don't really see a reason why to use this sort of script rather than using only if conditions from the first place, but maybe some of you could find a possible usage for this somewhere.

Penguin-Pal  (talk)  07:29, November 27, 2013 (UTC)