Tutorial Plugin : 3 - Commandes de Maxthon

De Wiki Francophone de Maxthon
Aller à la navigation Aller à la recherche

Maxthon now has more than 20 commands. Most commands only work in plugins but some can also be used on normal webpages.

Maxthon a maintenant plus de 20 commandes. De nombreuses commandes fonctionnent seulement dans les plugins, mais certaines peuvent aussi être utilisées dans des pages Web normales.

You can call these commands through the 'window.external' object. Because it was possible for webpages to use these commands, most commands require a security_id now.

Vous pouvez appeler ces commandes avec l'objet "window.external". Parce qu'il est possible pour les pages Web d'utiliser ces commandes, de nombreuses commandes nécessitent maintenant un "security_id" (une identification de sécurité).


A security_id is a variable that looks like this: "{DCFC4598-B97C-49B6-8108-EE86F8694283}". The security_id changes every time you restart your browser.

Un "security_id" est une variable qui ressemble à ceci : "{DCFC4598-B97C-49B6-8108-EE86F8694283}". Le "security_id" change chaque fois que vous relancez votre navigateur.

  1. For script plugins, you need to use %max_security_id in your script file, such as 'var security_id=%max_security_id', then you can use 'security_id' in your script. NOTE: Webpages are able to get this security_id variable if you run a plugin on a webpage and if the webpage knows the variable you use to store the max_security_id in. You can avoid this security issue if you put all your code in an anonymous function. More about anonymous functions in part 4.
  2. For sidebar plugins, a file named "max.src" will be created in your plugin's folder with variable max_security_id as the security_id. You can include this file into your html page to get the id.Like this:
    <script language="JavaScript" type="text/JavaScript" src="max.src">
    </script>

    This code should be placed inside the <head> element.

  1. Pour les plugins de script, vous devez utiliser %max_security_id dans le fichier de script, tel que 'var security_id=%max_security_id', alors vous pourrez utiliser 'security_id' dans votre script.
    NOTE : Les pages Web sont capables d'obtenir cette variable security_id si vous lancez un plugin sur une page Web et si la page Web connaît la variable que vous stockez dans le max_security_id. Vous pouvez éviter un litige de sécurité si vous mettez tout votre code dans une fonction annonyme. [Vous avez plus d'informations sur les fonctions anonymes dans la 4ème Partie]. Je ne suis pas trop sûr de la traduction de cette note. A revoir, svp.
  2. Pour les plugins de barre latérale, un fichier nommé "max.src" devra être créé dans le dossier de votre plugin avec la variable max_security_id comme étant le security_id. Vous pouvez inclure ce fichier dans votre page html pour obtenir le "id" (id est à mon avis égal à identifiant).
    Comme ceci :
     <lang="html4strict"><script language="JavaScript" type="text/JavaScript" src="max.src">
    </script>

    Ce code devrait être placé à l'intérieur de la balise <head> .

    These are the Maxthon DHTML commands, don't forget to put 'external.' before them!: Ce sont des commandes DHTML de Maxthon, n'oubliez pas de mettre 'external' devant elles ! :
  1. readFile( security_id, plugin_name, file_name) The 'plugin_name' refers to the plugin name defined in plugin.ini and the 'file_name' indicates which file it wants to read (located in the plugin folder). This filename can include a subpath, like 'data/settings.ini' to read the file 'settings.ini' in the 'data' subfolder.The filename can also include '..' to read the parent directory, for example '../../config/plugins.ini' to read the plugins.ini file in the Maxthon/config directory. You can't use '..' more than two times, so you are not able to read/write files outside the Maxthon directory (for more security).
  1. readFile( security_id, plugin_name, file_name) L'indication 'plugin name' fait référence au nom du plugin défini dans le fichier plugin.ini et l'indication 'file name' indique le nom du fichier qu'il veut lire (situé dans le dossier plugin). Ce nom de fichier peut inclure un chemin, tel que 'data/settings.ini' pour lire le fichier 'settings.ini' dans le dossier 'data'.
    Le nom de fichier peut également inclure '..' pour lire le dossier parent, par exemple : '../../config/plugins.ini' pour lire le fichier plugin.ini dans le [sous-]dossier Maxthon/config. Vous ne pouvez pas utiliser '..' plus de deux fois, ainsi vous ne pourrez pas lire/écrire des fichiers en dehors du dossier où Maxthon est situé (pour une meilleure sécurité).

    The command will return the file contents. If the plugin is not enabled or the 'plugin_name' is wrong or not found, the command will fail and return null. This command can only read ANSI text files.
    var text = external.readFile(%max_security_id,
    "Test plugin","export.txt")
  2. writeFile( security_id, plugin_name, file_name, content ) The 'plugin_name' refers to the plugin name defined in plugin.ini and the 'file_name' indicates the file name which will be written. The 'content' is the content that will be written to the file. If the plugin is not enabled or the 'plugin_name' is wrong or not found, the command will fail and return null. This command can only write text files. Also, the command adds an extra NULL character to the end of the file. This doesn't matter much, but it makes it impossible to write XML files. You have to use FileSystemObject (an ActiveX component) for that. Please note: The file will be overwritten from the beginning. To add content to a file, read the data from a file first, then add the new data and then write the data.
    external.writeFile(%max_security_id,"Test plugin",
    "export.txt", "Some Data.")
  3. writeFile( security_id, plugin_name, file_name, content ) Cette fonction ne peut être utilisée que dans un script de plugin, pour des raisons de sécurité. Le 'plugin_name' se réfère au nom du plugin défini dans plugin.ini et le 'file_name' indique le nom du fichier qui doit être écrit. Le 'content' est le contenu qui sera écrit dans le fichier. Si le plugin n'est pas capable d'écrire ou que le nom du plugin et erroné ou non trouvé, la fonction se terminera sur une erreur et retournera null.
    Cette commande peut seulement écrire des fichiers 'texte'. Aussi, la commande ajoute un caractère NULL à la fin du fichier. Cel n'a pas beaucoup d'importance, mais rend impossible d'écrire un fichier XML. Vous devez utiliser pour cela FileSystemObject (un composant ActiveX). Notez SVP: Le fichier sera écrasé à partir du début. Pour ajouter du contenu à un fichier, liser la donnée du premier fichier, puis ajouter la nouvelle donnée et écriver la donnée.
    Exemple: external.writeFile(%max_security_id,"Test plugin","setting.ini","username=abc\npass=qwrxcv"); 
  4. m2_readIni( security_id, plugin_name , file_name , section_name , key , default_value) This command will read the key in the ini-file specified by file_name in the plugin folder. It will return the default_value if the key is not available or if the file_name or plugin_name are wrong.
    path = external.m2_readIni(%max_security_id,
    "testplugin","settings.ini","general","save","0")
  5. m2_readIni( security_id, plugin_name , file_name , section_name , key , default_value) Cette fonction lit la clé utilisant la default_value dans le fichier ini spécifié par file_name dans le répertoire du plugin. <pre<Exemple: path = external.m2_readIni(%max_security_id,"testplugin","settings.ini","general","save","0");
  6. m2_writeIni( security_id , plugin_name , file_name , section_name , key , value ) This command will write the key with 'value' to the ini file specified by file_name.
    external.m2_writeIni(%max_security_id,"testplug",
    "settings.ini","general","save","1")
  7. m2_writeIni( security_id , plugin_name , file_name , section_name , key , value ) Cette fonction écrit la clé avec la valeur dans le fichier ini spécifié par file_name.
    Exemple: external.m2_writeIni(%max_security_id,"testplugin","settings.ini","general","save","true"); 
  8. tab_count This command will return the total number of open tabs, just like 'Number of tabs' in the statusbar.
    var total_tab = external.tab_count
  9. tab_count Cette commande retourne le nombre total d'onglets sous la forme d'un entier.
    Exemple: var total_tab = external.tab_count ; Démo 
  10. activate_tab( security_id , index ) This command will activate tab number 'index' in Maxthon. ('index' is starting from zero)
    external.activate_tab(%max_security_id,2)
  11. activate_tab( security_id , index ) Cette fonction active l'onglet numéro 'index' de Maxthon.
    Exemple: external.activate_tab(%max_security_id,2) 
  12. close_tab( security_id , index ) This command will close tab number 'index' in Maxthon. ('index' is starting from zero)
    external.close_tab(%max_security_id,2)
  13. close_tab( security_id , index ) Cette commande fermera l'onglet numéroté selon son 'index' dans Maxthon ('index' démarre à zéro).
    external.close_tab(%max_security_id,2)
  14. get_tab( security_id , index ) This command will return a web page object of tab number 'index'. ('index' is starting from zero) You can use this if you need to get information about this tab, like the title or URL.
    var doc = external.get_tab(%max_security_id,2).document
  15. get_tab( security_id , index ) Cette fonction retourne la page web de l'onglet index.
    Exemple: external.get_tab(%max_security_id,2) 
  16. cur_sel This command will return the number of the current active tab (starting from zero).
    var cur_tab = external.cur_sel
  17. cur_sel Cette fonction retourne le numéro de l'onglet courant sous la forme d'un entier.
    Exemple: var cur_tab = external.cur_sel; Démo 
  18. m2_plugin_folder( security_id , plugin_name ) This command will return the local path of the plugin. You can use this command if you add local images to a webpage or if you add a local stylesheet to a webpage.
    var folder = external.m2_plugin_folder(%max_security_id,
    "ViewSource!")

    This will return for example: "C:\Program Files\Maxthon\Plugin\ViewSource!\"

  19. m2_plugin_folder( security_id , plugin_name ) Cette fonction retourne le répertoire local du plugin.
    Exemple: var folder = external.m2_plugin_folder(%max_security_id,"ViewSource!");
    Ceci retourne par exemple : "C:\Program Files\Maxthon\Plugin\ViewSource!\" 
  20. m2_run_cmd( security_id , id ) This command will call a Maxthon command with the specified ID. The id of every command can be found in the language file, or here.
    external.m2_run_cmd(%max_security_id,32772)
    This will open a blank page.
  21. m2_run_cmd( security_id , id ) Cette fonction appelle une commande de Maxthon avec l'ID. L'id de chaque commande sera présent dans le fichier de chaque langue.
    Exemple: external.m2_run_cmd(%max_security_id,32772); //Ceci ouvre une page vierge. 
  22. m2_callerName( security_id, plugin_name) This command tells Maxthon the call is made from a Plugin. It's usually used before a 'window.open()' call to let maxthon bypass the popup filter. The opened window will get the focus if you use this command.
    external.m2_callerName(%max_security_id,"ViewSource!")
  23. m2_callerName( security_id, plugin_name) Cette fonction indique à Maxthon que l'appel est réalisé à partir du Plugin. C'est habituellement utilisé avant un appel 'window.open()' pour que maxthon ne tienne pas compte de la fenêtre popup que le plugin ouvre.
    Exemple: external.m2_callerName(%max_security_id,"ViewSource!")
  24. max_showConfig( security_id, plugin_name) This command will show the plugin's configuration dialog (check part 2 of this tutorial for more info about the configuration window).
    external.max_showConfig(%max_security_id,"ViewSource!")
  25. max_activex(security_id, prog_id) This command will create the ActiveX control with the prog_id. This ActiveX control has more rights than a normal ActiveX control, you can use it even if you have very high security settings, but it's still possible that virus scanners block the component. You have to open a new window or else you get the alert "This command can only be called from local pages". A new window is a 'local page' for Maxthon.
    external.m2_callerName(%max_security_id,'PLUGINNAME')
    window.open('about:blank','_blank')
    var XML=external.get_tab(%max_security_id,
    external.cur_sel).external.max_activex( %max_security_id, 
    "Microsoft.XMLDOM")
    external.get_tab(%max_security_id,external.cur_sel).close()
  26. max_activex(security_id, prog_id) Cette fonction crée l'ActiveX avec le prog_id. <pre<Exemple: var XML=external.max_activex(%max_security_id,"Microsoft.XMLDOM")
  27. max_modelessDialog( security_id , url , option , attr , window ) This command will open a modelessDialog. It's same as the window.ShowModelessDialog command. The last parameter 'window' is the window object of the web page.
     external.max_modelessDialog(%max_security_id,
    'example.htm',window, 'status:no;help:no;
     resizable:yes;scroll:yes;',window)
  28. max_modelessDialog( security_id , url , option , attr , window ) Cette fonction ouvre un modelessDialog. C'est la même chose que la fonction window.ShowModelessDialog. Le dernire paramètre 'window' est l'objet fenêtre de la page web.
    Exemple: external.max_modelessDialog(%max_security_id,'example.htm',window,'status:no;help:no;resizable:yes;scroll:yes;',window) 
  29. max_language_id This property returns the user's current selected Maxthon language code. You can view all the language codes here
    var language=external.max_language_id
  30. max_language_id Cette propriété représente la langue utilisée. Vous pouvez visualiser toutes les langues ici
    Exemple: var language=external.max_language_id 
  31. max_actSideBarItem( plugin_name ) This command will activate the sidebar plugin named as 'plugin_name'.
    external.max_actSideBarItem("Calculator++&quot)
  32. max_actSideBarItem( plugin_name ) Cette fonction active le plugin de la barre latérale du nom de 'plugin_name'.
    Exemple: external.max_actSideBarItem("Calculator++");
  33. addFavorite( url , title ) , addFavorite( url ) This command will ask the user to add the 'url' into favorites, using 'title' for the name of the url (not required).
    external.addFavorite( "http://www.google.com" )
    external.addFavorite( "http://www.google.com","This 
    is google")
  34. addFavorite( url , title ) , addFavorite( url ) Cette fonction demandera à l'utilisateur d'ajouter lurl' dans les favories, en utilisant 'title' comme nom d'url.
    Exemple 1: external.addFavorite( "http://www.google.com" ); Démo 
    Exemple 2: external.addFavorite( "http://www.google.com","C'est google"); Démo 
  35. addProxy (name, address, speed, is_web_proxy) This command will call Maxthon's 'add proxy' dialog to add the proxy named as 'name' at address 'address', giving the initial speed 'speed'. The is_web_proxy indicates whether the proxy is a web proxy or a normal proxy.
    external.addProxy("My proxy","192.168.1.0:8080",1,0)
  36. addProxy (name, address, speed, is_web_proxy) Cette fonction appellera la boîte de dialogue d'ajout d'un proxy de Maxthon pour ajouter le nom du proxy 'name' à l'adresse 'address', en indiquant comme vitesse initiale 'speed'. Le is_web_proxy indique si le proxy est un proxy web ou un proxy normal.
    Exemple: external.addProxy("Mon proxy","192.168.1.0:8080",1,0); Démo  
  37. addFilter( address ) , addFilter( address, is_pop_filter ) This command will call Maxthon's 'add filter' dialog, setting the address to be filtered as 'address'. 'is_pop_filter' indicates whether the default filter type is 'pop filter'.
    external.addFilter("http://www.yahoo.com/ad*")
    external.addFilter("http://www.yahoo.com/img/*", 0)
  38. addFilter( address ) , addFilter( address, is_pop_filter ) Cette fonction appellera la boîte de dialogue d'ajout d'un filtre de Maxthon, en indiquant l'adresse à filtrer 'address'. 'is_pop_filter' indiquant si le type de filtre par défaut est un filtre de popup.
    Exemple 1: external.addFilter("http://www.yahoo.com/ad*"); Démo 
    Exemple 2: external.addFilter("http://www.yahoo.com/img/*", 0); Démo 
  39. m2_addSearchEngine(name, address) This property will call Maxthon's 'add search engine' dialog.
    javascript:external.m2_addSearchEngine('SteadySearch',
    'http://www.steadysearch.com/search?p=Q&ts=ne&w=%us');
  40. m2_addSearchEngine(name, address) Cette fonction appelle la boite de dialogue "Ajouter un moteur de recherche" de Maxthon.
    javascript:external.m2_addSearchEngine('SteadySearch',
    'http://www.steadysearch.com/search?p=Q&ts=ne&w=%us');
  41. m2_search_text( security_id ) This property will return the text in Maxthon's search bar.
    var text = external.m2_search_text(%max_security_id)
  42. m2_search_text( security_id ) Cette propriété retourne le texte dans la barre de recherche de Maxthon.
    Exemple: var text = external.m2_search_text(%max_security_id) 

In a sidebar plugin you can implement a script function called max_callback(status).

  1. When the plugin is created the URL will be filename?maxcmd=init
  2. When the plugin is activated, max_callback('sidebar_activate') will be called
  3. When the plugin is deactivated, max_callback('sidebar_deactivate') will be called
  4. When the active tab is changed, max_callback('sidebar_tab_change') will be called
  5. When the plugin is unload, max_callback('sidebar_unload') will be called.


< Partie 2 : Fichiers Plugin | Sommaire Plugin | Partie 4 : Astuces >