arantius
asked on
Byte saving, string manipulation
I'm 65 bytes off of the 508 byte limit for a bookmarklet to work in IE. I'm looking to extract the TLD of the current page (whatever.com, whatever.org, ...). I currently have:
var r="://([^/]+)",l=document. location.h ref.match( r)[1].spli t(".");l=l [l.length- 2]+"."+l[l .length-1] ;
This is one of the bloated parts of my script. Can anyone save me a few bytes?
var r="://([^/]+)",l=document.
This is one of the bloated parts of my script. Can anyone save me a few bytes?
try swapping document.location with top.location
l=(''+top.location).match( /[^/]+$/)[ 0]
ASKER
@gwyn
That doesn't execute in firefox, and in IE it only returns the filename
@Virus
Yeah, that does save 5 bytes =)
That doesn't execute in firefox, and in IE it only returns the filename
@Virus
Yeah, that does save 5 bytes =)
what are you trying to extract from the location string? (it looked the file name to me)
would it be 'experts-exchange.com' from say
https://www.experts-exchange.com/questions/21189116/Byte-saving-string-manipulation.html
https://www.experts-exchange.com/questions/21189116/Byte-saving-string-manipulation.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes, exactly. i want the "domain name" with any sub domains stripped.
ebay.com for: www.ebay.com, signin.ebay.com, scgi.ebay.com, ebay.com
Etc.
ebay.com for: www.ebay.com, signin.ebay.com, scgi.ebay.com, ebay.com
Etc.
in which case it is the above eg
javascript:function x(){alert(l=(''+location.h ost).match (/[^.]*\.[ ^.]*$/)[0] )}x()
javascript:function x(){alert(l=(''+location.h
ASKER
Beautiful Gwyn =) Don't think it can get much smaller than that !
and what's about port? e.g. :8080
Thanks for the points
Above submitted from Netscape using
javascript:function x(){document.getElementsBy TagName('t extarea')[ 0].value+= 'Thanks for the points';document.answerQue stionForm. submit()}x ()
javascript:function x(){document.getElementsBy
to answer Devic (port number was not in question code)
l=(''+location.hostname).m atch(/[^.] *\.[^.]*$/ )[0]
eg
javascript:function x(){alert(l=(''+location.h ostname).m atch(/[^.] *\.[^.]*$/ )[0])}x()
l=(''+location.hostname).m
eg
javascript:function x(){alert(l=(''+location.h
Gwyn, I use always oldlook and adress is :
http://oldlook.experts-exchange.com/questions/21189116/Byte-saving-string-manipulation.html
now it works correct ;)
http://oldlook.experts-exchange.com/questions/21189116/Byte-saving-string-manipulation.html
now it works correct ;)
:-)
this also seems to work with the hostname
l=location.host.match(/[^. ]*\.[^.]*$ /)[0]
javascript:function x(){alert(l=location.host. match(/[^. ]*\.[^.]*$ /)[0])}x()
l=location.host.match(/[^.
javascript:function x(){alert(l=location.host.