Improvement requests :  K-Meleon Web Browser Forum
Use this forum to talk about a feature you're missing. 
about FavRenAdd.js
Posted by: chinarobin
Date: July 17, 2008 03:05AM

i want to add some websites to my favourite, which folder i should place the FavRenAdd.js?

when i put it under the folder of default/pref, it cannot add in correctly,

could someone give me a hand?

thanks very much in advance!!



Edited 1 time(s). Last edit at 07/17/2008 06:01AM by chinarobin.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 17, 2008 11:05AM

@ chinarobin

Place the FavRenAdd.js in your user macro folder. Instruction from MacroLibrary.

Quote

Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder (Edit > Configuration > Macros) and create the following text file(s):

Both files, FavRenAdd.kmm and FavRenAdd.js should be in your user macro folder.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: chinarobin
Date: July 17, 2008 12:54PM

i did as you mentioned, but it suggested some loading problems.

i am using official 1.15 Simplified Chinese.

what's the problem?



Edited 1 time(s). Last edit at 07/17/2008 12:56PM by chinarobin.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 17, 2008 03:12PM

Does the error message about loading problems occur when KM starts or does it occur when you try to use FavRenAdd?

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: kko
Date: July 17, 2008 04:45PM

Probably a problem with Chinese characters. When you choose a target folder with accents/umlauts or non-latin (Greek, Cyrillic, Chinese, ...) characters in the path name, FavRenAdd.js quits with a runtime error because it tries to create a shortcut in a non-existing folder. (I just tried it with German umlauts.)

The problem is that FavRenAdd.js is reading prefs.js as if it were a plain text file, but it's UTF-8.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 17, 2008 05:50PM

I grew up with ASCII. It may take me a while to figure out how to load and read UTF-8. If anyone has a way or an idea how to get WSH to use the UTF-8, I would love to hear from you.

I have other macros which read dot js files in WSH. Are they likely to have the same problem? SearchH is one I am now concerned about.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: kko
Date: July 17, 2008 08:41PM

Quote
JamesD
I have other macros which read dot js files in WSH. Are they likely to have the same problem?

Yes, all of K-Meleon's *.js files that are used to store preferences are UTF-8 encoded in case of doubt.


Quote
JamesD
SearchH is one I am now concerned about.

Well, whether it's a problem or not depends on what you do with the read data. You should definitely not use that data to address local files...

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 17, 2008 09:19PM

I am not sure about addressing local files. All the file names are done in these lines of code for SearchH.

var SearchH_History_Filespec= SearchH_Profile_Path + "\\History.dat" ;
var SearchH_Pref_Filespec= SearchH_Profile_Path + "\\prefs.js";
var SearchH_Defaults_Filespec = SearchH_Root_Path + "\\defaults\\pref\\I10n.js"
var SearchH_Htm_Filespec= SearchH_Profile_Path + "\\SH.htm";

If the paths, which are arguement passed by the exec statement, are UTF-8 then I am adding ASCII to them.

One thing I am now sure is wrong is this line in the heading of the html code.
c.WriteLine( "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" );

I just copied that from some page. I don't know what charset value should be used.

With regard to FavRenAdd, I guess I could make another version which passes all the information by arguement. I did that once but we had the problem that the total length of the strings was often more than the exec statement could handle.

Best solution would be to find someone who can program in C to add the "Rename/Add" function to the DLL.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: chinarobin
Date: July 18, 2008 05:31AM

Quote
JamesD
Does the error message about loading problems occur when KM starts or does it occur when you try to use FavRenAdd?

if i put them into my user macro folder, it will cause the problem as kko said.

i don't know any programming, so i can't understand any string lines.

Hope this problem can be soon solved asap.

Thank you all for your attention!

In addition&#65292;i found another FavRenAdd.kmm in this forum. the rename function does

not work, and the add function doesn't select correct folder every time. for

example, if i choose the folder A for the 1st website, and B for another one, it

will still add it to the folder A. Can you help me?

FavRenAdd.kmm is as follows:

# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- Favorites ---------------------------------------------------------------------------------------------
#
# Dependencies : -
# Resources : -
# Preferences : -
#
# ------------------------------------------------------------------------------------------------------------------

AddFavorite2_Page{
$_FavAction=Add; &_AddFavorite2;
}
AddFavorite2_Link{
$_FavAction=AddLink; &_AddFavorite2;
}

# ----- PRIVATE

_AddFavorite2{
$_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory");
$_FavFolder==""?$_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_FavFolder==""?$_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_SubFolder="?"; while($_SubFolder=="?") &_AddFavorite2_Loop;
$_SubFolder==":"?0:length($_SubFolder)==0?delpref("kmeleon.plugins.favorites.newitemFolder"): setpref(STRING,"kmeleon.plugins.favorites.newitemFolder",$_SubFolder);
# HERE IS THE TRAP
# When the plugin is called below, it's not sure that the pref is already updated from above
$_SubFolder==":"?0: plugin(favorites,$_FavAction);
}
_AddFavorite2_Loop{
$_SubFolder=promptforfolder(_("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:"),$_FavFolder."\\".getpref(STRING,"kmeleon.plugins.favorites.newitemFolder"));
$_SubFolder=$_SubFolder==""?":":index($_SubFolder,$_FavFolder)==0?substr($_SubFolder,length($_FavFolder)+1):"?";
}

_AddFavorite2_BuildMenu{
setmenu("F&avorites",macro,"&Add Page",AddFavorite2_Page,"favorites(Add)");
setmenu("F&avorites",command,"","favorites(Add)");
setmenu("DocumentSave",macro,"Add Page To F&avorites",AddFavorite2_Page,"favorites(Add)");
setmenu("DocumentSave",command,"","favorites(Add)");
setmenu("LinkSave",macro,"Add Link To F&avorites",AddFavorite2_Link,"favorites(AddLink)");
setmenu("LinkSave",command,"","favorites(AddLink)");
}
$kFavorites==true?($OnInit=$OnInit."_AddFavorite2_BuildMenu;"):0;

# ------------------------------------------------------------------------------------------------------------------
$kFavorites==true?($macroModules=$macroModules."AddFavorite2;"):0;




_FavRenAdd_ModMenu{
### add another option to Favorites menu if favorites plugin is active
$kFavorites=="true"?setmenu("F&avorites",macro,"&Rename-Add",_FavRenAdd_RenameAdd,1):0;

### show in Document Popup ;
$kFavorites=="true"?setmenu("DocumentSave",macro,"&Rename-Add to Favorites",_FavRenAdd_RenameAdd,1):0;
}

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 18, 2008 09:21PM

@chinarobin

That was some code that was looked at during the build of FavRenAdd. It had the problem that you noticed. Comment in the code points out the problem.

setpref(STRING,"kmeleon.plugins.favorites.newitemFolder",$_SubFolder);
# HERE IS THE TRAP
# When the plugin is called below, it's not sure that the pref is already updated from above
$_SubFolder==":"?0: plugin(favorites,$_FavAction);

The macro language does not support a "sleep" statement to wait for time enough for the setpref statement to complete. The setperf statement does not support a callback to the macro when the actions is completed. For those reasons, I did not use this method.

Early research indicates the the File System Object in Windows Scripting Host does not support UTF-8. Therefore I am doing more research. I must warn you that a fast fix for the problem is unlikely.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: chinarobin
Date: July 19, 2008 01:18AM

@JamesD

it's really a shame, but thank you all the same!

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 19, 2008 07:32PM

@ chinarobin

I have a version of the macro for testing now. You can replace FavRenAdd kmm and js files with these new files. They are to be named FRA_U8.kmm and FRA_U8.js

This is the simple way that I tried first which had the problem when the name and URL length were sometimes too long for the exec statement in the macro.

This version does not edit the fields unless a restricted character in used in the name or the name is a duplicate of an existing name. I very much hope this lack of editing will allow the macro to work for UTF-8.

FRA_U8.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- FRA_U8.kmm
# ---------- K-Meleon Macro Language Rename/Add page to Favorites ---------------
#
# Dependencies        : main.kmm, Favorites plugin active, JScript, Windows Scripting Host
# Resources           : -
# Preferences         : -
# Version             :  1.01   2008-07-19
# --------------------------------------------------------------------------------
#
_FRA_U8_RnameTrue{
####   look three places for the favorites directory
$_FRA_U8_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory");
$_FRA_U8_FavFolder==""?$_FRA_U8_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_FRA_U8_FavFolder==""?$_FRA_U8_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
####   $_FRA_U8_FavFolder should have the path for the favorites folder   c:\something\favorites
####   call _FRA_U8_RnameTrue_loop until $_FRA_U8_SubFolder is no longer a "?"
$_FRA_U8_SubFolder="?";   while($_FRA_U8_SubFolder=="?") &_FRA_U8_RnameTrue_loop;
$_FRA_U8_Title = substr($_FRA_U8_value,1);
macros(_FRA_U8_Sanitize_Title) ;                                
$_FRA_U8_PathName = $_FRA_U8_FavFolder."\\".$_FRA_U8_SubFolder."\\".$_FRA_U8_Title.".url" ;
$_FRA_U8_Ext_Interger = 1;
while ($_FRA_U8_Ext_Interger > 0 ) &_FRA_U8_Duplicates_loop ;
$_FRA_U8_Profile_Path = getfolder( ProfileFolder );
# $_fmax: The length of the command line must not exceed 258 characters!
$_fmax=258;  $_fcmd="(wscript.exe \"".$_FRA_U8_Path."\" \"".$_FRA_U8_PathName."\" \"".$_FRA_U8_CurURL.")" ;
length($_fcmd)>$_fmax ? &_FRA_U8_Error : exec("wscript.exe \"".$_FRA_U8_Path."\" \"".$_FRA_U8_PathName."\" \"".$_FRA_U8_CurURL."\"") ;
}

_FRA_U8_Error{
setclipboard($_FRA_U8_Path. "\n" .$_FRA_U8_Profile_Path. "\n" .length($_fcmd) );
alert("Unable to create favorite - data too long!\n\nThe data was copied to the clipboard.","Failure to complete",EXCLAIM);
}

_FRA_U8_Sanitize_Title{
$_FRA_U8_RevTitle = gsub( "?"," ",$_FRA_U8_Title); 
$_FRA_U8_RevTitle = gsub( ":"," ",$_FRA_U8_RevTitle); 
$_FRA_U8_RevTitle = gsub( "*"," ",$_FRA_U8_RevTitle); 
$_FRA_U8_RevTitle = gsub( "<"," ",$_FRA_U8_RevTitle); 
$_FRA_U8_RevTitle = gsub( ">"," ",$_FRA_U8_RevTitle); 
$_FRA_U8_RevTitle = gsub( "/"," ",$_FRA_U8_RevTitle); 
$_FRA_U8_RevTitle = gsub( "|"," ",$_FRA_U8_RevTitle); 
$_FRA_U8_RevTitle = gsub( "\\","",$_FRA_U8_RevTitle);
$_FRA_U8_Title = gsub( "\"","^",$_FRA_U8_RevTitle);
}

_FRA_U8_Duplicates_loop{
$_FRA_U8_Exists=readfile($_FRA_U8_PathName);
$_FRA_U8_Exists=1.$_FRA_U8_Exists ;
$_FRA_U8_Len2=length($_FRA_U8_Exists);
$_FRA_U8_Len2 == 1 ? $_FRA_U8_Ext_Interger=0 : &_FRA_U8_Extend;
}

_FRA_U8_Extend{
$_FRA_U8_Wrk_Int = $_FRA_U8_Ext_Interger - 1 ;
$_FRA_U8_Ext_Interger == 1 ? $_FRA_U8_PathName = gsub(".url" , "[".$_FRA_U8_Ext_Interger."].url",$_FRA_U8_PathName):0;
$_FRA_U8_Ext_Interger > 1 ? $_FRA_U8_PathName = gsub("[".$_FRA_U8_Wrk_Int."].url" , "[".$_FRA_U8_Ext_Interger."].url" , $_FRA_U8_PathName):0;
$_FRA_U8_Ext_Interger = $_FRA_U8_Ext_Interger + 1 ;
}

_FRA_U8_RnameTrue_loop{
$_FRA_U8_SubFolder=promptforfolder("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:",$_FRA_U8_FavFolder);
$_FRA_U8_SubFolder=$_FRA_U8_SubFolder=="" ? "" : index($_FRA_U8_SubFolder,$_FRA_U8_FavFolder) == 0 ? substr($_FRA_U8_SubFolder,length($_FRA_U8_FavFolder)+1) : "?";
}

_FRA_U8_RenameAdd{
$_FRA_U8_CurrTitle = $TITLE;
$_FRA_U8_CurURL = $URL;
$_FRA_U8_value=prompt($_FRA_U8_CurrTitle,"Rename the Favorite Title here",$_FRA_U8_CurrTitle);
###  cancel from prompt will return a length of zero to which we add one
$_FRA_U8_value = 1.$_FRA_U8_value;
$_FRA_U8_Len=length($_FRA_U8_value);
###  if the length is 1 cancelled was pressed on the prompt box
$_FRA_U8_Len == 1 ? &_FRA_U8_Cancelled :&_FRA_U8_RnameTrue ;
}

_FRA_U8_Cancelled{
$FRA_U8_Button=confirm("Did you mean to cancel?","Affirm cancel" ,YESNO,QUESTION);
$FRA_U8_Button == "YES" ? 0 : &_FRA_U8_RenameAdd ;
}

_FRA_U8_ModMenu{
### add another option to Favorites menu if favorites plugin is active
$kFavorites=="true"?setmenu("F&avorites",macro,"&Rename-Add-8",_FRA_U8_RenameAdd,1):0;

### show in Document Popup ;
$kFavorites=="true"?setmenu("DocumentSave",macro,"&Rename-Add-8 to Favorites",_FRA_U8_RenameAdd,1):0;
}

_FRA_U8_GetPath{
### FRA_U8.js is supposed to be located in the same folder as FRA_U8.kmm (this file).
### If it isn't, Windows Script Host will notify the user.
$_FRA_U8_Data=readfile(getfolder(MacroFolder)."\\FRA_U8.kmm");
$_FRA_U8_Path=getfolder($_FRA_U8_Data==""?UserMacroFolder:MacroFolder)."\\FRA_U8.js";
}

$OnStartup=$OnStartup."_FRA_U8_GetPath;";
$OnInit=$OnInit."_FRA_U8_ModMenu;";
$macroModules=$macroModules."FRA_U8;";

FRA_U8.js

/* FRA_U8.js by JamesD, version  1.01  2008-07-19

   This script is a helper application for the K-Meleon Macro Module FRA_U8.kmm that
   enables you to rename a favorite, select a folder, and write the favorite to that folder.

   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.count()==2)
{
var $_FRA_U8_PathName  = WScript.Arguments(0);
var $_FRA_U8_CurURL  = WScript.Arguments(1);
var WshShell = new ActiveXObject("WScript.Shell")
var oShellLink = WshShell.CreateShortcut($_FRA_U8_PathName);
oShellLink.TargetPath = $_FRA_U8_CurURL;
oShellLink.Save();
}
else
{
objArgs = WScript.Arguments ;
WScript.Echo(WScript.Arguments.Count());
for (i=0; i<objArgs.length; i++)
{
    WScript.Echo(objArgs(i))
}
}


Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: chinarobin
Date: July 22, 2008 03:03AM

my problem still occured,but maybe not the problem of the 2 files you supplied with.

when i try to put it into macros folder like this way&#65306;the Edit > Configuration >

User-Defined Macros it suggest that the macro folder does not exist or invalid

catalog and when i put them into Macro Folder (Edit > Configuration > Macros),

loading problem happened. what the matter on earth, what should i do?

thanks very much!

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 22, 2008 12:09PM

I think the problem must be that I do not know how to code for UTF-8. These work for me, but I use only English. Maybe someone who reads this post will be kind and explain to me what I have to change to make them work for languages other than English.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: guenter
Date: July 22, 2008 02:02PM

@JamesD,

UTF8 is only a matter of using the right Editor.
I swear to PsPad.

PsPad shows in the status line what encoding the opened document has.
Format menu item lets You chose encodings. Default setting is ANSI - so change it.
Warning: the items German name is Format (sixth menu item from left).

BTW. For some Windows versions - MS made default editors do not even have an option to encode as UTF8. Or have a default encoding that is not easy to change sad smiley / many items (the first 200 odd) have the same encoding bitewise in ASCII. - But it does not help - for some items such as chrome files You must use UTF8 ( if the program that uses the file wants it ).


@chinarobin - PsPad has a Chinese version - maybe You use it also to re-save the file. Since JamesD swears the file works at his system - it might be Your editor that writes the wrong encoding (as I mentioned You will see no difference since many letters have identical bites )



Edited 1 time(s). Last edit at 07/22/2008 02:02PM by guenter.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: kko
Date: July 22, 2008 06:09PM

Quote
JamesD
I think the problem must be that I do not know how to code for UTF-8. These work for me, but I use only English. Maybe someone who reads this post will be kind and explain to me what I have to change to make them work for languages other than English.

It's all in order, James. FRA_U8.kmm/.js are working fine for me. As long as you use only plain English in your macros/scripts, there is no difference between UTF-8 and plain text.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: kko
Date: July 22, 2008 06:12PM

@chinarobin: You probably made a mistake when copy/pasting. The contents of FRA_U8.kmm starts with # and ends with ;. The contents of FRA_U8.js starts with / and ends with }.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 22, 2008 08:09PM

@ kko

I am glad the FRA_U8 works. Hope it will help chinarobin. Is this version ready for the MacroLibrary? Should I put warning in the FavRenAdd macro that it is only for English?

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: chinarobin
Date: July 23, 2008 01:33AM

failure to complete
unable to create favorite-date too long
the data was copied to the clipboard.

failure again enve this newest english version.

ok, i will leave this matter and keep on using this fast browser.

maybe my Chinese windows xp lead to such problem

thank you all above who gave me sincere help.

I'm a keen advocator of K-Meleon from China with little pc knowledge and hope it

develops stronger with its own property in future



Edited 1 time(s). Last edit at 07/23/2008 02:01AM by chinarobin.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 28, 2008 04:56PM

I have been doing some research and testing on the issue of using UTF-8 with FavRenAdd. The results are not positive. It appears that the save command in the shell within WSH is only for ASCII. The following is a quote from http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.scripting.wsh&tid=5937c80d-90c9-4769-af31-a24aa3892428&cat=en_US_d02fc761-3f6b-402c-82f6-ba1a8875c1a7&lang=en&cr=&sloc=en-us&m=1&p=1

"From running this in Dependency Walker, it appears that the
problem is the Save() method in WshShell's shortcut object. It appears that
it explicitly uses ANSI functions in OleAut32.dll to create the file, thus
choking on the wide characters. "

The save command in the shell is required to create an internet shortcut.

In addition to that problem is the fact that Windows Scripting Host will only read ASCII or UTF-16. K-Meleon uses UTF-8 for files. This means that WSH cannot read wide characters from K-Meleon files.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: chinarobin
Date: July 29, 2008 12:02AM

i think that's a deadly problem

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 29, 2008 11:17AM

Have just learned more from kko. Maybe I will be proved wrong. Still working on this.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: JamesD
Date: July 30, 2008 02:24PM

I have a new international version of FavRenAdd complete. It does not require reading of files so language should not be a factor. Many thanks must be given to kko for the large amount of help and support given to this effort.

The only limitation on this version is the length of the data string passed from the K-Meleon macro to Windows Scripting Host. Web pages with very long URLs may not work. There will be an error message if this occurs. This size limit also applies to the name you give to the shortcut.

FavRenAdd.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# ---------- FavRenAdd.kmm
# ---------- K-Meleon Macro Language Rename/Add page to Favorites ---------------
# ---------- INTERNATIONAL VERSION
#
# Dependencies        : - main.kmm, Favorites plugin active, JScript, Windows Scripting Host
# Resources           : - Registry keys "HKCU\\Software\\KMELEON\\FavRenAdd\\URLname"
#                 	            and "HKCU\\Software\\KMELEON\\FavRenAdd\\URLdisc"
# Preferences         : -
# Version             : -  3.0   2008-07-30
# --------------------------------------------------------------------------------
#
_FavRenAdd_RnameTrue{
####   look three places for the favorites directory
$_FavRenAdd_FavFolder=getpref(STRING,"kmeleon.plugins.favorites.directory");
$_FavRenAdd_FavFolder==""?$_FavRenAdd_FavFolder=readreg("HKCU","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
$_FavRenAdd_FavFolder==""?$_FavRenAdd_FavFolder=readreg("HKLM","Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Favorites"):0;
####   $_FavRenAdd_FavFolder should have the path for the favorites folder   c:\something\favorites
####   call _FavRenAdd_RnameTrue_loop until $_FavRenAdd_SubFolder is no longer a "?"
$_FavRenAdd_SubFolder="?";   while($_FavRenAdd_SubFolder=="?") &_FavRenAdd_RnameTrue_loop;
$_FavRenAdd_Title = substr($_FavRenAdd_value,1);
macros(_FavRenAdd_Sanitize_Title) ;                                
$_FavRenAdd_PathName = $_FavRenAdd_FavFolder."\\".$_FavRenAdd_SubFolder."\\".$_FavRenAdd_Title.".url" ;
$_FavRenAdd_Ext_Interger = 1;
while ($_FavRenAdd_Ext_Interger > 0 ) &_FavRenAdd_Duplicates_loop ;
## enclosure of a parameter in double quotes is only necessary when the parameter can contain whitespace
## therefor the 1, 2, and 3 in the next "exec" lines do not have double quotes
## first check the line lengths
$_fmax=258 ; $_FavRenAdd_ExVal = 0 ;
$_fcmd = "(wscript.exe \"".$_FavRenAdd_Path."\" 1 \"".$_FavRenAdd_PathName.")" ;
length($_fcmd)>$_fmax ? &_FavRenAdd_Error1:0;
$_fcmd = "(wscript.exe \"".$_FavRenAdd_Path."\" 2 \"".$_FavRenAdd_CurURL.")" ;
length($_fcmd)>$_fmax ? &_FavRenAdd_Error2:0;
$_FavRenAdd_ExVal < 2 ? &_FavRenAdd_RunScript:0;
}

_FavRenAdd_RunScript{
exec("wscript.exe \"".$_FavRenAdd_Path."\" 1 \"".$_FavRenAdd_PathName."\"");
exec("wscript.exe \"".$_FavRenAdd_Path."\" 2 \"".$_FavRenAdd_CurURL."\"");
exec("wscript.exe \"".$_FavRenAdd_Path."\" 3 \""execute"\"") ;
}

_FavRenAdd_Error1{
alert("Unable to create favorite - data too long!  Line length, ". length($_fcmd). " and line are displayed\n\n". $_fcmd, "String length too long!", EXCLAIM) ;
$_FavRenAdd_ExVal = $_FavRenAdd_ExVal + 2;
}

_FavRenAdd_Error2{
alert("Unable to create favorite - data too long!  Line length, ". length($_fcmd). " and line are displayed\n\n". $_fcmd, "String length too long!", EXCLAIM) ;
$_FavRenAdd_ExVal = $_FavRenAdd_ExVal + 3;
}

_FavRenAdd_Sanitize_Title{
$_FavRenAdd_RevTitle = gsub( "?"," ",$_FavRenAdd_Title); 
$_FavRenAdd_RevTitle = gsub( ":"," ",$_FavRenAdd_RevTitle); 
$_FavRenAdd_RevTitle = gsub( "*"," ",$_FavRenAdd_RevTitle); 
$_FavRenAdd_RevTitle = gsub( "<"," ",$_FavRenAdd_RevTitle); 
$_FavRenAdd_RevTitle = gsub( ">"," ",$_FavRenAdd_RevTitle); 
$_FavRenAdd_RevTitle = gsub( "/"," ",$_FavRenAdd_RevTitle); 
$_FavRenAdd_RevTitle = gsub( "|"," ",$_FavRenAdd_RevTitle); 
$_FavRenAdd_RevTitle = gsub( "\\","",$_FavRenAdd_RevTitle);
$_FavRenAdd_Title = gsub( "\"","^",$_FavRenAdd_RevTitle);
}

_FavRenAdd_Duplicates_loop{
$_FavRenAdd_Exists=readfile($_FavRenAdd_PathName);
$_FavRenAdd_Exists=1.$_FavRenAdd_Exists ;
$_FavRenAdd_Len2=length($_FavRenAdd_Exists);
$_FavRenAdd_Len2 == 1 ? $_FavRenAdd_Ext_Interger=0 : &_FavRenAdd_Extend;
}

_FavRenAdd_Extend{
$_FavRenAdd_Wrk_Int = $_FavRenAdd_Ext_Interger - 1 ;
$_FavRenAdd_Ext_Interger == 1 ? $_FavRenAdd_PathName = gsub(".url" , "[".$_FavRenAdd_Ext_Interger."].url",$_FavRenAdd_PathName):0;
$_FavRenAdd_Ext_Interger > 1 ? $_FavRenAdd_PathName = gsub("[".$_FavRenAdd_Wrk_Int."].url" , "[".$_FavRenAdd_Ext_Interger."].url" , $_FavRenAdd_PathName):0;
$_FavRenAdd_Ext_Interger = $_FavRenAdd_Ext_Interger + 1 ;
}

_FavRenAdd_RnameTrue_loop{
$_FavRenAdd_SubFolder=promptforfolder("Specify where to add the new shortcut. Select your Favorites folder or one of its subfolders:",$_FavRenAdd_FavFolder);
$_FavRenAdd_SubFolder=$_FavRenAdd_SubFolder=="" ? "" : index($_FavRenAdd_SubFolder,$_FavRenAdd_FavFolder) == 0 ? substr($_FavRenAdd_SubFolder,length($_FavRenAdd_FavFolder)+1) : "?";
}

_FavRenAdd_RenameAdd{
$_FavRenAdd_CurrTitle = $TITLE;
$_FavRenAdd_CurURL = $URL;
$_FavRenAdd_value=prompt($_FavRenAdd_CurrTitle,"Rename the Favorite Title here",$_FavRenAdd_CurrTitle);
###  cancel from prompt will return a length of zero to which we add one
$_FavRenAdd_value = 1.$_FavRenAdd_value;
$_FavRenAdd_Len=length($_FavRenAdd_value);
###  if the length is 1 cancelled was pressed on the prompt box
$_FavRenAdd_Len == 1 ? &_FavRenAdd_Cancelled :&_FavRenAdd_RnameTrue ;
}

_FavRenAdd_Cancelled{
$FavRenAdd_Button=confirm("Did you mean to cancel?","Affirm cancel" ,YESNO,QUESTION);
$FavRenAdd_Button == "YES" ? 0 : &_FavRenAdd_RenameAdd ;
}

_FavRenAdd_ModMenu{
### add another option to Favorites menu if favorites plugin is active
$kFavorites=="true"?setmenu("F&avorites",macro,"&Rename-Add",_FavRenAdd_RenameAdd,1):0;

### show in Document Popup ;
$kFavorites=="true"?setmenu("DocumentSave",macro,"&Rename-Add to Favorites",_FavRenAdd_RenameAdd,1):0;
}

_FavRenAdd_GetPath{
### FavRenAdd.js is supposed to be located in the same folder as FavRenAdd.kmm (this file).
### If it isn't, Windows Script Host will notify the user.
$_FavRenAdd_Data=readfile(getfolder(MacroFolder)."\\FavRenAdd.kmm");
$_FavRenAdd_Path=getfolder($_FavRenAdd_Data==""?UserMacroFolder:MacroFolder)."\\FavRenAdd.js";
}

$OnStartup=$OnStartup."_FavRenAdd_GetPath;";
$OnInit=$OnInit."_FavRenAdd_ModMenu;";
$macroModules=$macroModules."FavRenAdd;";

FavRenAdd.js

/* FavRenAdd.js by JamesD, version  3.01  2008-07-30
   INTERNATIONAL VERSION

   This script is a helper application for the K-Meleon Macro Module FavRenAdd.kmm that
   enables you to rename a favorite, select a folder, and write the favorite to that folder.

   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.count()==2)
{
	var WshShell = new ActiveXObject("WScript.Shell")
	if (WScript.Arguments(0) == 1)
		{
			WshShell.RegWrite ("HKCU\\Software\\KMELEON\\FavRenAdd\\URLname", WScript.Arguments(1), "REG_SZ");
		}
	if (WScript.Arguments(0) == 2)
		{
			WshShell.RegWrite ("HKCU\\Software\\KMELEON\\FavRenAdd\\URLdisc", WScript.Arguments(1), "REG_SZ");
		}		
	if (WScript.Arguments(0) == 3)
		{
			WScript.Sleep(1000);
			var $_FavRenAdd_PathName = WshShell.RegRead ("HKCU\\Software\\KMELEON\\FavRenAdd\\URLname") ;
			var $_FavRenAdd_CurURL   = WshShell.RegRead ("HKCU\\Software\\KMELEON\\FavRenAdd\\URLdisc") ;
			var oShellLink = WshShell.CreateShortcut($_FavRenAdd_PathName);
			oShellLink.TargetPath = $_FavRenAdd_CurURL;
			oShellLink.Save();
			WshShell.RegDelete ("HKCU\\Software\\KMELEON\\FavRenAdd\\URLname") ;
			WshShell.RegDelete ("HKCU\\Software\\KMELEON\\FavRenAdd\\URLdisc") ;
		}		
}
else
{
objArgs = WScript.Arguments ;
WScript.Echo(WScript.Arguments.Count());
for (i=0; i<objArgs.length; i++)
{
    WScript.Echo(objArgs(i))
}
}



Edited 1 time(s). Last edit at 07/30/2008 02:26PM by JamesD.

Options: ReplyQuote
Re: about FavRenAdd.js
Posted by: siria
Date: December 31, 2009 12:38AM

EDIT:
oops... old thread ;-) Continued here:
http://kmeleonbrowser.org/forum/read.php?4,81881



Edited 2 time(s). Last edit at 12/31/2009 12:46AM by siria.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.