Greasify Userscript Macro (Greasemonkey)



For The Current Version Go Here!




Directions and Limitations:

You must define the directory where you have your UserScripts. Change the variable $LOCALPATH in Greasify to the directory.

You must put the names of your userscripts into Greasify. These are defined with $x1, $x2, etc. WHILE seems to only allow 8 loops so that is why there are two different sets of $x variables. You can add more sets of $x variables while adjusting $xtotal to reflect the number of $x variables for that particular loop.

Also, 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/*
WOULD NOT WORK: http://*.yahoo.*/page.*

Finally, it is only set to check the first 4 @include vars in the userscript but this can be modified by changing the variable $howmany located in GMCodeChk.

Updated Nov 12, 2006: Added On/Off Toggle to the Tools menu so that Greasify can be enabled/disabled "on the fly". Also cleaned up some code.



First, add the specified line to OnLoad in macros.cfg:

OnLoad{
# General:
&Sync;

### ADD THIS LINE: ###
getpref(INT,"greasify.enabled")==0 ? 0:&Greasify;
### --- ###

}

Then add all this code at the bottom of macros.cfg:

Greasify{

### Set Path Here: ###
$LOCALPATH = "C:\\path\\to_scripts\\";

### Set # of @include lines to process: ###
$howmany = 4;
### --- ###

$HOST = hostname( $URL );
$x1 = "0001.user.js";
$x2 = "nameofscript.user.js";
$x3 = "0003.user.js";
$x4 = "0004.user.js";
$x5 = "0005.user.js";
$x6 = "0006.user.js";
$x7 = "0007.user.js";
$x8 = "0008.user.js";
$xmain = 1; $xtotal = 8;
while ( $xmain <= $xtotal ) &GMCodeChk;

$x1 = "97966963a64.user.js";
$x2 = "1234.user.js";
$x3 = "1003.user.js";
$x4 = "1004.user.js";
$x5 = "1005.user.js";
$x6 = "somename.user.js";
$x7 = "1007.user.js";
$xmain = 1; $xtotal = 7;
while ( $xmain <= $xtotal ) &GMCodeChk;
}


GreasifyToggle{
$VALUE = getpref(INT, "greasify.enabled");
$VALUE==0 ? setpref(INT, "greasify.enabled", 1):setpref(INT, "greasify.enabled", 0);
$VALUE==0 ? statusbar("Greasify Enabled"):statusbar("Greasify Disabled");
}


GMCodeChk{
$xnamer = $xmain==1 ? $xname = $x1:0; $xnamer = $xmain==2 ? $xname = $x2:0; $xnamer = $xmain==3 ? $xname = $x3:0;
$xnamer = $xmain==4 ? $xname = $x4:0; $xnamer = $xmain==5 ? $xname = $x5:0; $xnamer = $xmain==6 ? $xname = $x6:0;
$xnamer = $xmain==7 ? $xname = $x7:0; $xnamer = $xmain==8 ? $xname = $x8:0; $xnamer = $xmain==9 ? $xname = $x9:0;
$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;
&GCHostChk;
$hst = $hstrun; $hst2 = $hstrun2;
$ISUB2 = dirname($hst);
&GCChk2;
$xyz = 1;
while ($xyz < $howmany) &GCChkRun;
$z>0 ? injectJS($CONTENT):0;
$xmain = $xmain + 1;
}


GCChkRun{
&GCChk1;
&GCChk2;
$xyz = $xyz + 1;
}


GCChk1{
$hstrun = $hst2;
&GCHostChk;
$hst = $hstrun; $hst2 = $hstrun2;
$ISUB2 = dirname($hst);
}


GCChk2{
$HRLEN = length($HOSTREAL);
$HRLEN<=3 ? $HOSTREAL = -1:0;
$HOSTREAL==-1 ? 0:$HOST = $HOSTREAL;
$HOST2 = hostname( $ISUB2 );
$zz = $HOST==$HOST2 ? 1:0;
$z = $z + $zz;
}


GCHostChk{
$I2 = index($hstrun, "http:\/\/"); $I22 = substr($hstrun, $I2);
$ICHK = 7; $ICHK2 = substr($I22, 0, 8); $ICHKDOT = substr($I22, 0, 9);
$ICHK3B = $ICHK2=="http:\/\/\*" ? $ICHK = $ICHK + 1:0;
$ICHK3B = $ICHKDOT=="http:\/\/\*." ? $ICHK = $ICHK + 1:0;
$dotidx = 0; $HOSTREAL=-1;
$ICHK3B!=0 ? $dotidx = index($HOST, "."):0;
$ICHK3B!=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);
}

And add this line to menus.cfg:

&Tools{
%ifplugin macros
:Pro&xy
:&User Agent

### ADD THIS LINE: ###
macros(GreasifyToggle, Toggle Greasif&y)
### --- ###

-



Other notes: Internal Greasemonkey functions won't work in K-Meleon so if the script has something like GM_AddStyle it will not be recognized.


Back