K-Meleon

KMeleonWiki > Resources > MacroLibrary > KmmSearchH

Submitted by: JamesD



Notes:

This macro will create a local web page with the user’s previous web searches listed. It does this by scanning the history.dat file for searches where the search engine URL matches one the search engine URLs in the user’s pref.js file. The history plugin must be enabled so that data is written to the history file. Right clicking the history button will display the menu for this macro. You must create a page before you can use view but you can view a created page as many times as you need.

JScript and Windows Script Host 3.0 (or better) required!

WSH is part of Microsoft Internet Explorer 5.0 and newer. Latest version of WSH is available in the Download Section of Microsoft's Scripting Homepage.




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

SearchH.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#  
# ---------- SearchH.kmm
# ---------- K-Meleon Macro Language  Search History for web searches ---------------
#
# Dependencies        : - main.kmm history.dll
# Resources           : - history.dat
# Preferences         : - kmeleon.plugins.macros.search.engine[0,1...x].url
# Version             : - 0.5   2008-06-20
# --------------------------------------------------------------------------------

_SearchH_Create{
$_SearchH_Profile_Path=getfolder( ProfileFolder );
exec("wscript.exe \"".$_SearchH_Path."\" \"".$_SearchH_Profile_Path."\"") ;
}

_SearchH_View{
$_SearchH_Profile_Path=getfolder( ProfileFolder );
$_SearchH_Page_Path= $_SearchH_Profile_Path."\\SH.htm";
##open( $_SearchH_Page_Path );
opennew( $_SearchH_Page_Path );
##$kTabs?opentab( $_SearchH_Page_Path ):opennew( $_SearchH_Page_Path );
}

_SearchH_ModMenu{
$_SearchH_Popm = "Search History";
setmenu("Histor&y",popup,$_SearchH_Popm,1);
setmenu($_SearchH_Popm,macro,"Create page",_SearchH_Create,0);
setmenu($_SearchH_Popm,macro,"View page",_SearchH_View,1);
}

_SearchH_Get_Path{
### SearchH.js is supposed to be located in the same folder as SearchH.kmm (this file).
### If it isn't, Windows Script Host will notify the user.
### Double underscore makes variable local only.
$_SearchH_Path=getfolder(UserMacroFolder)."\\SearchH.js";
}

$OnStartup=$OnStartup."_SearchH_Get_Path;";
$OnInit=$OnInit."_SearchH_ModMenu;";

$macroModules=$macroModules."SearchH;";


SearchH.js


/*
***   SearchH.js by JamesD, version  0.5  2008-06-20

   This script is a helper application for the K-Meleon Macro Module SearchH.kmm that
   creates a local web page with previous searches by reading the history.dat and pref.js files.

   Windows Script Host 3.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()==1)
{
var t, i, k ;  
var d, s = "Date created:  ", hm = "at:  ";   
var  words , wordslenght, look_1,  look_1_b ;  
var SearchH_NE_Choice ;
var ForReading = 1,  ForWriting = 2 ;  
var SearchH_SEngine_length ;
var SearchH_Profile_Path  = WScript.Arguments(0);
var SearchH_History_Filespec= SearchH_Profile_Path + "\\History.dat" ;
var SearchH_Pref_Filespec= SearchH_Profile_Path + "\\prefs.js"; 
var SearchH_Htm_Filespec= SearchH_Profile_Path + "\\SH.htm"; 
var SearchH_Search = new Array();
var SearchH_SEngine = new Array();
var SearchH_Search_Text = new Array();

k=0;
var obj = new ActiveXObject("Scripting.FileSystemObject");
look_1 = null;
if ( obj.fileExists(SearchH_Pref_Filespec))
        {
                b = obj.OpenTextFile(SearchH_Pref_Filespec, ForReading);
                while (  !b.AtEndOfStream )
                {
                        //  read one line from the file                
                        words = b.ReadLine();
                        //  get the begining position of a search Pref
                         look_1 = words.indexOf("kmeleon.plugins.macros.search.engine");
                         if (look_1 > 9)   // this is an SEngine line  
                                 {
                                        SearchH_NE_Choice = words.substr(49,3) ;
                                        if  (SearchH_NE_Choice == "url" )  // this is an SEngine url line
                                        {
                                                 wordslength = words.length ;                                                                                        
                                                SearchH_SEngine[k] = words.substr(56, wordslength -59);
                                                k = k + 1 ;
                                        }
                                }
                }  // end of while loop
                b.Close();                                
        }  // end of if exists

look_1 = null; 
if (obj.FileExists(SearchH_History_Filespec))
        {
                t=0 ;
                a = obj.OpenTextFile(SearchH_History_Filespec, ForReading);
                while (  !a.AtEndOfStream )
                {
                        //  read one line from the file                
                        words = a.ReadLine();
                        for ( k=0 ; k< SearchH_SEngine.length ; ++k )
                        {
                                //  get the begining position of the searched for string - SearchH_SEngine[k]
                                 look_1 = words.indexOf(SearchH_SEngine[k]);
                                  SearchH_SEngine_length = SearchH_SEngine[k].length ;
                                 if (look_1 > -1)     
                                         {
                                                 wordslength = words.length ;
                                                 look_1_b = words.indexOf(")(",look_1 + (SearchH_SEngine_length -1)); 
                                                 if (look_1_b < 0 ) 
                                                 {
                                                         SearchH_Search[t] = words.substr( look_1 ) ;
                                                         look_1_c = SearchH_Search[t].length ;
                                                         SearchH_Search[t] = SearchH_Search[t].substr(0, look_1_c -1) ;
                                                         t = t+1 ;
                                                  }         
                                                  else  
                                                  {
                                                         SearchH_Search[t] = words.substr( look_1  , look_1_b -  look_1 ) ;
                                                        t = t+1 ;
                                                 }  // ends the if else block
                                         }  // ends the if(look_1 block
                                }  // end the for loop
         }   //  end the while loop
                
                a.Close();
        }  //end of the exists loop

// now sort the array
var SearchH_Search_S;
SearchH_Search_S = SearchH_Search.sort();                
//  now write the information

var re = new RegExp("%20","g");  //Create regular expression object.
var c =  obj.CreateTextFile(SearchH_Htm_Filespec, true)        ;
if (obj.FileExists(SearchH_Htm_Filespec))
        {
                c.WriteLine( "<html>" );
                c.WriteLine( "<head>" );
                c.WriteLine( "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" );
                c.WriteLine( "<title>K-Meleon Search History</title>" );
                c.WriteLine( "</head>" );
                c.WriteLine( "<body>" );
                c.WriteLine("<div align=\"center\"><H1> Search History </H1></div>");
                
                d = new Date();                                      //Create Date object.
                s += (d.getMonth() + 1) + "/";
                s += d.getDate() + "/";
                s += d.getYear();
                hm += d.getHours() + ":";
                hm += d.getMinutes() ;
                c.WriteLine("<div align=\"center\"><H4>" + s  +"  " + hm + "</H4></div>");                
                c.WriteLine("<ol>");
                for (i=0; i < SearchH_Search_S.length ; ++i )
                        {
                                look_1 = SearchH_Search_S[i].indexOf("=") ;
                                SearchH_Search_Text[i] = SearchH_Search_S[i].substr(look_1 +1).replace(re, " ") ;
                                c.WriteLine(  "<li><B>" + SearchH_Search_Text[i] + "</B><a HREF = \"" +SearchH_Search_S[i] + "\">    " + SearchH_Search_S[i] + "</a> </li>" ) ;
                        }
                c.WriteLine( "</ol>" );        
                c.WriteLine( "</body>" );
                c.WriteLine( "</html>" );
                WScript.Echo("Search History page written "+ hm)
                c.close() ;        
        }        
        else
        { 
                WScript.Echo( "file not made");
        }
}
else
{
objArgs = WScript.Arguments ;
WScript.Echo(WScript.Arguments.Count());
for (i=0; i<objArgs.length; i++)
{
    WScript.Echo(objArgs(i))
}
}        


Comments & Questions

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.