sofiaviolet: congratulations! you win the internet (you win the internet)
[personal profile] sofiaviolet
Notes: This will require creating/editing a layer (theme or layout). The directions below are intended for use on Dreamwidth, but this kind of thing does also work on LiveJournal, and possibly on clones.

To see random text in action, view my journal in my style. The text appears in the left sidebar, beneath the pink rose. Refresh the page a couple of times to see the text change. If you'd like to view the code for my layout, here's the raw code and with syntax highlighted.

I am willing to help people troubleshoot their implementations of this code, but my time is not infinite and my skills are limited. But feel free to ask, and I'll do what I can.


1. Get ready to edit a layer.

If you are already using a custom theme or layout layer, then click the Edit button.

If not, then create a layout-specific theme layer for your current layout.

2. Find the function called Page::print().

If you don't have that function in the layer you're currently working on, get the code for it from the appropriate public layer and paste that into your layer.

3. You will be entering the first part of the code on a new line right after function Page::print() {.

var string[] freetext;
$freetext[0] = "f00";
$freetext[1] = "bar";
$freetext[2] = "baz";
$freetext[3] = "quux";
var int randomtext;
$randomtext = rand(0, ((size $freetext) - 1));

4. Replace the words inside the double quotes with whatever text you want (including HTML tags - just be sure to escape any internal double quotes, ie <img src=\"http://site.com/pic.jpg\">).

You can add more $freetext[n] items - just be sure to number them consecutively, put double quotes around each item, and end each line with a semicolon.

5. Within the Page::print() function, find the place where you want your text to appear and paste the following on a new line:

println "$freetext[$randomtext]";

Make sure not to damage any of the surrounding code.

6. Hit the Save & Compile button. If it throws an error, then something is in the wrong place, or you've made a typo. Check the box with the error message for more details.

If it compiles properly, then open up your journal and make sure the text appears the way you want it to.



The concepts used for this code can also be used to randomize header graphics and background images.

Date: 2009-05-08 07:46 (UTC)
tenshinochouwa: smecker from boondock: "and there was a firefight!" (Default)
From: [personal profile] tenshinochouwa
Approximately an hour later, I'm done. I might have made it too hard on myself, but I had a great idea and it was totally worth it. Thanks so much, this was fun! (Hi you don't know me but I just subscribed to you)

Date: 2009-05-08 17:39 (UTC)
tenshinochouwa: smecker from boondock: "and there was a firefight!" (Default)
From: [personal profile] tenshinochouwa
Thanks, coding it was a bit of a hassle but I love the result.

April 2014

S M T W T F S
  123 45
6789101112
13141516171819
20212223242526
27282930   

Most Popular Tags

txtbx

Not nice, but friendly.