#ß K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage2) # # ---------------------- searchWwwInPage.kmm (FUNCTION TEST) ---------------------- # Version : v 0.2 / 2016-10-16 / by siria # K-Meleon version: KM7X ?? (macro-clipboard bugs in older versions) # Menu: Edit > Find in page last web search (later versions plus options menu) # Shortcut: CTRL+SHIFT+F (or change it below) # Button: (by user now, by macro later) # Prefs: kmeleon.plugins.macros.searchWwwInPage.xxxx # kmeleon.plugins.macros.search.query (<- shared with jsnj's searchplus macro) # Forum-1: http://kmeleonbrowser.org/forum/read.php?4,139963 # Forum-2: http://kmeleonbrowser.org/forum/read.php?xxx # Configuration: for BETA use page about:config, filter searchwww (toggle auto on/off; change URL key) # ------------------------------------------------------------------------------------------- # # First TEST version: does it work at all?? which KM-version?? helpful or useless?? Can Clipboard be reset?? # Recommend for first tests the shortcut CTRL+SHIFT+F, and if it's any use, could later add a macro button. # BUTTON optional: for now you can create one manually in toolbars.cfg, command is "macros(searchWwwInPage)" plus optional menu "Find" # # FUN CTION: This macro tries to figure out after every page load if the URL is a search engine (default url key: "/search?q="). If yes, what the searchtext was (= text after key until next &). This text is stored in a pref (profile or about:config) until the next search overwrites it again. Later, when user manually calls this macro on whatever page, it opens the native KM FindBar at the bottom and tries to PASTE the last searchtext inside, using macro-CLIPBOARD commands. # # Currently it AUTO-pastes only if the searchtext was 1 single word or started with a quoted expression ("aaa bbb ccc"), in that case the rest is ignored. If the searchtext consists of several words without quotes, the macro first opens an edit-field for user input. A later version may create a little popupmenu with single words in such cases. # # Note: # When searching for "word1 word2" Google also finds "word1;word2" "word1 ,word2" ,"word1. word2" ect. # No chance for this with the native Find-In-Page toolbar. # # ALTERNATIVE would be a little javascript snippet (bookmarklet), which has no toolbar nor buttons, and just jumps to the first hit and then the next ones. But don't have such a code yet, only saw fully grown independant ones so far ;-) # Manual button in an old style toolbars.cfg like Klassik (image depending from user skin) # searchWwwInPage{ # macros(searchWwwInPage)|Find # Find last web search in page # menu.bmp[12] # } # ------------------------------------------------------------------------------------------- # **USERCONFIG** choose your own keyboard shortcut: $_SWiPg_shortcut= "CTRL SHIFT F" ; # ------------------------------------------------------------------------------------------- _searchWwwInPage_firstrun{ # check if prefs exists already, if not create default values (universal urlkey) $_x=getpref(STRING,"kmeleon.plugins.macros.searchWwwInPage.urlkey"); $_x>"" ? 0 : setpref(STRING,"kmeleon.plugins.macros.searchWwwInPage.urlkey","/search?q="); $_x=getpref(STRING,"kmeleon.plugins.macros.searchWwwInPage.autosave"); if ($_x != "NO" and $_x != "YES") { alert("Macro \"searchWwwInPage\":\nConfiguration currently only in \"about:config\"","INFO (new macro)",INFO); setpref(STRING,"kmeleon.plugins.macros.searchWwwInPage.autosave","YES"); } $_x=""; } searchWwwInPage_saveLast{ if (getpref(STRING,"kmeleon.plugins.macros.searchWwwInPage.autosave")=="YES") { # $_uKey="/search?q="; $_uKey=getpref(STRING,"kmeleon.plugins.macros.searchWwwInPage.urlkey"); #alert($_uKey,"$_uKey - debug WWiPg2"); if (index($URL,$_uKey)>0) { # Take URL part after "/search?q=", then cut it at next "&", store this middle part $_sw=substr($URL,index($URL,$_uKey)+length($_uKey)); index($_sw,"&")>0 ? $_sw=substr($_sw,0,index($_sw,"&")) : 0; #alert($_sw,"$_sw - debug WWiPg3"); $_sw=gsub("+"," ",$_sw); $_sw=urldecode($_sw); #alert($_sw,"$_sw - debug WWiPg4"); setpref(STRING,"kmeleon.plugins.macros.search.query",$_sw); }}} searchWwwInPage{ macroinfo="Find in page the searchtext from last web SEARCH (options in about:config)"; id(ID_EDIT_FIND); $_sw=getpref(STRING,"kmeleon.plugins.macros.search.query"); if ($_sw>"") { $_sw1=""; # If searchtext is 1 word (=no blanks), use as is, only delete quotes: if (index($_sw," ")<0) $_sw1=gsub("\"","",$_sw); if (index($_sw,"\"")==0) { # If it STARTS with a " (quote) then use the text between it and the next " and ignore rest $_sw1=substr($_sw,1); $_sw1=substr($_sw1,0,index($_sw1,"\"")); } ##### alert($_sw."\n\n".$_sw1,"debug wwinpage1: sw - sw1"); if ($_sw1=="") $_sw1=prompt("","Find in page: all words together?",$_sw); # if ($_sw1>"") { # If searchtext was only 1 word OR if it had 2 quotes (" ") OR was input manually: # backup clipboard, copy searchtext into clip, paste clip into Find-Field, restore clipboard from backup ##### PROB: not sure about macros lineorder bug: can setclip sw1 work if value deleted at almost same time?? ### $_SWiPg_clipbak=getclipboard(); setclipboard($_sw1); id(ID_EDIT_FIND); id(ID_EDIT_PASTE); # $URLBAR="(debug test - Find in page: ".$_sw1." )"; ### setclipboard($_SWiPg_clipbak); } } $_sw=""; $_sw1=""; $_SWiPg_clipbak=""; } _searchWwwInPage_BuildMenu{ # to do: no menu yet for options, use about:config (toggle automatic on/off; change urlkey) setmenu("Find",macro,"Find in page last web search (SWiPg)","searchWwwInPage"); setaccel($_SWiPg_shortcut,"macros(searchWwwInPage)"); } #------------------------------------- STARTUP $OnInit=$OnInit."_searchWwwInPage_BuildMenu;"; # Check after EVERY page load if AUTO=YES, needed for in-session switching on/off: $OnLoad=$OnLoad."searchWwwInPage_saveLast;"; $OnStartup=$OnStartup."_searchWwwInPage_firstrun;"; $macroModules=$macroModules."searchWwwInPage;";