Greasify Userscript Macro |
GreaseMonkey for KMeleon!For K-Meleon 1.02 and older?:Greasify for K-Meleon 1.021.02: The include URLs in the userscript can start or end with an asterix but there can't be any other *s for it to work properly. Example: WOULD WORK: http://*.yahoo.com/* Updated Dec. 5 - minor bug fixes Updated November 22nd - Fixed Enable/Disable and added experimental support for GM_addStyle Updated Nov 19, 2006: Major improvements. Integrated a Greasify Controls Sub-menu under the Tools menu. Greasify can be enabled/disabled "on the fly" and all configuration is done through the GUI. Also cleaned up some code. Should now better interpret include URLS (though it isn't perfect). For K-Meleon 1.02:MACROS.CFGFirst, add the specified line to OnLoad in macros.cfg:
OnLoad{
# General: &Sync; ### ADD THIS LINE: ### getpref(INT,"kmeleon.plugins.macros.greasify.enabled")!=0 ? &Greasify:0; ### --- ### } Then add all this code at the bottom of macros.cfg:
########### GREASIFY v.5.3R2 #############
$_Greasify_Custom="kmeleon.plugins.macros.greasify";
Greasify{
$frun = getpref(INT,$_Greasify_Custom.".firstrun");
$fruns = $frun==1 ? "NO":confirm("Greasify is installed. Do you wish to configure it now?","Greasify First Run Config",YESNO,QUESTION);
$fruns=="YES" ? &GreasifyFirstTime:setpref(INT,$_Greasify_Custom.".firstrun",1);
$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 = 32: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 ? injectJS($CONTENT):0;
$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;
$xmain = $xmain + 1;
$xname = getpref(STRING,$_Greasify_Custom.".userscript".$xmain);
$xnameLEN = length($xname);
}
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");
}
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");
}
GreasifyScriptsApplied{
$scriptsactive = getpref(STRING,$_Greasify_Custom.".scripts.active");
alert($scriptsactive,"Userscripts Applied to the Current Page",INFO);
}
GreasifyFirstTime{
alert("You will be prompted for your userscripts path. You can cancel this if you want to setup Greasify later from the Tools Menu.","Greasify First-Time Run",EXCLAIM);
&GreasifySetDir;
$res = confirm("Add a script now?","Add Script To Repository?",YESNO,QUESTION);
$res=="YES" ? &GreasifySetScripts:0;
setpref(INT,$_Greasify_Custom.".firstrun",1);
}
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);
}
##############################
MENUS.CFGAdd this in the Macros section of menus.cfg: # ---------- Macros
%ifplugin macros
### ADD THIS CODE: ###
&Greasify{
macros(GreasifyToggle, &Toggle Greasify On/Off)
-
macros(GreasifyScriptsActive, &Show Userscripts In Repository)
macros(GreasifyScriptsApplied, Show Actively Applied Scripts to &Page)
-
macros(GreasifySetScripts, &Add User Script...)
macros(GreasifyDelScript, &Remove Script From Repository...)
macros(GreasifyExportScriptList, E&xport Script List to Clipboard)
-
macros(GreasifySetDir, Set Userscripts &Directory)
macros(GreasifySBToggle, Toggle Greasify Statusbar Message)
-
macros(GreasifyApplyNow, Apply Greasify &Now)
}
### --- ###
And add this line to the Tools section of menus.cfg:
&Tools{
%ifplugin macros :Pro&xy :&User Agent ### ADD THIS LINE: ### :&Greasify ### --- ### - Userscript headers that don't conform to the "official" standard may prevent the script from being applied (see the greasemonkey XPI in subdir chrome/chromeFiles/content/template.user.js) Old Code Here Comments can be left here. |