# Greasify .6.2.4.20070318 (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); $activeURL = $URL; $xnameLEN = index($activeURL,"tp:\/\/")==-1 ? 0:$xnameLEN; 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 ); $USHstart = index($CONTENT, "\/\/ ==UserScript=="); $USHend = index($CONTENT, "\/\/ ==\/UserScript=="); $con2IDX = $USHend + 19; $activeURL = $URL; $con2 = substr($CONTENT,$con2IDX); $USHend = $USHend - $USHstart; $USHeader = substr($CONTENT, $USHstart, $USHend); $strAidx = index($USHeader, "\/\/ @include"); $strAidx = $strAidx + 11; $strA = substr($USHeader,$strAidx); $z = 0; $hstrun = $strA; $NS = index($USHeader, "\/\/ @name"); $NS = substr($USHeader,$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; &GCChk2; #$xyz = 1; $z<1? $xyz = 1: $xyz = $howmany; while ($xyz < $howmany) &GCChkRun; $z>=1 ? &GreasifyInjectJS:0; $xmain = $xmain + 1; $xname = getpref(STRING,$_Greasify_Custom.".userscript".$xmain); $xnameLEN = length($xname); } GreasifyInjectJS{ injectJS($con2); $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; $vchk = ""; $vchk = getpref(BOOL,$_Greasify_Custom.".copyclipboard"); $vchk==true ? setclipboard($con2) : 0; } GCChkRun{ $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; } GCChk2{ $checkBeginning = ""; $checkEnding = ""; $hstrun = "\^".$hstrun; $checkBeginning = index($hstrun,"\^\*"); $checkBeginning!=-1? $hstrun = gsub("\^\*.", "", $hstrun):0; $checkBeginning!=-1? $hstrun = gsub("\^\*", "", $hstrun):0; $checkBeginning==-1? $hstrun = substr($hstrun,1):0; $gocount = 6; $checkEnding = 0; $USidx = length($hstrun); $USidx = $USidx - 1; length($hstrun)<1? $gocount = 0:0; $checkBeginning!=-1? $checkBeginning = 1:0; $USidx>0? while ($gocount > 0) &GreasifyHostCheckHelper:0; $checkBeginning!=1? 0 : $checkEnding!=1? 0 : $theMeth = "BeginStarEndStar"; $checkBeginning!=1? 0 : $checkEnding==1? 0 : $theMeth = "BeginStarEnd"; $checkBeginning==1? 0 : $checkEnding==1? 0 : $theMeth = "BeginEnd"; $checkBeginning==1? 0 : $checkEnding!=1? 0 : $theMeth = "BeginEndStar"; $thirdStar = index($hstrun,"\*")!=-1 ? "true" : "false"; $activeURLsecEval = -1; $activeURLftpEval = -1; $activeURLeval = -1; $activeSecEvalIndex = -1; $activeftpEvalIndex = -1; $activeURLeval = index($activeURL, "http:\/\/"); $activeSecEvalIndex = index($activeURL, "https:\/\/"); $activeftpEvalIndex = index($activeURL, "ftp:\/\/"); $activeURLeval==-1 ? $activeURLsecEval = $activeSecEvalIndex:0; $activeURLeval!=-1 ? 0 : $activeURLsecEval!=-1 ? 0 : $activeURLftpEval = $activeftpEvalIndex; $activeURLeval!=-1? $activeURLStartLoc = $activeURLeval + 7:0; $activeURLsecEval!=-1? $activeURLStartLoc = $activeURLsecEval + 8:0; $activeURLftpEval!=-1? $activeURLStartLoc = $activeURLftpEval + 6:0; $activeURLeval==-1? 0 : $strAeval==-1? 0 : $thirdStar=="true"? 0:&gEvalAll; $activeURLeval==-1? 0 : $strAeval==-1? 0 : $thirdStar=="false"? 0:&gEvalAllAlt; $activeURLsecEval==-1? 0 : $secEval==-1? 0 : $thirdStar=="true"? 0:&gEvalAll; $activeURLsecEval==-1? 0 : $secEval==-1? 0 : $thirdStar=="false"? 0:&gEvalAllAlt; $activeURLftpEval==-1? 0 : $ftpEval==-1? 0 : $thirdStar=="true"? 0:&gEvalAll; $activeURLftpEval==-1? 0 : $ftpEval==-1? 0 : $thirdStar=="false"? 0:&gEvalAllAlt; } gEvalAll{ $activeURLLength = length($activeURL); $hstrunLength = length($hstrun); $theMeth=="BeginStarEndStar" ? &gEvalAll_BeginStarEndStar : 0; $theMeth=="BeginEndStar" ? &gEvalAll_BeginEndStar : 0; $theMeth=="BeginStarEnd" ? &gEvalAll_BeginStarEnd : 0; $theMeth=="BeginEnd" ? &gEvalAll_BeginEnd : 0; } gEvalAll_BeginStarEndStar{ index($activeURL, $hstrun)!=-1 ? $z = 1 : 0; } gEvalAll_BeginEndStar{ $activeURL = substr($activeURL, $activeURLStartLoc); $activeURL = substr($activeURL,0,$hstrunLength); $z = $activeURL==$hstrun ? 1 : 0 ; } gEvalALL_BeginStarEnd{ $activeURL = substr($activeURL, $activeURLStartLoc); $activeURLLength>$hstrunLength? $activeURLLength = $activeURLLength - $hstrunLength:0; $activeURLLength>$hstrunLength? $activeURL = substr($activeURL, $activeURLLength):0; $activeURLLength<$hstrunLength? $hstrunLength = $hstrunLength - $activeURLLength:0; $activeURLLength<$hstrunLength? $hstrun = substr($hstrun, $hstrunLength):0; $z = $activeURL==$hstrun ? 1 : 0 ; } gEvalAll_BeginEnd{ $activeURL = substr($activeURL, $activeURLStartLoc); $z = $activeURL==$hstrun ? 1 : 0 ; } gEvalAllAlt{ $midIDX = index($hstrun,"\*"); $mid1 = substr($hstrun,0,$midIDX); $midIDX = $midIDX + 1; $mid2 = substr($hstrun,$midIDX); $mid1Length = length($mid1); $mid2Length = length($mid2); $activeURLLength = length($activeURL); $hstrunLength = length($hstrun); $theMeth=="BeginStarEndStar" ? gEvalAllAlt_BeginStarEndStar:0; $theMeth=="BeginEndStar" ? gEvalAllAlt_BeginEndStar:0; $theMeth=="BeginStarEnd" ? gEvalAllAlt_BeginStarEnd:0; $theMeth=="BeginEnd" ? gEvalAllAlt_BeginEnd:0; } gEvalAllAlt_BeginStarEndStar{ index($activeURL, $mid1)!=-1 ? index($activeURL, $mid2)!=-1 ? $z = 1 : 0; } gEvalAllAlt_BeginEndStar{ $activeURLa = substr($activeURL,0,$mid1Length); $activeURLa==$mid1 ? index($activeURL, $mid2)!=-1 ? $z = 1 : 0; } gEvalAllAlt_BeginStarEnd{ $activeURLLength = $activeURLLength - $mid2Length:0; $activeURLb = substr($activeURL,$activeURLLength,$mid2Length):0; $activeURLb==$mid2 ? index($activeURL, $mid1)!=-1 ? $z = 1 : 0; } gEvalAllAlt_BeginEnd{ $activeURLa = substr($activeURL,0,$mid1Length):0; $activeURLLength = $activeURLLength - $mid2Length:0; $activeURLb = substr($activeURL,$activeURLLength,$mid2Length):0; $activeURLa==$mid1 ? $activeURLb==$mid2 ? $z = 1 : 0; } GreasifyHostCheckHelper{ $hstrunvchk = ""; $checkEnding = 0; $USidx = $USidx - 1; $hstrunvchk = substr($hstrun, $USidx); $chkHstRun = index($hstrunvchk,"\.\*"); $chkHstRun = index($hstrunvchk,"\/\*"); $USidx = $USidx + 1; $hstrunvchk = substr($hstrun, $USidx,1); $chkHstRun!=-1 ? $USidx = $USidx - 1:0; $hstrunvchk=="\*" ? $hstrun = substr($hstrun, 0, $USidx):0; $hstrunvchk=="\*" ? $checkEnding = 1:0; $hstrunvchk=="\*" ? $gocount = 0:0; $gocount>0 ? $gocount = $gocount - 1:0; $USidx = $USidx - 1; } GCHostChk{ $strAeval = -1; $ftpEval = -1; $secEval = -1; $strStartLoc = -1; $more = -1; $strAeval = index($hstrun, "http:\/\/"); $secEvalIndex = index($hstrun, "https:\/\/"); $strAeval==-1 ? $secEval = $secEvalIndex:0; $ftpEvalIndex = index($hstrun, "ftp:\/\/"); $strAeval!=-1 ? 0 : $secEval!=-1 ? 0 : $ftpEval = $ftpEvalIndex; $strAeval!=-1? $strStartLoc = $strAeval + 7:0; $secEval!=-1? $strStartLoc = $secEval + 8:0; $ftpEval!=-1? $strStartLoc = $ftpEval + 6:0; $strStartLoc!=-1? $hstrun = substr($hstrun, $strStartLoc):0; $includeAgain = index($hstrun,"\/\/ @include"); $hstrun2 = 0; $includeAgain!=-1? $hstrun = substr($hstrun,0,$includeAgain):0; $includeAgain!=-1? $includeAgain = $includeAgain + 11:0; $includeAgain!=-1? $hstrun2 = substr($hstrun,$includeAgain):0; $more = index($hstrun, "\/\/ "); $more!=-1? $hstrun = substr($hstrun,0,$more):0; } 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); } GreasifyViewScript{ $scrnum = ""; $LOCALPATH = getpref(STRING,$_Greasify_Custom.".directory"); &GreasifyScriptsActive; $scrnum = prompt("Enter script number to view:", "View Script - Selection", ""); $scrnum!="" ? &GreasifyViewScript2:0; $scrnum!="" ? open($scrtoView):0; } GreasifyViewScript2{ $scrtoView = getpref(STRING,$_Greasify_Custom.".userscript".$scrnum); $scrtoView = $LOCALPATH."\\".$scrtoView; $scrtoView = gsub("\\", "\/", $scrtoView); $scrtoView = "file\:\/\/\/".$scrtoView; } GreasifyVerifyScript{ $vchk = ""; $vchk = getpref(BOOL,$_Greasify_Custom.".copyclipboard"); $vchk==false ? setpref(BOOL,$_Greasify_Custom.".copyclipboard",TRUE) : setpref(BOOL,$_Greasify_Custom.".copyclipboard",FALSE); menuchecked=getpref(BOOL,$_Greasify_Custom.".copyclipboard"); } ############################## # ----- 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,separator,"E&xport Script List to Clipboard"); setmenu($_gmenu,macro,"E&xport Script List to Clipboard",GreasifyExportScriptList); setmenu($_gmenu,macro,"View Script Source In &Browser",GreasifyViewScript); setmenu($_gmenu,separator,"Set Userscripts &Directory"); setmenu($_gmenu,macro,"Set Userscripts &Directory",GreasifySetDir); setmenu($_gmenu,macro,"Copy Applied Scripts To Clipboard For Testing",GreasifyVerifyScript); setmenu($_gmenu,macro,"Toggle Greasify Statusbar &Message",GreasifySBToggle); setmenu($_gmenu,separator,"Apply Greasify &Now"); setmenu($_gmenu,macro,"Apply Greasify &Now",GreasifyApplyNow); rebuildmenu($_gmenu); } _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;";