User JS: text/x-plainscript
Ok, so this is totally useless. I don’t need it. I most certainly don’t recommend that anyone actually uses this for anything, but I’m doing it, simply because I got excited about Advanced User JavaScript: event handling and already wrote something about it in my linkblog.
Hallvord wrote a few words about the BeforeScript event, adding something that caught my interest:
The event handler function receives an object with information about the event. The function can check various properties of this object to get information about the event. The element property tells you what element the event is happening to, and the event property is the event object that will be passed to the page’s script.
Hallvord’s quote provided me with a hint: The element refered to, acts mostly like any other DOM node. This means that you can check which properties are attached to the <script> element, and act on them, by using DOM methods such as hasAttribute and getAttribute. Meet text/x-plainscript.
- First, download and append plainscript.js to your user js file.
- Next, visit the plainscript test document
- Finally, view the source of the plainscript test document.
What is going on?
“Plainscript” is the world’s most primitive, and probably also most useless “scripting language”: It takes a set of statements, and parses them one by one, and creates output according to this.
Each statement is separated by . (A dot followed by two spaces), and the plainscript has to end with that sequence. The statements you can use are:
Setpropertyvalue. This statement allows you to set a document property. The two supported properties arecolorandbackground, andvalueis any valid CSS color value.Addtypecontent. This statement allows you to add content to your document.typecan take two values, eithertextorparagraph.textwill addcontentto the last paragraph, whileparagraphwill addcontentas a new paragraph.Waitdurationtype. This statement allows you to pause script output for a given period, either in seconds or minutes.Wait 2 seconds.would pause script output for two seconds, whileWait 1 minute.would pause for one minute.
An example “script” could be:
Add paragraph Demo text here. Wait 1 second. Set color #333.
Note that I say “script”, because what you saw is all that it does. It is not Turing-complete, and you couldn’t write a proper 99 bottles of beer in this, even if you tried.
Also note that I don’t condone creating and deploying custom script languages on the web. It breaks interoperability. Badly. It breaks the web.
Still, being able to do stuff like this is just cool, and I’m sure someone will find a userful application for this, one that doesn’t break the web, but rather mends it. In the meantime, I am going to bow before my new Opera overlords.
Comments
Comment from Peter Karlsson on 2005-03-23 20:54
I’m just waiting for someone to implement a full VBScript interpreter in JavaScript, that can be hooked up here so that we can all enjoy the security holes of our favourite competitor… :-)
Comment from Aaron on 2005-03-23 23:17
Couldn’t you use this as a cross-domain XMLHttp? Script elements aren’t limited by same origin policy in most browsers. Set it to a URL and parse the result. Bam!
Comment from Hallvord R. M. Steen on 2005-03-24 01:12
LOL! Perhaps my next localhost-only utility page will be written in text/x-plainscript ;)
Aaron: dynamically generated SCRIPT element can indeed be used as a sort of cross-domain XMLHttp (with or without User JS).
This discussion has been closed. No further comments may be added.