Page 1 of 1

OS Detection

Posted: 10 Jun 2009 08:07
by nikola23
I added some code to the script on the front side that detects your OS.. currently it only detects that your running os x. I added a little code to have it check which version you're running so that when 1.0.0 comes out everyone running 10.4 wont be downloading an incompatible version... I could only test it on os x 10.4, 10.5 and windows vista though so someone might want to double check the logic.

Code: Select all

<script type="text/javascript"><!-- if ( navigator.platform.indexOf("Win32") != -1 ) { document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9/win32/vlc-0.9.9-win32.exe">Download Now</a> for Windows (16 MB)</p>'); } else if( navigator.platform.indexOf("BeOS") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-beos.html">Download Now</a> for BeOS</p>'); } else if( navigator.platform.indexOf("Linux") != -1 ) { if( navigator.userAgent.indexOf("Ubuntu") != -1 || navigator.userAgent.indexOf("ubuntu") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-ubuntu.html">Download Now</a> for Ubuntu Linux</p>'); } else if( navigator.userAgent.indexOf("Fedora") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-fedora.html">Download Now</a> for Fedora Linux</p>');} else if( navigator.userAgent.indexOf("SUSE") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-suse.html">Download Now</a> for Suse Linux</p>'); } else if( navigator.userAgent.indexOf("Debian") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-debian.html">Download Now</a> for Debian GNU/Linux</p>'); } else if( navigator.userAgent.indexOf("Mandriva") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-mandriva.html">Download Now</a> for Mandriva Linux</p>'); } else if( navigator.userAgent.indexOf("Red Hat") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-redhat.html">Download Now</a> for RedHat Linux</p>'); } else if( navigator.userAgent.indexOf("gentoo") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-gentoo.html">Download Now</a> for Gentoo Linux</p>'); } else { document.writeln( '<p><a class="download" href="/vlc/">Download Now</a> for Linux and other OSes</p>'); } } else if( navigator.userAgent.indexOf("freebsd") != -1 || navigator.userAgent.indexOf("FreeBSD") != -1 ) { document.writeln( '<p><a class="download" href="/vlc/download-freebsd.html">Download Now</a> for FreeBSD</p>'); } else if( navigator.userAgent.indexOf("Mac OS X") != -1 ||navigator.userAgent.indexOf("MSIE 5.2") != -1 ||( navigator.userAgent.indexOf("Mac") && navigator.userAgent.indexOf("Opera") ) ) { if ( navigator.oscpu.indexOf("10.1") != -1 ) { document.writeln( '<p><a class="download" href="http://download.videolan.org/pub/videolan/vlc/0.7.0/macosx/vlc-0.7.0.dmg">Download Now</a> for Mac OS X 10.1 (7.3 MB)</p>');} else if ( navigator.oscpu.indexOf("10.2") != -1 ) { document.writeln( '<p><a class="download" href="http://download.videolan.org/pub/videolan/vlc/0.8.4a/macosx/vlc-0.8.4a.dmg">Download Now</a> for Mac OS X 10.2 (13 MB)</p>');} else if ( navigator.oscpu.indexOf("10.3") != -1 ) { document.writeln( '<p><a class="download" href="http://download.videolan.org/pub/videolan/vlc/0.8.6i/macosx/vlc-0.8.6i-powerpc.dmg">Download Now</a> for Mac OS X 10.3 (14.2 MB)</p>');} else if ( navigator.oscpu.indexOf("10.4") != -1 ) { if( navigator.platform.indexOf("MacPPC") != -1|| navigator.platform.indexOf("PowerPC") != -1 ) { document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-powerpc.dmg">Download Now</a> for Mac OS X PowerPC (19 MB)</p>'); } else if( navigator.platform.indexOf("Intel") != -1 ) { document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-intel.dmg">Download Now</a> for Mac OS X Intel (19 MB)</p>');} else { document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-powerpc.dmg">Download Now</a> for Mac OS X PowerPC (19 MB)</p>');document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-intel.dmg">Download Now</a> for Mac OS X Intel (19 MB)</p>'); } } else if ( navigator.oscpu.indexOf("10.5") != -1 ) { if( navigator.platform.indexOf("MacPPC") != -1|| navigator.platform.indexOf("PowerPC") != -1 ) { document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-powerpc.dmg">Download Now</a> for Mac OS X PowerPC (19 MB)</p>'); } else if( navigator.platform.indexOf("Intel") != -1 ) { document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-intel.dmg">Download Now</a> for Mac OS X Intel (19 MB)</p>');} else { document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-powerpc.dmg">Download Now</a> for Mac OS X PowerPC (19 MB)</p>');document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-intel.dmg">Download Now</a> for Mac OS X Intel (19 MB)</p>'); } } } else if( navigator.platform.indexOf("Mac") != -1 ) { document.writeln( "<p>Haha Mac OS 9 is dead! (if you\\\'re not using Mac OS 9 ... please write us a mail so we can fix this OS detection script)</p>'" ); } else { document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9/win32/vlc-0.9.9-win32.exe">Download Now</a> for Windows (16 MB)</p>');document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-powerpc.dmg">Download Now</a> for Mac OS X PowerPC (19 MB)</p>');document.writeln( '<p><a class="download" href="/mirror-geo.php?file=vlc/0.9.9a/macosx/vlc-0.9.9a-intel.dmg">Download Now</a> for Mac OS X Intel (19 MB)</p>'); } --></script>

Re: OS Detection

Posted: 10 Jun 2009 13:02
by Jean-Baptiste Kempf
Can you send a patch against the website code?

Re: OS Detection

Posted: 10 Jun 2009 18:34
by nikola23
http://pastebin.com/m643e4204 That's just against the original script itself... hopefully it's more readable because its all tabbed out and such this time.

Re: OS Detection

Posted: 11 Jun 2009 21:41
by nikola23
Is that more along the lines of what you were asking for?

Re: OS Detection

Posted: 12 Jun 2009 00:06
by Jean-Baptiste Kempf
No, I have no time for this.

Please patch source code of website:
http://svn.videolan.org/listing.php?rep ... deolan.org_

Re: OS Detection

Posted: 12 Jun 2009 02:59
by Arite
@nikola23: This is probably the file you want to patch (in addition to index.php perhaps):
http://svn.videolan.org/filedetails.php ... ecific.php

Arite.