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 default I10n.js file and the user’s prefs.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.


Updates:

2008-06-28
Cosmetic change to output. %3d to = and %2c to .
2008-06-24
Default engines file, I10n.js, is included



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, Prefs.js, I10n.js
# Preferences         : - kmeleon.plugins.macros.search.engine[0,1...x].url
# Version             : - 0.8   2008-06-24
# --------------------------------------------------------------------------------

_SearchH_Create{
$_SearchH_Profile_Path=getfolder( ProfileFolder );
$_SearchH_Root_Path=getfolder( RootFolder ) ;
exec("wscript.exe \"".$_SearchH_Path."\" \"".$_SearchH_Profile_Path."\" \"".$_SearchH_Root_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.8.1  2008-06-28

   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, I10n.js,
   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()==2)
{
var t, i, k ;                                                        // counters for arrays
var d, s = "Date created:  ", hm = "at:  ";          //Declare date/time variables.
var  words , wordslenght, look_1,  look_1_b ;     //   input line variables
var SearchH_NE_Choice ;
var ForReading = 1,  ForWriting = 2 ;  
var SearchH_SEngine_length ;
var SearchH_Profile_Path  = WScript.Arguments(0);
var SearchH_Root_Path  = WScript.Arguments(1);
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"; 
var SearchH_Search = new Array();                // the searches
var SearchH_SEngine = new Array();                // intermediate for prefs engines
var SearchH_DEngine = new Array();                // intermediate for default engines
var SearchH_Search_Text = new Array();                // output search text
var SearchH_CEengine = new Array();                //combined engines before sort
var SearchH_Both_Engine = new Array();        // combined engines after sort
var SearchH_Search_S = new Array();                // searches after sort

//  ##############  READ DEFAULT ENGINES
k=0;
var obj = new ActiveXObject("Scripting.FileSystemObject");
look_1 = null;
if ( obj.fileExists(SearchH_Defaults_Filespec))
        {
                b = obj.OpenTextFile(SearchH_Defaults_Filespec, ForReading);
                while (  !b.AtEndOfStream )
                {
                        //  read one line from the file                
                        words = b.ReadLine();
                        //  get the begining position of an engine
                         look_1 = words.indexOf("kmeleon.plugins.macros.search.engine");
                         if ((look_1 > 4)  && (look_1 < 10))   // this is an DEngine line  
                                 {
                                        SearchH_NE_Choice = words.substr(44,3) ;
                                        if  (SearchH_NE_Choice == "url" )  // this is an DEngine url line
                                        {
                                                 wordslength = words.length ;                                                                                        
                                                SearchH_DEngine[k] = words.substr(51, wordslength -54);
                                                k = k + 1 ;
                                        }
                                }
                        }  // end of while loop
                b.Close();
        }  // end of if exists
//  ##############  READ PREFS ENGINES        
k=0;
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
//  ##############   COMBINE THE DEFAULT AND PREFS ENGINES
SearchH_CEengine = SearchH_DEngine.concat(SearchH_SEngine) ;
//  ##############  SORT THE COMBINED ENGINES
SearchH_Both_Engine = SearchH_CEengine.sort();
//  ############## MAKE DUPLICATE ENGINES EQUAL NULL
for (k=0; k <SearchH_CEengine.length ; ++k )
        {
                if ( k> 0)
                        {
                                //WScript.Echo ( "Search_S " + k +" " + Search_S[k] );
                                if ( SearchH_CEengine[k] == SearchH_CEengine[k-1] )
                                        {
                                                SearchH_CEengine[k] = null ;
                                        }
                        }                        
        }
//  ##############  READ HISTORY FOR MATCHES TO ENGINES
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();
                         // loop thru all SearchH_SEngine values
                        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
//  ##############          SORT THE SEARCHES
SearchH_Search_S = SearchH_Search.sort();
//  ##############   WRITE THE INFORMATION AS HTML
var re = new RegExp("%20","g");  //Create regular expression object.        
var re2 = new RegExp("%3D","g") ;  //=
var re3 = new RegExp("%2C","g") ;  //.
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.length ; ++i )
                        {
                                k = 1 ;
                                look_1 = SearchH_Search[i].indexOf("=") ;
                                if  (look_1 == -1)
                                        {
                                                look_1_b =         SearchH_Search[i].indexOf("ial:Search/");  // Wikipedia
                                                if (look_1_b > -1) 
                                                {
                                                        k = 11 ;
                                                        look_1 = look_1_b ;
                                                }
                                        }
                                SearchH_Search_Text[i] = SearchH_Search[i].substr(look_1 + k).replace(re, " ")  ;
                                SearchH_Search_Text[i] = SearchH_Search_Text[i].replace(re2, "=")  ;
                                SearchH_Search_Text[i] = SearchH_Search_Text[i].replace(re3, ".")  ;
                                c.WriteLine(  "<li><B>" + SearchH_Search_Text[i] + "</B><a HREF = \"" +SearchH_Search[i] + "\">    " + SearchH_Search[i] + "</a> </li>" ) ;
                        }
                c.WriteLine( "</ol>" );        
                c.WriteLine( "</body>" );
                c.WriteLine( "</html>" );
                WScript.Echo("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.