We heard you like RegEX

Home Forums General Chat We heard you like RegEX

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #3398
    Joaco
    Participant

    So I just made a little experiment with it.



    Untitled

    //found on google. modified by me to allow #, . and tag names
    function $() {
    var elements = new Array()
    for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i]
    if (typeof element == 'string')
    if(element.indexOf('#') == 0) {
    //ID
    element = document.getElementById(element.replace('#',''))
    } else if(element.indexOf('.') == 0) {
    //Class
    element = document.getElementsByClassName(element.replace('.',''))
    } else {
    //Tag Name
    element = document.getElementsByTagName(element)
    }
    if (arguments.length == 1)
    return element
    elements.push(element)
    }
    return elements
    }
    //regex fun!
    var _ = function(Queries) {
    Queries = Queries.split(/salsos/gi)
    for(x=0;x<Queries.length;x++) {
    query = Queries[x]
    var Element, Query, Action, Time, Event
    if(/^finds{1}(.+)s{1}ins{1}(.+)/i.test(query)) {
    } else if(/^gets{1}(.+)/i.test(query)) { //get #div
    Element = query.match(/^gets{1}(.+)/i)[1]
    return $(Element)
    } else if(/^hides{1}(.+)/i.test(query)) { // hide #div
    Element = query.match(/^hides{1}(.+)/i)[1]
    $(Element).style.display="none"
    } else if(/^moves{1}(.+)s{1}tos{1}(.+)/i.test(query)) { // move x
    Query = query.match(/^moves{1}(.+)s{1}tos{1}(.+)/i)
    Element = Query[1]
    var DestX = eval(Query[2].split(",")[0])
    var DestY = eval(Query[2].split(",")[1])
    if($(Element).style.position == '')
    $(Element).style.position = 'relative'
    $(Element).style.left=DestX
    $(Element).style.top=DestY
    } else if(/^dos"(.+)"s{1}ins(.+)s(ms|s)/i.test(query)) {
    Query=query.match(/^dos"(.+)"s{1}ins(.+)s(ms|sec)/i)
    Action = Query[1]
    Time = (Query[3]=="ms")? parseInt(Query[2]):parseInt(Query[2])*1000
    setTimeout("_('"+Action+"')",Time)
    } else if(/^dos"(.+)"s{1}everys(.+)s(ms|s)/i.test(query)) {
    Query=query.match(/^dos"(.+)"s{1}everys(.+)s(ms|sec)/i)
    Action = Query[1]
    Time = (Query[3]=="ms")? parseInt(Query[2]):parseInt(Query[2])*1000
    setInterval("_('"+Action+"')",Time)
    } else if(/^changes(.+)'sscontentsstos'(.+)'/i.test(query)) {
    Query = query.match(/^changes(.+)'sscontentsstos'(.+)'/i)
    Element = $(Query[1])
    $(Element).innerHTML=Query[2]
    } else if(/^whens(.+)sons(.+)sdos(.+)/i.test(query)) {
    Query = query.match(/^whens(.+)sons(.+)sdos(.+)/i)
    Event = Query[1]
    Element = Query[2]
    Action = Query[3]
    $(Element).addEventListener(Event,function(){eval(Action)},false)
    }
    }
    return 0
    }
    document.ready = function(callback){window.addEventListener('load',callback,false)}
    document.ready(function(){
    var console = {
    Log : function() {
    for(var x=0;x<arguments.length;x++) {
    $('#console').innerHTML+=arguments[x]
    }
    return 0
    }
    }
    console.Log("_('get #america').innerHTML:"+_('get #america').innerHTML)
    console.Log("
    ")
    _('do "move #america to 100,100" in 1 sec also do "move #america to 0,0" every 3 sec ALSO change #america's contents to 'cant touch this' also when mouseover on #america do _("move #america to "+Math.floor(Math.random()*500)+","+Math.floor(Math.random()*500))')
    })



    I like the part where everything fails and you see this text. Because you shouldn't see this at all.



    The last one, when * on * do *, doesn’t work. I’ll fix it later.

    #20324
    DarkDragoon
    Participant

    So I heard you don’t like telling us what each part will do. ;-;
    Too lazy to go through all of that code, ya’ know?

    #20325
    David
    Participant

    It obviously comments on how Americaa has assholes and stuffs.

    trollface.jpg

    #20326
    Joaco
    Participant

    The other day I was cloning jquery for learning purposes, so I decided to do another type of library. A more “high level” language-based library. You could give it instructions like “hide ELEMENT”, “move element to dis position”, “do this, do that,” etc.
    Example: “get ELEMENT” would return the DOMElement. To differentiate between tags, classes and elements you should precede it with a #, . and nothing, for id, class and tag name, respectively.
    “hide ELEMENT” would change element(s)’s display to :none
    “move ELEMENT to left,top” checks if it already has the type of position defined, (relative, absolute, fixed), if not, it sets it to relative (which is the default..?) and moves the element to the desired position.
    “do “action” in x sec|ms” will do the action in x sec(or ms). The action can’t be javascript, it is parsed by _( ).
    “change element’s contents to ‘newContent'” change element’s contents to the specified new content.
    “when EVENT on ELEMENT do STUFF” pretty much. Adds an event listener. doesn’t work yet.

    Also, instead of doing this:
    _(“move #header to 20,10”)
    _(“change #header’s contents to ‘‘”)
    you can do this in one call:
    _(” move #header to 20,10 also change #header’s contents to ‘‘”)

    and I will edit the contents now 😛

    #20327
    Joaco
    Participant

    Improved source code.
    “when EVENT on ELEMENT do STUFF” works now.
    Works like this:
    “when mouseover on #america do javascript”
    javascript, for example, can be: alert(‘hello world’)

    added ‘do “action” every x sec|ms’
    syntax is the same as ‘do “action” in x sec|ms’, instead of a timeout it sets an interval and repeats the action every x period of time..

    #20332
    Dustin
    Participant

    if(/^finds{1}(.+)s{1}ins{1}(.+)/i.test(query)) { //find assholes in america returns true. 😛

    Jerk. I loved you.

    #20336
    Joaco
    Participant

    oh lol I thought I removed that 😛
    it’s like when you’re writing a story and you just write dumb shit just to look how it would look like and you forget to remove it.
    anyway, I didn’t mean everyone is an asshole
    and you can find assholes in every country
    (except the netherlands)

    i love you 🙁

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.