# Greasify .5.5.20070115R2 (http://www.digivill.net/~joykillr/kmeleon) # K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage) # ---------- Greasify Macro ------------------------------------------------------------------------------------ # # Dependencies : main.kmm ($macroPrefBranch, JS) # Resources : - # Preferences : kmeleon.plugins.macros.greasify # kmeleon.plugins.macros.greasify.userscript[1-99] # kmeleon.plugins.macros.greasify.scripts.active # # ------------------------------------------------------------------------------------------------------------------ ###########GREASIFY############# $_Greasify_Custom=$macroPrefBranch."greasify"; Greasify{ $LOCALPATH = getpref(STRING,$_Greasify_Custom.".directory"); $howmany = 8; $scripts = ""; $HOST = hostname( $URL ); $hostlength = length($HOST); $xtotal = getpref(INT,$_Greasify_Custom.".scripttotal"); $xmain = 1; $hostlength==0 ? $xmain = 99:0; $xname = getpref(STRING,$_Greasify_Custom.".userscript".$xmain); $xnameLEN = length($xname); while ($xnameLEN != 0) &GMCodeChk; setpref(STRING,$_Greasify_Custom.".scripts.active", $scripts); } GMCodeChk{ $xname = getpref(STRING,$_Greasify_Custom.".userscript".$xmain); $xnameLEN = length($xname); $P1 = $LOCALPATH."\\".$xname; $CONTENT = readfile( $P1 ); $UAREA = index($CONTENT, "\/\/ ==UserScript=="); $II = index($CONTENT, "\/\/ ==\/UserScript=="); $II = $II - $UAREA; $UAREA = substr($CONTENT, $UAREA, $II); $I = index( $UAREA, "\/\/ @include" ); $ISUB = substr($UAREA, $I); $z = 0; $hstrun = $ISUB; $NS = index($UAREA, "\/\/ @name"); $NS = substr($UAREA,$NS); $NS = substr($NS,10); $NSend = index($NS, "\/\/ @namespace"); $NS = substr($NS,0,$NSend); index($CONTENT,"GM_addStyle(")>=1 ? &Greasify_AddStyle:0; &GCHostChk; $hst = $hstrun; $hst2 = $hstrun2; $ISUB2 = dirname($hst); &GCChk2; $xyz = 1; while ($xyz < $howmany) &GCChkRun; $z>=1 ? &GreasifyInjectJS:0; $xmain = $xmain + 1; $xname = getpref(STRING,$_Greasify_Custom.".userscript".$xmain); $xnameLEN = length($xname); } GreasifyInjectJS{ injectJS($CONTENT); $sbgo = getpref(INT,$_Greasify_Custom.".statusbarmsg"); $sbx = $z>=1 ? $sbgo!=-1 ? $sbgo!=0 ? 1:0; $sbx==1 ? statusbar("***Userscript Applied: ".$NS):0; $z>=1 ? $scripts = $scripts.\n\n.$NS." (".$xname.")".\n:0; } GCChkRun{ $HOSTREAL = -1; $hst2!=0 ? &GCChk1:$hst2>0 ? &GCChk1:0; $hstrun2!=0 ? &GCChk2:$hstrun2>0 ? &GCChk2:0; $z>=1 ? $xyz = $howmany:$xyz = $xyz + 1; } GCChk1{ $hstrun = $hst2; &GCHostChk; $hst = $hstrun; $hst2 = $hstrun2; $ISUB2 = dirname($hst); } GCChk2{ $HRLEN = length($HOSTREAL); $HRLEN<=0 ? $HOSTREAL = -1:0; $HOST2 = hostname( $ISUB2 ); $starbeg!=1 ? 0:$anyslash!=-1 ? 0:$HOST==$HOST2 ? $z = $z + 1:0; $z>=1 ? 0:$HOSTREAL==-1 ? 0:$HOSTREAL==$HOST2 ? $z = $z + 1:0; $USidx = length($hstrun); $USidx = $USidx - 2; $USidx2 = $USidx + 1; $hstr = substr($URL,7); $hstr = substr($hstr,0,$USidx); $hstrunvchk = substr($hstrun,$USidx,$USidx2); substr($hstrunvchk,0,1)=="*" ? $hstrunver = substr($hstrun, 0, $USidx):$hstrunver = $hstrun; $gocount = 8; $z>=1 ? 0:while ($gocount > 0) &GreasifyHostCheckHelper; $z>=1 ? 0:$hstr==$hstrunver ? $z = $z + 1:0; } GreasifyHostCheckHelper{ $USidx = $USidx - 1; $USidx2 = $USidx + 1; $hstrunvchk = substr($hstrun,$USidx,$USidx2); substr($hstrunvchk,0,2)=="\/\*" ? $hstrunver = substr($hstrun, 0, $USidx):$hstrunver = $hstrunver; substr($hstrunvchk,0,2)=="\/\*" ? $hstr = substr($hstr,0,$USidx):$hstr = $hstr; substr($hstrunvchk,0,2)=="\/\*" ? $gocount = 0:0; $gocount = $gocount - 1; } GCHostChk{ $I2 = index($hstrun, "http:\/\/"); $I22 = substr($hstrun, $I2); $ICHK = 7; $ICHK2 = substr($I22, 0, 8); $ICHKDOT = substr($I22, 0, 9); $ICHK2=="http:\/\/\*" ? $ICHK = $ICHK + 1:$starbeg = 0; $ICHK2=="http:\/\/\*" ? $starbeg = 1:0; $ICHK3B = $ICHKDOT=="http:\/\/\*." ? $ICHK = $ICHK + 1:0; $dotidx = 0; $HOSTREAL=-1; $dotidx = index($HOST, "."); $dotidx!=0 ? $dotidx = $dotidx + 1:0; $ICHK3B!=0 ? $HOSTREAL = substr($HOST, $dotidx):0; $hstrun = substr($I22, $ICHK); $ICHK3ORIG = index($hstrun, "\/\/ @include"); $ICHK3 = $ICHK3ORIG==-1 ? 0:$ICHK33 = substr($hstrun, $ICHK3ORIG); $ICHK3==0 ? $hstrun2 = 0:$hstrun2 = $ICHK33; $ICHK3==0 ? 0:$hstrun = substr($hstrun, 0, $ICHK3ORIG); $anyslash = index($hstrun, "\/")==-1 ? 0:1; } GreasifyDelScript{ &GreasifyScriptsActive; $scrnum = prompt("Enter the number of the script you wish to remove:", "Select Script To Remove", ""); $scrtodel = getpref(STRING,$_Greasify_Custom.".userscript".$scrnum); $scrnum!="" ? $confdel = confirm("Are you sure you wish to remove ".$scrtodel."?", "Remove Script from Repository?", YESNO, QUESTION):$confdel = "NO"; $confdel=="YES" ? $scrtomov = getpref(STRING,$_Greasify_Custom.".userscript".$count):0; $confdel=="YES" ? setpref(STRING,$_Greasify_Custom.".userscript".$scrnum, $scrtomov):0; $confdel=="YES" ? setpref(STRING,$_Greasify_Custom.".userscript".$count, ""):0; $confdel=="YES" ? $count = $count - 1:0; $confdel=="YES" ? setpref(INT,$_Greasify_Custom.".scripttotal", $count):0; } GreasifySetDir{ $FOLDERPATH = promptforfolder("Select Folder Containing User Scripts"); setpref(STRING,$_Greasify_Custom.".directory", $FOLDERPATH); } GreasifyScriptsActive{ $un = 1; $count = getpref(INT,$_Greasify_Custom.".scripttotal"); $scripts = ""; $workpref = getpref(STRING,$_Greasify_Custom.".userscript1"); $preflen = length($workpref); while ($preflen != 0) &GreasifyScriptsActiveHelp; alert($scripts, "Userscripts In Repository", INFO); } GreasifyScriptsActiveHelp{ $workpref = getpref(STRING,$_Greasify_Custom.".userscript".$un); $preflen = length($workpref); $scripts = $scripts.\n.$un.". ".$workpref; length($workpref)<=0 ? $preflen = 0:$un = $un + 1; $workpref = getpref(STRING,$_Greasify_Custom.".userscript".$un); $preflen = length($workpref); } GreasifySetScripts{ $FOLDERPATH = getpref(STRING,$_Greasify_Custom.".directory"); $foldlen = length($FOLDERPATH); $FILEPATH = promptforfile($FOLDERPATH,"User Script Files","*.user.js"); $filelen = length($FILEPATH); $un = 1; $workpref = getpref(STRING,$_Greasify_Custom.".userscript".$un); $preflen = length($workpref); while ($preflen >= 1) &GreasifySetScriptsHelp; $foldlen = $filelen - $foldlen; $filelen = $filelen - $foldlen; $filelen = $filelen + 1; $FILEPATH = substr($FILEPATH, $filelen); length($FILEPATH)>1 ? $RESULT = confirm("Confirm addition of userscript ".$FILEPATH."?", $FILEPATH, YESNO, QUESTION):$RESULT = "NO"; $RESULT == "YES" ? setpref(STRING,$_Greasify_Custom.".userscript".$un, $FILEPATH):0; $RESULT == "YES" ? setpref(INT,$_Greasify_Custom.".scripttotal", $un):0; } GreasifySetScriptsHelp{ $workpref = getpref(STRING,$_Greasify_Custom.".userscript".$un); $preflen = length($workpref); length($workpref)<=0 ? $preflen = 0:$un = $un + 1; } GreasifyToggle{ $VALUE = getpref(INT,$_Greasify_Custom.".enabled"); $VALUE==0 ? setpref(INT,$_Greasify_Custom.".enabled",1):setpref(INT,$_Greasify_Custom.".enabled",0); $VALUE==0 ? statusbar("Greasify Enabled"):statusbar("Greasify Disabled"); getpref(INT,$_Greasify_Custom.".enabled")!=1 ? setpref(BOOL,$_Greasify_Custom.".enablednew",FALSE):setpref(BOOL,$_Greasify_Custom.".enablednew",TRUE); menuchecked=getpref(BOOL,$_Greasify_Custom.".enablednew"); } GreasifySBToggle{ $VALUE = getpref(INT,$_Greasify_Custom.".statusbarmsg"); $VALUE==0 ? setpref(INT,$_Greasify_Custom.".statusbarmsg", 1):setpref(INT,$_Greasify_Custom.".statusbarmsg", 0); $VALUE==0 ? statusbar("Greasify Status-bar Notification Disabled"):statusbar("Greasify Status-bar Notification Enabled"); getpref(INT,$_Greasify_Custom.".statusbarmsg")!=1 ? setpref(BOOL,$_Greasify_Custom.".statbarnew",TRUE):setpref(BOOL,$_Greasify_Custom.".statbarnew",FALSE); menuchecked=getpref(BOOL,$_Greasify_Custom.".statbarnew"); } GreasifyScriptsApplied{ $scriptsactive = getpref(STRING,$_Greasify_Custom.".scripts.active"); alert($scriptsactive,"Userscripts Applied to the Current Page",INFO); } Greasify_AddStyle{ $CONTENT = $CONTENT.\n\n."function GM_addStyle(css) {var head = document.getElementsByTagName('head')[0]; if (!head) { return; } var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = css; head.appendChild(style);}".\n; } GreasifyApplyNow{ &Greasify; } GreasifyExportScriptList{ $un = 1; $count = getpref(INT,$_Greasify_Custom.".scripttotal"); $scripts = ""; $workpref = getpref(STRING,$_Greasify_Custom.".userscript1"); $preflen = length($workpref); while ($preflen != 0) &GreasifyScriptsActiveHelp; $scripts = gsub("\n1.", "Greasify User Script List \n1. ", $scripts); setclipboard($scripts); } ############################## # ----- PRIVATE $_Greasify_Custom=$macroPrefBranch."greasify"; _Greasify_BuildMenu{ $_gmenu="&Greasify"; setmenu(PrivacySecurity,popup,$_gmenu); setmenu($_gmenu,macro,"&Toggle Greasify On/Off",GreasifyToggle); setmenu($_gmenu,separator,"&Show Userscripts In Repository"); setmenu($_gmenu,macro,"&Show Userscripts In Repository",GreasifyScriptsActive); setmenu($_gmenu,macro,"Show Actively Applied Scripts to &Page",GreasifyScriptsApplied); setmenu($_gmenu,separator,"&Add User Script From Repository..."); setmenu($_gmenu,macro,"&Add User Script To Repository...",GreasifySetScripts); setmenu($_gmenu,macro,"&Remove Script From Repository...",GreasifyDelScript); setmenu($_gmenu,macro,"E&xport Script List to Clipboard",GreasifyExportScriptList); setmenu($_gmenu,separator,"Set Userscripts &Directory"); setmenu($_gmenu,macro,"Set Userscripts &Directory",GreasifySetDir); setmenu($_gmenu,macro,"Toggle Greasify Statusbar Message",GreasifySBToggle); setmenu($_gmenu,separator,"Apply Greasify &Now"); setmenu($_gmenu,macro,"Apply Greasify &Now",GreasifyApplyNow); } _Greasify_SetAccels{ setaccel("CTRL ALT U","macros(GreasifyToggle)"); } _GreasifyOnLoad{ getpref(INT,$_Greasify_Custom.".enabled")!=0 ? &Greasify:0; } $OnInit=$OnInit."_Greasify_SetAccels;_Greasify_BuildMenu;"; #$OnInit=$OnInit."_Greasify_BuildMenu;"; $OnLoad=$OnLoad."_GreasifyOnLoad;"; # ------------------------------------------------------------------------------------------------------------------ $macroModules=$macroModules."Greasify;";