Home › Forums › General Chat › We heard you like RegEX
- This topic has 6 replies, 4 voices, and was last updated 14 years, 7 months ago by
Joaco.
-
AuthorPosts
-
23 July 2010 at 05:39 #3398
Joaco
ParticipantSo 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.
23 July 2010 at 06:11 #20324DarkDragoon
ParticipantSo I heard you don’t like telling us what each part will do. ;-;
Too lazy to go through all of that code, ya’ know?23 July 2010 at 13:36 #20325David
ParticipantIt obviously comments on how Americaa has assholes and stuffs.
trollface.jpg
23 July 2010 at 18:18 #20326Joaco
ParticipantThe 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 😛
23 July 2010 at 19:51 #20327Joaco
ParticipantImproved 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..23 July 2010 at 23:15 #20332Dustin
Participantif(/^finds{1}(.+)s{1}ins{1}(.+)/i.test(query)) { //find assholes in america returns true. 😛
Jerk. I loved you.
24 July 2010 at 04:11 #20336Joaco
Participantoh 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 🙁
-
AuthorPosts
- You must be logged in to reply to this topic.