Advertisement
Bommel

Babelfish Firefox addon/extension 1.97/1.54 working dict.leo

Apr 7th, 2013
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var bfplugin = {//never change this line
  2.  
  3.   //BabelFish compatibility:
  4.   minBFVersion: '1.94',
  5.   //Your plugin edit version:
  6.   pluginVersion: '1.54',
  7.   //Author:
  8.   pluginAuthor: 'NettiCat, modified by Arkitk',
  9.  
  10.   //Description:
  11.   //------------
  12.   //Babelfish is a Firefox addon/extension working dict.leo.org and google
  13.   //the original addon and website of NettiCat is not longer available. The latest version was 1.97.
  14.   //It can be found using a search enginge. You still need a working definition/plugin-file like
  15.   //this one.
  16.   //Since the translation services were not working with the old pluginVersions, I tried
  17.   //to modify the definitions. Google is available with the most probable translation. leo.org as
  18.   //html-style and pure text of the first translation occurance. All other services were removed/are
  19.   //not available anymore. The translation order cannot be changed easily in the
  20.   //defintion/plugin-file. It is the responsibility of the addon.
  21.   //It seems that service3 is executed 2 times by the addon. Dont know why. Therefore problems
  22.   //of the order/priority of the translation service are likely.
  23.   //It is possible to show more output of google-translation by changing this definition.
  24.   //I give no support, because i am a noob programming with java script and addons. For new Verions
  25.   //just search, maybe you are lucky ;) <
  26.  
  27.   //Display name of your service:
  28.   service1Name: 'Google',
  29.   service2Name: 'LeoDic_puretext',
  30.   service3Name: 'LeoDic',
  31.   detectionName: 'Google',
  32.    
  33.  
  34.   //URL to get the text translation (enclose in outer single '' AND inner double ""):
  35.   //placeholder for the text to translate is %s
  36.   //placeholder for source language code is %from
  37.   //placeholder for target language code is %to
  38.   service1URL: '"http://translate.google.de/translate_a/t?client=t&text=%s&hl=en&sl=auto&tl=%to&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=%to&sc=1"',
  39.   service2URL: '"http://dict.leo.org/%from%to/?search=%s&searchLoc=0"',
  40.   service3URL: '"http://dict.leo.org/%from%to/?search=%s&searchLoc=0"',
  41.  
  42.   // alternativ
  43.   //'"http://dict.leo.org/?lp=%from%to&lang=en&relink=off&search=%s"',
  44.   //'"http://dict.leo.org/%from%to?lp=%from%to&lang=en&relink=off&search=%s"',
  45.   //'"http://dict.leo.org/%from%to/?search=%s"';
  46.   //http://translate.google.de/translate_a/t?client=t&text=%s&hl=en&sl=auto&tl=%to&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=%to&sc=1
  47.   //service1URL: '"http://translate.google.de/translate_a/t?client=t&text=fenetre&hl=en&sl=auto&tl=de&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=de&sc=1"',
  48.   //service1URL: '"http://translate.google.de/?hl=en&tab=wT#auto/%to/%s"',
  49.  
  50.   //URL to translate a whole page (enclose in outer single '' AND inner double ""):
  51.   //placeholder for the site to translate is %url
  52.   //placeholder for source language code is %from
  53.   //placeholder for target language code is %to
  54.   //placeholder for browser language code is %nl
  55.   service1SiteURL: '"http://translate.google.com/translate?hl=%nl&langpair=%from|%to&u=%url"',
  56.   service2SiteURL: '"http://translate.google.com/translate?hl=%nl&langpair=%from|%to&u=%url"',
  57.    
  58.  
  59.   //URL to detect a language (enclose in outer single '' AND inner double ""):
  60.   //placeholder for the text is %s
  61.   detectionURL: '"http://translate.google.de/translate_a/t?client=t&text=%s&hl=en&sl=auto&tl=en&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=en&sc=1"',
  62.   //Maximum text-length accepted by service, otherwise text is splitted:
  63.   //service2MaxLength: 1000,
  64.   //service5MaxLength: 300,
  65.  
  66.  
  67.   //Whole page translation supports translation of secure sites (HTTPS):
  68.   service1HTTPSSupport: 0,
  69.   service2HTTPSSupport: 0,
  70.    
  71.  
  72.   //Whole page translation cookie requirement (0=no, 1=yes, 2=if enabled only):
  73.   service1CookieRequirement: 0,
  74.   service2CookieRequirement: 0,
  75.    
  76.  
  77.   //Post methods needed
  78.   //service4PostParams: '"go=Search&lan1=%from&lan2=%to&word=%s"',
  79.    
  80.  
  81.   //Language codes used in the service URL (with %from or %to):
  82.   //Remove languages not supported by your service
  83.   //Change the short language codes to those used by your service
  84.   service1LanguageCodes : {
  85.     'auto' : '',
  86.     'AFRIKAANS' : 'af',
  87.     'ALBANIAN' : 'sq',
  88.     'AMHARIC' : 'am',
  89.     'ARABIC' : 'ar',
  90.     'ARMENIAN' : 'hy',
  91.     'AZERBAIJANI' : 'az',
  92.     'BASQUE' : 'eu',
  93.     'BELARUSIAN' : 'be',
  94.     'BENGALI' : 'bn',
  95.     'BIHARI' : 'bh',
  96.     'BULGARIAN' : 'bg',
  97.     'BURMESE' : 'my',
  98.     'CATALAN' : 'ca',
  99.     'CHEROKEE' : 'chr',
  100.     'CHINESE' : 'zh',
  101.     'CHINESE[S]' : 'zh-CN',
  102.     'CHINESE[T]' : 'zh-TW',
  103.     'CROATIAN' : 'hr',
  104.     'CZECH' : 'cs',
  105.     'DANISH' : 'da',
  106.     'DHIVEHI' : 'dv',
  107.     'DUTCH': 'nl',
  108.     'English' : 'en',
  109.     'ESPERANTO' : 'eo',
  110.     'ESTONIAN' : 'et',
  111.     'FILIPINO' : 'tl',
  112.     'FINNISH' : 'fi',
  113.     'French' : 'fr',
  114.     'GALICIAN' : 'gl',
  115.     'GEORGIAN' : 'ka',
  116.     'German' : 'de',
  117.     'GREEK' : 'el',
  118.     'GUARANI' : 'gn',
  119.     'GUJARATI' : 'gu',
  120.     'HEBREW' : 'iw',
  121.     'HINDI' : 'hi',
  122.     'HUNGARIAN' : 'hu',
  123.     'ICELANDIC' : 'is',
  124.     'INDONESIAN' : 'id',
  125.     'INUKTITUT' : 'iu',
  126.     'ITALIAN' : 'it',
  127.     'JAPANESE' : 'ja',
  128.     'KANNADA' : 'kn',
  129.     'KAZAKH' : 'kk',
  130.     'KHMER' : 'km',
  131.     'KOREAN' : 'ko',
  132.     'KURDISH': 'ku',
  133.     'KYRGYZ': 'ky',
  134.     'LAOTHIAN': 'lo',
  135.     'LATVIAN' : 'lv',
  136.     'LITHUANIAN' : 'lt',
  137.     'MACEDONIAN' : 'mk',
  138.     'MALAY' : 'ms',
  139.     'MALAYALAM' : 'ml',
  140.     'MALTESE' : 'mt',
  141.     'MARATHI' : 'mr',
  142.     'MONGOLIAN' : 'mn',
  143.     'NEPALI' : 'ne',
  144.     'NORWEGIAN' : 'no',
  145.     'ORIYA' : 'or',
  146.     'PASHTO' : 'ps',
  147.     'PERSIAN' : 'fa',
  148.     'POLISH' : 'pl',
  149.     'PORTUGUESE' : 'pt',
  150.     'PUNJABI' : 'pa',
  151.     'ROMANIAN' : 'ro',
  152.     'RUSSIAN' : 'ru',
  153.     'SANSKRIT' : 'sa',
  154.     'SERBIAN' : 'sr',
  155.     'SINDHI' : 'sd',
  156.     'SINHALESE' : 'si',
  157.     'SLOVAK' : 'sk',
  158.     'SLOVENIAN' : 'sl',
  159.     'SPANISH' : 'es',
  160.     'SWAHILI' : 'sw',
  161.     'SWEDISH' : 'sv',
  162.     'TAJIK' : 'tg',
  163.     'TAMIL' : 'ta',
  164.     'TAGALOG' : 'tl',
  165.     'TELUGU' : 'te',
  166.     'THAI' : 'th',
  167.     'TIBETAN' : 'bo',
  168.     'TURKISH' : 'tr',
  169.     'UKRAINIAN' : 'uk',
  170.     'URDU' : 'ur',
  171.     'UZBEK' : 'uz',
  172.     'UIGHUR' : 'ug',
  173.     'VIETNAMESE' : 'vi',
  174.     'UNKNOWN' : ''
  175.   },
  176.    
  177.   service2LanguageCodes : {
  178.    'Chinese' : 'ch',
  179.    'English' : 'en',
  180.    'French' : 'fr',
  181.    'German' : 'de',
  182.    'Italian' : 'it',
  183.    'Spanish' : 'es',
  184.   },
  185.  
  186.   service3LanguageCodes : {
  187.    'Chinese' : 'ch',
  188.    'English' : 'en',
  189.    'French' : 'fr',
  190.    'German' : 'de',
  191.    'Italian' : 'it',
  192.    'Spanish' : 'es',
  193.   },
  194.    
  195.   //Language codes used by language detection:
  196.   //Change the short language codes on the right to those sent by your language detection service
  197.   detectionLanguageCodes : {
  198.     'AFRIKAANS' : 'af',
  199.     'ALBANIAN' : 'sq',
  200.     'AMHARIC' : 'am',
  201.     'ARABIC' : 'ar',
  202.     'ARMENIAN' : 'hy',
  203.     'AZERBAIJANI' : 'az',
  204.     'BASQUE' : 'eu',
  205.     'BELARUSIAN' : 'be',
  206.     'BENGALI' : 'bn',
  207.     'BIHARI' : 'bh',
  208.     'BULGARIAN' : 'bg',
  209.     'BURMESE' : 'my',
  210.     'CATALAN' : 'ca',
  211.     'CHEROKEE' : 'chr',
  212.     'CHINESE' : 'zh',
  213.     'CHINESE[S]' : 'zh-CN',
  214.     'CHINESE[T]' : 'zh-TW',
  215.     'CROATIAN' : 'hr',
  216.     'CZECH' : 'cs',
  217.     'DANISH' : 'da',
  218.     'DHIVEHI' : 'dv',
  219.     'DUTCH': 'nl',
  220.     'English' : 'en',
  221.     'ESPERANTO' : 'eo',
  222.     'ESTONIAN' : 'et',
  223.     'FILIPINO' : 'tl',
  224.     'FINNISH' : 'fi',
  225.     'French' : 'fr',
  226.     'GALICIAN' : 'gl',
  227.     'GEORGIAN' : 'ka',
  228.     'German' : 'de',
  229.     'GREEK' : 'el',
  230.     'GUARANI' : 'gn',
  231.     'GUJARATI' : 'gu',
  232.     'HEBREW' : 'iw',
  233.     'HINDI' : 'hi',
  234.     'HUNGARIAN' : 'hu',
  235.     'ICELANDIC' : 'is',
  236.     'INDONESIAN' : 'id',
  237.     'INUKTITUT' : 'iu',
  238.     'ITALIAN' : 'it',
  239.     'JAPANESE' : 'ja',
  240.     'KANNADA' : 'kn',
  241.     'KAZAKH' : 'kk',
  242.     'KHMER' : 'km',
  243.     'KOREAN' : 'ko',
  244.     'KURDISH': 'ku',
  245.     'KYRGYZ': 'ky',
  246.     'LAOTHIAN': 'lo',
  247.     'LATVIAN' : 'lv',
  248.     'LITHUANIAN' : 'lt',
  249.     'MACEDONIAN' : 'mk',
  250.     'MALAY' : 'ms',
  251.     'MALAYALAM' : 'ml',
  252.     'MALTESE' : 'mt',
  253.     'MARATHI' : 'mr',
  254.     'MONGOLIAN' : 'mn',
  255.     'NEPALI' : 'ne',
  256.     'NORWEGIAN' : 'no',
  257.     'ORIYA' : 'or',
  258.     'PASHTO' : 'ps',
  259.     'PERSIAN' : 'fa',
  260.     'POLISH' : 'pl',
  261.     'PORTUGUESE' : 'pt',
  262.     'PUNJABI' : 'pa',
  263.     'ROMANIAN' : 'ro',
  264.     'RUSSIAN' : 'ru',
  265.     'SANSKRIT' : 'sa',
  266.     'SERBIAN' : 'sr',
  267.     'SINDHI' : 'sd',
  268.     'SINHALESE' : 'si',
  269.     'SLOVAK' : 'sk',
  270.     'SLOVENIAN' : 'sl',
  271.     'SPANISH' : 'es',
  272.     'SWAHILI' : 'sw',
  273.     'SWEDISH' : 'sv',
  274.     'TAJIK' : 'tg',
  275.     'TAMIL' : 'ta',
  276.     'TAGALOG' : 'tl',
  277.     'TELUGU' : 'te',
  278.     'THAI' : 'th',
  279.     'TIBETAN' : 'bo',
  280.     'TURKISH' : 'tr',
  281.     'UKRAINIAN' : 'uk',
  282.     'URDU' : 'ur',
  283.     'UZBEK' : 'uz',
  284.     'UIGHUR' : 'ug',
  285.     'VIETNAMESE' : 'vi',
  286.     'UNKNOWN' : ''
  287.   },
  288.  
  289.  
  290.  
  291.   service1ProcessResponse: function(response){
  292.   // NEW
  293.   // possible results of query
  294.   /* // example 1
  295.   [
  296.   [["language","language","",""]],
  297.   ,"en",,,,,,
  298.   [["en"]],
  299.   2]
  300.   // example 2
  301.   [
  302.     [["boy","garçon","",""]],
  303.     [["noun",["boy","lad","chap","youngster"],
  304.         [["boy",["garçon","boy","fils","gamin","jeune homme","élève"],[2],0.55225247],
  305.          ["lad",["garçon","gars","jeune","gamin","homme","fils"],[3],0.01382537],
  306.          ["chap",["type","garçon","bonhomme","gerçure","jeune homme","joue"],[3],0.0010172778],
  307.          ["youngster",["enfant","jeune homme","garçon","jeune cheval"],[4],0.00053606776]]
  308.         ]],
  309.     "fr",
  310.     ,
  311.     [["boy",[5],1,0,1000,0,1,0]],
  312.     [["garçon",4,,,""],["garçon",5,[["boy",1000,1,0],["guy",0,1,0],["fellow",0,1,0],["son",0,1,0],["boys",0,1,0]],[[0,6]],"garçon"]],
  313.     ,
  314.     ,
  315.     [["fr"]],
  316.     3
  317.   ]
  318.   // example 3
  319.   [
  320.   [["boy , window","garçon, fenetre","",""]],,"fr",,[["boy",[4],1,0,597,0,1,0],[", window",[5],0,0,529,1,3,0]],[["garçon",4,[["boy",597,1,0],["son",0,1,0],["guy",0,1,0],["fellow",0,1,0],["boys",0,1,0]],[[0,6]],"garçon, fenetre"],[", fenetre",5,[[", window",529,0,0]],[[6,15]],""]],,,[["fr"]],13]
  321.   */
  322.    //your regex rules go here...
  323.     var response=response.replace(/,,/g,",[[]],");          // ",," replace with ",[[]]," to make the response a full matrix
  324.     response=response.replace(/,,/g,",[[]],");          // again because of odd occurance of "," example ",,,"
  325.     var ds = response.split(']],');                 // split into elements
  326.     ds[0]=""+ds[0];                         // make string again
  327.     ds[0]=ds[0].replace(/\[/g, '');                 // delete [
  328.     ds[0]=ds[0].replace(/,\"\"/g, '');              // delete ,"",""
  329.     ds[0]=ds[0].replace(/\]/g, '');                 // delete ]
  330.     var directtranlation=ds[0].split('","');
  331.     if (directtranlation[0]) {
  332.         directtranlation[0]=directtranlation[0].replace(/\"/g, '');}    // delete "
  333.     if (directtranlation[1]) { 
  334.         directtranlation[1]=directtranlation[1].replace(/\"/g, '');}    // delete "
  335.        
  336.     /* ds[1]~alttr contains possible alternative source words and their translations, example output for alttr 
  337.     noun
  338.     boy,lad,chap,youngster
  339.     boy
  340.     garçon,boy,fils,gamin,jeune homme,élève
  341.     2,0.55225247
  342.     lad
  343.     garçon,gars,jeune,gamin,homme,fils
  344.     3,0.01382537
  345.     chap
  346.     type,garçon,bonhomme,gerçure,jeune homme,joue
  347.     3,0.0010172778
  348.     youngster
  349.     enfant,jeune homme,garçon,jeune cheval
  350.     4,0.00053606776 */
  351.     // alttr[0] type of word (noun, adjective ...
  352.     // alttr[1] length= number of possible alternative source words, iterator i
  353.     // alttr[3*(i-1)+2] first possible source word
  354.     // alttr[3*(i-1)+3] first possible source word with possible translations in target language
  355.     // alttr[3*(i-1)+4]     second item = probability of first possible source word with
  356.     //             first item = unknown
  357. /*  ds[1]=""+ds[1];
  358.     alert(ds[0]);
  359.     alert(ds[1]);  
  360.     var alttr = ds[1].split(',\[');
  361.     alert(alttr);
  362.     for( var i = 0, len = alttr.length; i < len; i++ ) {       
  363.         if( alttr[i] ) {
  364.             alttr[i] = alttr[i].split(',');
  365.             alttr[i] = ""+alttr[i];
  366.             alttr[i]=alttr[i].replace(/\[/g, '');       // delete [
  367.             alttr[i]=alttr[i].replace(/\]/g, '');       // delete ]
  368.             alttr[i]=alttr[i].replace(/\"/g, '');       // delete "
  369.         }
  370.     } */
  371.     // building simple html view
  372. /*  if( directtranlation ) {
  373.         response="<b>"+directtranlation[1]+"</b> - ";
  374.         if( directtranlation ) {
  375.                 response=response+directtranlation[0];
  376.         }
  377.     } */
  378.     if( directtranlation ) {
  379.         response=directtranlation[0];
  380.     }
  381.     /* here addtional info (response contains addional information) should be parsed and evaluated, but results differ and i have no time to find
  382.     a aprobiate solution, and it is not important
  383.     response=response+"\n";response=response+"\n"+"<b>"+alttr[0]+"</b>"+"\n";   //word class
  384.     for( var i = 0, len = alttr[1].length; i < len; i++ ) {             // iterate through alternatives
  385.         if( alttr[i] ) {
  386.             response="<b>"+alttr[3*(i-1)+2]+"</b> - "+alttr[[3*(i-1)+4]]+" - "+alttr[[3*(i-1)+3]]+"\n";
  387.             alert(response);
  388.         }
  389.     } */
  390.    
  391.     /* //other tests, not working, but for info
  392.     javascript:alert("detection:"+detectedlang, "isReliable", 1);
  393.         var startdelimeter='<div class="goog-inline-block goog-toolbar-button-inner-box">';         // start html-tag of translation
  394.         var enddelimeter="</div>";              // end tag of translation
  395.         var startindexoutput=response.lastIndexOf(startdelimeter);      // corresponding start index/position
  396.         response=response.substring(startindexoutput);          // delete all text before start delimeter, for easier finding the end delimeter          
  397.         var endindexoutput=response.indexOf(enddelimeter);      // end index/position
  398.         response=response.substring(startdelimeter.length,endindexoutput);      // extract translation as html (between start and end)
  399.         javascript:alert("detection:"+response, "isLastReliable", 1); */
  400.    return response;
  401.   },
  402.  
  403.   service2ProcessResponse: function(response){
  404.    // only first translation suggestion
  405.    if(!response) {return '';}
  406.    var startdelimeter='<div data-dz-role="result">';            // start html-tag of translation
  407.    var enddelimeter="<h2>Weitere Treffer</h2>";             // end tag of translation
  408.    var startindexoutput=response.lastIndexOf(startdelimeter);       // corresponding start index/position
  409.    if(startindexoutput<0) {
  410.     startindexoutput=response.lastIndexOf('<div id="section-0" class="section results">');
  411.     if(startindexoutput<0) {return '';}             // catch error not finding delimeter
  412.    }
  413.    var endindexoutput=response.lastIndexOf(enddelimeter);       // end index/position
  414.    if(endindexoutput<0) {
  415.     endindexoutput=response.lastIndexOf('<th colspan="2">Weitere Aktionen</th>');
  416.     if(endindexoutput<0) {return '';}               // catch error not finding delimeter
  417.    }
  418.    str = response.substring(startindexoutput,endindexoutput);       // extract translation as html-format (between start and end)
  419.    
  420. /*    // not known how to get the content of %to, so extraction of htmlcode easiest way
  421.    var targetlangdelim = str.indexOf('<td class="text" lang="');
  422.    var targetlang='';
  423.    if (targetlangdelim<0) {return '';}
  424.    targetlang = str.substring(str.indexOf(targetlangdelim)+1);
  425.    targetlang = targetlang.substring(0,targetlang.indexOf('</td>'));
  426.    targetlang = bfplugin.leoClearHTML(targetlang);
  427.     */
  428.    var firsttranslation='<td class="text" lang="';          //+ "de" +'">';     // when target language is known replace "de"
  429.    //alert("index:"+str.indexOf(firsttranslation)+" STR:"+str);
  430.    if (str.indexOf(firsttranslation)<0){return '-';}            // catch error not finding delimeter
  431.    str = str.substring(str.indexOf(firsttranslation)+1);        // first occurance of translation (source) (+1 to skip source=first finding)
  432.    str = str.substring(str.indexOf(firsttranslation));          // first occurance of translation (target)
  433.    str = str.substring(str.indexOf(firsttranslation),str.indexOf('</td>'));
  434.    str = bfplugin.leoClearHTML(str);                    // del html tags
  435.    str = str.replace(/, $/, '');                    // delete last comma
  436.    //str = str.replace(/(\r\n|\n|\r)/gm,"");                // delete empty lines etc
  437.    return str;
  438.   },
  439.  
  440.   service3ProcessResponse: function(response){
  441.    var startdelimeter='<div data-dz-role="result">';            // start html-tag of translation
  442.    var enddelimeter="<h2>Weitere Treffer</h2>";             // end tag of translation
  443.    var startindexoutput=response.lastIndexOf(startdelimeter);       // corresponding start index/position
  444.    var endindexoutput=response.lastIndexOf(enddelimeter);       // end index/position
  445.    str = response.substring(startindexoutput,endindexoutput);       // extract translation as html (between start and end)
  446.    //change here for other html-format
  447.    str = str.replace(/h2/g,"h3");
  448.    return str;
  449.   },
  450.  
  451.   detectionProcessResponse: function(response){
  452.         /* // OLD APPROACH        
  453.     try{
  454.           var result = JSON.parse(String(response));
  455.           if(!result || !result.responseData || !result.responseData.language)
  456.              throw "error";
  457.        }catch(e){return "";}
  458.        return [result.responseData.language, result.responseData.isReliable, result.responseData.confidence]; */
  459.        
  460.         // NEW
  461.     // http://translate.google.de/translate_a/t?client=t&text=fenetre&hl=en&sl=auto&tl=de&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=de&sc=1
  462.     // will get
  463.     // file "t" with:
  464.     //[[["Fenster","fenetre","",""]],,"fr",,[["Fenster",[4],1,0,1000,0,1,0]],[["fenetre",4,[["Fenster",1000,1,0],["Fensters",0,1,0],["window",0,1,0]],[[0,7]],"fenetre"]],,,[["fr","en"]],4]
  465.         if(!response) {return '';}
  466.     var detectedlang=response.replace(/,,/g,",[[]],");          // ",," replace with ",[[]],"
  467.     detectedlang=detectedlang.replace(/,,/g,",[[]],");          // again because of odd occurance of "," example ",,,"
  468.     detectedlang=detectedlang.match(/\]\],\"(.*?)\",\[\[/g);        // search for ]],"*",[[ where * is the detected language
  469.     if (detectedlang) {
  470.         var detectedlang=response.replace(/,,/g,",[[]],");
  471.         var detectedlang=detectedlang.replace(/,,/g,",[[]],");
  472.         detectedlang=detectedlang.match(/\]\],\"(.*?)\",\[\[/g);
  473.         detectedlang=""+detectedlang;                   // String(detectedlang)
  474.         //detectedlang=detectedlang.substring(4,6);         // alternative zu .match
  475.         detectedlang=detectedlang.replace(/"/g, '');            // delete "
  476.         detectedlang=detectedlang.replace(/\[/g, '');           // delete [
  477.         detectedlang=detectedlang.replace(/\]/g, '');           // delete ]
  478.         detectedlang=detectedlang.replace(/,/g, '');            // delete ,
  479.     }
  480.     else {
  481.         detectedlang="unknown";
  482.     }
  483.     alert("Detected language: "+detectedlang);
  484.     return [detectedlang, true, 1];                     // fake isReliable and fake confidence, since i have no time to extract
  485.   },
  486.  
  487.   //User defined function
  488.   //To use this function anywhere above you would address it with bfplugin.leoClearHTML(...)
  489.   leoClearHTML: function(str) {
  490.    str = str.replace(/<small>.*?<\/small>/gi, '');    // delete additional grammar hints
  491.    str = str.replace(/<sup>.*?<\/sup>/gi, '');
  492.    str = str.replace(/<[^>]*>/g, '');                 // delete all html tags
  493.    str = str.replace(/^\s+/,'').replace(/\s+$/,'');   // delete heading and trailing spaces
  494.    return str;
  495.   }
  496.  
  497.  
  498. };//never change this line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement