General
: K-Meleon Forum
General discussion about K-Meleon.
Goto:
Forum List
•
Message List
•
Search
•
Log In
Your Name:
Subject:
Help information
BBcode help
Smileys help
[quote=kko] [size=large]1) Use macros and an external application[/size] This code (an update of a [url=http://freenet-homepage.de/CoolMcKluus/software/kmeleon/macros/AddFavorite.html]previous version[/url]) is most probably the easiest example for the use of an external application. It makes use of the Shell.UIHelper ActiveX control (an Internet Explorer component) which is capable to do all we need (removing invalid characters from the link title, showing a dialog where the user can change this title and choose a location, and finally saving the shortcut to disk). All what's left to do is determining the URL of the current page (or link) and the page's title (or link's text) through macros (and JavaScript). Then we send this information to a Windows script through command line parameters. The script is only needed to create an instance of the Shell.UIHelper ActiveX control and call its AddFavorite() method with these command line parameters as arguments. All the rest is done by the control, we don't need to reinvent the wheel. [b]Problem:[/b] The favorites plugin doesn't notice when an external application is adding shortcuts to the Favorites folder and won't display these in the browser's menu and toolbar until it's reinitialized (i.e. the browser is restarted). [b][u]AddFavorite.js[/u]:[/b] [code]/* AddFavorite.js by kko, version 1.0 This script uses Internet Explorer's own "Add to Favorites" function to create a new Internet Shortcut. You will be asked for the name and the location. Windows Script Host 1.0 (or better) required! WSH is part of Microsoft Internet Explorer 5.0 and newer. Latest version of WSH is available at http://msdn.microsoft.com/scripting/ */ if (WScript.Arguments.length) { var uih = WScript.CreateObject("Shell.UIHelper"); var cmd = "uih.AddFavorite(WScript.Arguments(0)"; if ((WScript.Arguments.length > 1) && (WScript.Arguments(1))) cmd += ",WScript.Arguments(1)"; eval(cmd+");"); } else WScript.Echo("Syntax: "+WScript.ScriptName+" URL [Title]");[/code] [b][u]AddFavorite.kmm[/u]:[/b] [code]# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage) # ---------- Alternative "Add to Favorites" functionality ---------------------------------------------------------- # # Dependencies : main.kmm (JS) # Resources : AddFavorite.js # Preferences : - # # ------------------------------------------------------------------------------------------------------------------ AddFavorite_Page{ # Replacement for plugin command favorites(Add)/plugin(favorites,Add) $__s=$TITLE==$URL?"":$TITLE; exec("wscript.exe \"".$_AddFavorite_Path."\" \"".$URL."\" \"".$__s."\""); } AddFavorite_Link{ # Replacement for plugin command favorites(AddLink)/plugin(favorites,AddLink) $__t=$TITLE==$URL?"":$TITLE; $JS_doitLink="top.document.title=a[j].textContent;j=a.length"; &JS_hndlLink; $__s=$TITLE==$URL?"":$TITLE; injectJS("(function(){top.document.title='".$__t."';})();"); exec("wscript.exe \"".$_AddFavorite_Path."\" \"".$LinkURL."\" \"".$__s."\""); } # ----- PRIVATE $_AddFavorite_Path=""; _AddFavorite_BuildMenu{ setmenu("F&avorites",macro,"&Add Page",AddFavorite_Page,"favorites(Add)"); setmenu("F&avorites",command,"","favorites(Add)"); setmenu("DocumentSave",macro,"Add Page To F&avorites",AddFavorite_Page,"favorites(Add)"); setmenu("DocumentSave",command,"","favorites(Add)"); setmenu("LinkSave",macro,"Add Link To F&avorites",AddFavorite_Link,"favorites(AddLink)"); setmenu("LinkSave",command,"","favorites(AddLink)"); } $kFavorites==true?($OnInit=$OnInit."_AddFavorite_BuildMenu;"):0; _AddFavorite_GetPath{ # AddFavorite.js is supposed to be located in the same folder as AddFavorite.kmm (this file). # If it isn't, Windows Script Host will notify the user. $__data=readfile(getfolder(MacroFolder)."\\AddFavorite.kmm"); $_AddFavorite_Path=getfolder($__data==""?UserMacroFolder:MacroFolder)."\\AddFavorite.js"; } $kFavorites==true?($OnStartup=$OnStartup."_AddFavorite_GetPath;"):0; # ------------------------------------------------------------------------------------------------------------------ $kFavorites==true?($macroModules=$macroModules."AddFavorite;"):0;[/code][/quote]
[Please Enable JavaScript]
K-Meleon forum is powered by
Phorum
.
Home/News
Screenshots
Download
Documentation
Resources
Get Involved
Forum
Bugs
Development