Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Galera,
essa semana eu fiz uma ferramenta pra detectar plugins no browser , como não tinha uma base legal usei scripts que encontrei na net , e fui ajuntando scripts e mais scripts .
so que não acho seguro esses scripts , o código e sujo e embaralho
abaixo tenho um script que detecta se tem alguns plugins e mais abaixo tenho uma função que detecta a versão do flash
gostaria de fazer uma tarefa conjunta com a comunidade e disponibilizar script mais sólidos e limpos
meu objetivo é :
se eu quero algo pra flash , tenho uma função somente pra flash e assim por diante
retirar os excessos de ifs
testar coisas por vez
dividir as tarefas em funções isoladas ( testaBrowser , detectaPlugin , detectaVersao )
/************************************************************************************/o script abaixo esta zuado , mais funciona , o objetivo e otimiza-lo de acordo com os tópicos acima*************************************************************************************/var resolucao = "";var agt = navigator.userAgent.toLowerCase();var ie = (agt.indexOf("msie") != -1);var ns = (navigator.appName.indexOf("Netscape") != -1);var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));var mac = (agt.indexOf("mac")!=-1); if (ie && win) { pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("AcroPDF.PDF.1","Acrobat Reader"); } if (ns || !win) { nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase(); pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader"); } function detectIE(ClassID,name) { result = false; document.write('<script LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; } function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; } if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1); function getFlashVersion() { var flashVersion = 0; var userAgent = navigator.userAgent.toLowerCase(); if (navigator && navigator.plugins != null && navigator.plugins.length > 0) { var flashPlugin = navigator.plugins["Shockwave Flash"]; if (typeof flashPlugin == "object") { for (var i = 9; i > 2; i--) { if (flashPlugin.description.indexOf(i + ".") != -1) { flashVersion = i; break; } } } } else if (window.ActiveXObject) { for (var i = 9; i > 2; i--) { try { var oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');"); if (oFlash) { flashVersion = i; break; } } catch(e) {} } } return flashVersion; }
-----------------------------------------------------------------------------------
Post Mesclado
-----------------------------------------------------------------------------------
Galera vo ja postando o que eu to fazendo , sintam-se para opinarem e modificarem o script e os comentários , acho que é bacana o script ser feito em lingua portuguesa(Brasil)
/****************************************************************************************************Biblioteca de teste de Pluginsautor : Comunidade JavaScriptdata : 21/09/2007linguagem : Português (Brasil)********************************************************************************************************//************************************************************************************A primeira função pega dados gerais do navegador e converte a string em caixa baixa**************************************************************************************/function dadosNavegador(){ agent = navigator.userAgent.toLowerCase(); return agent; }document.write(dadosNavegador());
Continuando
/**************************************************************************************************Biblioteca de teste de Pluginsautor : Comunidade JavaScriptdata : 21/09/2007linguagem : Português (Brasil)****************************************************************************************************//********************************************************************************A primeira função pega dados gerais do navegador e converte a string em caixa baixa************************************************************************************/function dadosNavegador(){ agent = navigator.userAgent.toLowerCase(); return agent; } function dadosNavegadorNetscape(){ nomeNavegador = navigator.appName.toLowerCase(); return nomeNavegador; } function dadosNavegadorNaoSei(){ win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1)); return win; } //no outro script tem esse teste mais ele nao e utilizadofunction dadosNavegadorMac(){ mac = (agt.indexOf("mac")!=-1); }// esses write e so pra testar , posteriormente serão retiradosdocument.write(dadosNavegadorNetscape());function navegadorTipo(){ if(dadosNavegador().indexOf("msie") != -1 ) return "msie"; if(dadosNavegadorNetscape().indexOf("Netscape") != -1 ) return "netscape"; if(dadosNavegadorNaoSei().indexOf("Netscape") != -1 ) return win; }
parte 3°
/****************************************************************************************************teste de Plugin Flashautor : Comunidade JavaScriptdata : 21/09/2007linguagem : Português (Brasil)********************************************************************************************************//************************************************************************************As funções abaixo coletam dados de navegadores**************************************************************************************/function dadosNavegador(){ agent = navigator.userAgent.toLowerCase(); return agent; } function dadosNavegadorNetscape(){ nomeNavegador = navigator.appName.toLowerCase(); return nomeNavegador; } function dadosNavegadorNaoSei(){ win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1)); return win; } //no outro script tem esse teste mais ele nao e utilizadofunction dadosNavegadorMac(){ mac = (agt.indexOf("mac")!=-1); }/**********************************************************************************************************função abaixo testa o tipo do Navegador************************************************************************************************************/function navegadorTipo(){ if(dadosNavegador().indexOf("msie") != -1 ) return "msie"; if(dadosNavegadorNetscape().indexOf("Netscape") != -1 ) return "netscape"; if(dadosNavegadorNaoSei().indexOf("Netscape") != -1 ) return "win";} /**********************************************************************************************************************função abaixo acha a versão do Flash , cheguei a conclusão que ele não precisa das funções acima ***********************************************************************************************************************/function getFlash() { var flashVersion = 0; var userAgent = navigator.userAgent.toLowerCase(); if (navigator && navigator.plugins != null && navigator.plugins.length > 0) { var flashPlugin = navigator.plugins["Shockwave Flash"]; if (typeof flashPlugin == "object") { for (var i = 9; i > 2; i--) { if (flashPlugin.description.indexOf(i + ".") != -1) { flashVersion = i; break; } } } } else if (window.ActiveXObject) { for (var i = 9; i > 2; i--) { try { var oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');"); if (oFlash) { flashVersion = i; break; } } catch(e) {} } } return flashVersion; }/***************************************************************************************************************função abaixo ve se tem plugin ou nao******************************************************************************************************************/function testaPluginFlash(){ if(getFlash()) return "OK"; else return "não tem plugin"; }Carregando comentários...