AdBlock Locus

AdBlock Locus provides a GUI for K-Meleon's built-in adblocker. The extension is distributed as a single K-Meleon macro module (.kmm) file. Kmm macros are a type of plain text extension exclusive to K-Meleon. They're human-readable and can be opened in any text editor. The full source is below:

Full Source Code

# -----------------------------------------------------------------------------------
# AdBlock Locus 2.1
# -----------------------------------------------------------------------------------
#
# AdBlock Locus provides a graphical user interface or GUI for K-Meleon's built-in 
# adblocking (BAB) features. All of the BAB's blocking abilities are handled by the
# "adblock.dll" Kplugin. AdBlock Locus provides menus, buttons, and preference 
# dialogs to set up the BAB. It defaults to a custom blocklist designed specifically
# for K-Meleon around the limitations of the BAB.
#
# -----------------------------------------------------------------------------------
#
# KM forum: 		  http://kmeleonbrowser.org/forum/read.php?9,156032
# Website:			  https://rjjiii.github.io/K-Meleon/AdBlockLocus/
# Dependencies:		  K-Meleon/kplugins/adblock.dll
# Preferences:		  "kmeleon.plugins.adblock.subscriptions" (list of URLs for rules)
#	(plugin)          "kmeleon.plugins.adblock.logging", "kmeleon.plugins.adblock.disabled",
# Preferences:		  "kmeleon.plugins.adblock.rules.auto", "kmeleon.plugins.adblock.log.auto", 
# 	(macro)           "kmeleon.plugins.adblock.rules.days", "kmeleon.plugins.adblock.log.days",
#                     "kmeleon.plugins.adblock.rules.next", "kmeleon.plugins.adblock.log.next",
#                     "kmeleon.plugins.adblock.rules.cleared", "kmeleon.plugins.adblock.log.cleared",
#				      "kmeleon.plugins.adblock.subs.core", "kmeleon.plugins.adblock.subs.easylist",
#				      "kmeleon.plugins.adblock.subs.customcheck", "kmeleon.plugins.adblock.subs.custom",
#				      "kmeleon.plugins.adblock.subs.french", "kmeleon.plugins.adblock.subs.spanish",
#				      "kmeleon.plugins.adblock.subs.german", "kmeleon.plugins.adblock.subs.chinese",
#				      "kmeleon.plugins.adblock.subs.russian",	"kmeleon.plugins.adblock.subs.cntblock",
#				      "kmeleon.plugins.adblock.subs.privacy", "kmeleon.plugins.adblock.subs.facebook",
#				      "kmeleon.plugins.adblock.newsubscriptions", "kmeleon.plugins.adblock.rulesnew",
# Preferences:		  "kmeleon.plugins.sessions.autoload", "kmeleon.extensions.restart.autoload",
#	(session)		  "kmeleon.plugins.sessions.openStart", "kmeleon.extensions.restart.openStart",
#					  "kmeleon.plugins.sessions.ask_autoload", "kmeleon.extensions.restart.ask_autoload",
#					  "kmeleon.extensions.restart",
# Files:		      adblock.txt, adblock.log, (created in profile by adblock.dll)
#					  adblockmacro.log (created in profile by macro)
# -----------------------------------------------------------------------------------
#
# AdBlock Locus is maintained by RJJ III and includes code from the following macro 
# by JamesD, rodocop, & siria:
# http://kmeleonbrowser.org/forum/read.php?9,135175
#
# -----------------------------------------------------------------------------------

_Adblockplugin_disable {
menuchecked= getpref( BOOL, "kmeleon.plugins.adblock.disabled") ;
macroinfo= _("Checked: plugin disabled. Or not checked: plugin enabled.");
macros("_Adblockplugin_toggle");
}

_Adblockplugin_subscriptions {
macroinfo=_("View the list of subscriptions.");
menuchecked=statusbar( _("View and edit the blocking list and log.") );
$_Adblockplugin_sources  = getpref( STRING, "kmeleon.plugins.adblock.subscriptions") ; 
$_Adblockplugin_sources = gsub( "|", "\n\n", $_Adblockplugin_sources );
alert($_Adblockplugin_sources, _("Adblock Subscriptions"));
}

_Adblockplugin_logging {
menuchecked= getpref( BOOL, "kmeleon.plugins.adblock.logging");
macroinfo= _("Toggle logging. Checked is active.");
togglepref( BOOL, "kmeleon.plugins.adblock.logging");
$__adblogging = getpref(BOOL, "kmeleon.plugins.adblock.logging");
$__adblogging ? $__adblogging = _("TRUE") : $__adblogging = _("FALSE");
$_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Logging set to ").$__adblogging._(" by user.");
appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
}

_Adblockplugin_FileNotFound{
alert(sub("%s",$acfg_File,_("The file %s could not be found.")),_(Adblock),EXCLAIM);
}

# Rather than giving an error message in prompt, this creates the message in adblock.txt
_Adblockplugin_FileNotFoundRules{
$_file=getfolder(ProfileFolder)."\\adblock.txt";
$_x=appendfile($_file, "! No rules were found. If this is your first time running AdBlock Locus, choose Refresh Rules from the AdBlock Locus menu to download subscriptions and start blocking ads. You can select which lists of blocking rules you want to use by selecting Tools > AdBlock Locus> Subscriptions and toggling subscriptions. You should use at least one base subscription like Easylist or Core. You can add supplemental subscriptions for different languages and filters.");
$__path=getfolder(ProfileFolder)."\\".$ARG.".txt";
$__data=readfile($__path);
if ($__data=="") {&_Adblockplugin_FileNotFound;
 } else {
 $ext="txt"; &getSecureExtensionHandler;
 exec(sub("%1",$__path,$cmdline));
 }
}

_Adblockplugin_rules {
macroinfo=_("Open the rules in a text editor.");
menugrayed = getpref(BOOL, "kmeleon.plugins.adblock.rules.deleted");
$__path=getfolder(ProfileFolder)."\\".$ARG.".txt";
$__data=readfile($__path);
if ($__data=="") {&_Adblockplugin_FileNotFoundRules;
 } else {
 $ext="txt"; &getSecureExtensionHandler;
 exec(sub("%1",$__path,$cmdline));
 }
}

_Adblockplugin_user_rules {
macroinfo=_("Open the rules in a text editor.");
$__path=getfolder(ProfileFolder)."\\".$ARG.".txt";
$__data=readfile($__path);
if ($__data=="") {&_Adblockplugin_FileNotFoundUserRules;
 } else {
 $ext="txt"; &getSecureExtensionHandler;
 exec(sub("%1",$__path,$cmdline));
 }
}

#Create the user's custom rules file if it doesn't exist yet
_Adblockplugin_FileNotFoundUserRules{
$_file=getfolder(ProfileFolder)."\\adblock_user.txt";
$_x=appendfile($_file, "! AdBlock Locus custom rules subscription: \n! The macro handles custom rules as a subscription to this file. \n! Refresh the rules or delete 'adblock.txt' to reload these rules. \n! Lines beginning with a '!' are comments. \n! Rule syntax:  https://adblockplus.org/filter-cheatsheet \n! Support:      http://kmeleonbrowser.org/forum/read.php?19,156032");
$__path=getfolder(ProfileFolder)."\\".$ARG.".txt";
$__data=readfile($__path);
if ($__data=="") {&_Adblockplugin_FileNotFound;
 } else {
 $ext="txt"; &getSecureExtensionHandler;
 exec(sub("%1",$__path,$cmdline));
 }
}



_Adblockplugin_logs {
macroinfo=_("Open the log file (adblock.log) in a text editor.");
menugrayed = getpref(BOOL, "kmeleon.plugins.adblock.log.cleared"); 
$__path=getfolder(ProfileFolder)."\\".$ARG.".log";
$__data=readfile($__path);
if ($__data=="") {&_Adblockplugin_FileNotFound;
 } else {
 $ext="log"; &getExtensionHandler;
 exec(sub("%1",$__path,$cmdline));
 }
}

_Adblockplugin_clear_rules {
macroinfo=_("Delete the current rules (adblock.txt).");
menugrayed = getpref(BOOL, "kmeleon.plugins.adblock.rules.deleted");
# Delete prefs first to avoid duplication bug
delpref( "kmeleon.plugins.adblock.subscriptions" );
$__path=getfolder(ProfileFolder)."\\adblock.txt" ;
$__return = deletefile($__path);
if ($__return) {
  logmsg(_("AdBlock Locus clear rules succeded. code = ").$__return, warning);
  setpref(BOOL, "kmeleon.plugins.adblock.rules.deleted", true); 
  $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("The rules file, adblock.txt, was deleted by user.");
  appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
  macros("_Adblockplugin_toolbar_set");
  } else {
  logmsg(_("AdBlock Locus clear rules failed. code = ").$__return, error);
  }  
# Restart KM on next startup to load rules:
}

_Adblockplugin_clear_log {
macroinfo=_("Delete the current log file (adblock.log).");
menugrayed = getpref(BOOL, "kmeleon.plugins.adblock.log.cleared");  
$__path=getfolder(ProfileFolder)."\\adblock.log" ;
$__return = deletefile($__path);
if ($__return) {
  logmsg(_("AdBlock Locus clear log succeded. code = ").$__return , warning);
  setpref(BOOL, "kmeleon.plugins.adblock.log.cleared", true);
  $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("The log file, adblock.log, was deleted by user.");
  appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
  } else {
  logmsg(_("AdBlock Locus clear log failed. code = ").$__return , error);
  }  
}

_Adblockplugin_Aclear_rules {
menuchecked= getpref( BOOL, "kmeleon.plugins.adblock.rules.auto") ;
macroinfo= _("Toggle automatic update of rules from subscriptions.");
togglepref( BOOL, "kmeleon.plugins.adblock.rules.auto");
$__abauto = getpref(BOOL, "kmeleon.plugins.adblock.rules.auto");
$__abauto ? $__abauto =_("be AUTOMATICALLY") : $__abauto =_("NOT be") ; 
logmsg(_("AdBlock Locus automatic update of blocking rules was set to ").$__abauto.".", warning);
statusbar(_("The AdBlock plugin rules will ").$__abauto." deleted and updated.");
}    

_Adblockplugin_Aclear_rules_I {
menuchecked=statusbar( _("Delete logs or rules automatically. New rules are downloaded after deletion.") );
macroinfo= _("Set the interval for automatic updates.");
$_Adblockplugin_rule_days=getpref(INT, "kmeleon.plugins.adblock.rules.days");
$__abtype = _("rules") ; $__abtypeL = "rules" ;
macros("_Adblockplugin_Aclear_interval");
}

_Adblockplugin_Aclear_log {
menuchecked= getpref( BOOL, "kmeleon.plugins.adblock.log.auto") ;
macroinfo= _("Toggle automatic deletion of logs.");
togglepref( BOOL, "kmeleon.plugins.adblock.log.auto");
$__abauto = getpref(BOOL, "kmeleon.plugins.adblock.log.auto");
$__abauto ? $__abauto =_("be AUTOMATICALLY") : $__abauto =_("NOT be") ; 
logmsg(_("Adblock Locus automatic deletion of blocking log is ").$__abauto.".", warning);
statusbar(_("The AdBlock plugin log will ").$__abauto." deleted.");
}

_Adblockplugin_Aclear_log_I {
macroinfo= _("Set the interval for the automatic deletion logs.");
$_Adblockplugin_log_days=getpref(INT, "kmeleon.plugins.adblock.log.days");
$__abtype = _("log");  $__abtypeL = "log" ; 
macros("_Adblockplugin_Aclear_interval");
}

_Adblockplugin_Aclear_interval {
if ( $__abtypeL == "rules" ) {
   $__abint = $_Adblockplugin_rule_days; }else{ $__abint = $_Adblockplugin_log_days; }
$__abintxt1 = _("The unit of time used for\nautomatic actions is a day.\n\nThe value must be at least 1 day.") ;
$__abintxt2 = _("The current schedule for deleting the \n").$__abtype._(" is:\t").$__abint." days.";
$__abintxt3 = _("Do you wish to change the number of days?");  
$__abcf = confirm( $__abintxt1."\n".$__abintxt2."\n\n".$__abintxt3 , _("AdBlock Locus ").$__abtype._(" deletion interval") ,YESNO, QUESTION );
if ($__abcf == "YES") { macros("_Adblockplugin_Aclear_int_chg") ;
  }else{ $__abp = $__abint;   macros("_Adblockplugin_Aclear_InvSet"); }
}

_Adblockplugin_Aclear_int_chg {
$__abp = prompt( _("Enter number of days between deletions."), _("Adblock ").$__abtype._(" days selection.") );
$__abp > 0 ? macros("_Adblockplugin_Aclear_verify") : macros("_Adblockplugin_Aclear_OutRange");
}

_Adblockplugin_Aclear_OutRange {
alert(_("The value is out of range. \nIt must be greater than zero"), _("Adblock interval"), EXCLAIM);
macros("_Adblockplugin_Aclear_int_chg");
}

_Adblockplugin_Aclear_verify {  # ask whether to use proposed value
$__abintxt2 = _("The proposed value for deleting \n").$__abtype._(" is\t").$__abp._(" days.");
$__abintxt3 = _("Do you wish to use the proposed value?");  
$__abcf = confirm( $__abintxt1."\n".$__abintxt2."\n\n".$__abintxt3 , _("Adblock ").$__abtype._(" new days verification.") ,YESNO, QUESTION );
$__abcf == "YES" ? &_Adblockplugin_Aclear_InvSet : &_Adblockplugin_Aclear_retryexit ; 
}

_Adblockplugin_Aclear_InvSet {
# $UNIXTIME = time(); 86400 = 1 day
$__abnext = ($__abp * 86400) + time() ;
setpref( INT, "kmeleon.plugins.adblock.".$__abtypeL.".next", $__abnext);
$__abint == $__abp ? 0 : setpref( INT, "kmeleon.plugins.adblock.".$__abtypeL.".days", $__abp );
statusbar(_("The pref ")."'kmeleon.plugins.adblock.".$__abtypeL.".next'"._(" set with days = ").$__abp.".");
logmsg(_("The pref ")."'kmeleon.plugins.adblock.".$__abtypeL.".next'"._(" set with days = ").$__abp.".", warning);
$_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("The pref ")."'kmeleon.plugins.adblock.".$__abtypeL.".next'"._(" set with days = ").$__abp.".";
appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
macros("_Adblockplugin_BuildMenuAs");
}

_Adblockplugin_Aclear_retryexit {
$__sbrty = confirm( _("Do you wish to retry setting \n the days value or \ncancel this operation?") , _("Adblock ").$__abtype._(" new days entry."), RETRYCANCEL , QUESTION );
$__sbrty == "RETRY" ? &_Adblockplugin_Aclear_int_chg :0;
}

_Adblockplugin_macro_log {
macroinfo=_("View the macro's log file.");
$__path=getfolder(ProfileFolder)."\\".$ARG.".log";
$__data=readfile($__path);
if ($__data=="") {&_Adblockplugin_FileNotFound;
 } else {
 $ext="log"; &getExtensionHandler;
 exec(sub("%1",$__path,$cmdline));
 }
}

_Adblockplugin_DayCheck {  ## DayCheck happens OnQuit.  Logmsg() items are lost
$_adblockmacro_text = "";  ## set macrotext value to empty -  global over both rules and log
# Check for adblock.txt before closing because it's loaded the next time KM opens.
$__path=getfolder(ProfileFolder)."\\adblock.txt";
if (fileexists($__path)) {
	delpref("kmeleon.plugins.adblock.rules.deleted");
}
getpref( BOOL, "kmeleon.general.offline") ? &_Adblockplugin_DayCheck3 : &_Adblockplugin_DayCheck2 ;   
}

_Adblockplugin_DayCheck2 {
if ((getpref(BOOL,"kmeleon.plugins.adblock.rules.auto")) and ( time() > getpref(INT,"kmeleon.plugins.adblock.rules.next"))) {
   $__path=getfolder(ProfileFolder)."\\adblock.txt";
   ## remove existing adblock.txt file
   if (fileexists($__path)) {
     $__return = deletefile($__path);
     if ($__return) {
       $_adblockmacro_text = $_adblockmacro_text ."\n". date( "%Y-%m-%d %H:%M" )." >> "._("Adblock.txt file deleted automatically.");
       } else {
       $_adblockmacro_text = $_adblockmacro_text ."\n". date( "%Y-%m-%d %H:%M" )." >> "._("Adblock clear rules (adblock.txt) failed. code = ").$__return;
       }
     }
     ## increment the rules.next by days
     $__abp = getpref(INT, "kmeleon.plugins.adblock.rules.days");
     $__abnext = ($__abp * 86400) + time() ;
     setpref(INT, "kmeleon.plugins.adblock.rules.next", $__abnext); 
     $_adblockmacro_text = $_adblockmacro_text ."\n". date( "%Y-%m-%d %H:%M" )." >> "._("Adblock next rules delete was set to ").$__abnext." for ". date( "%Y-%m-%d %H:%M",$__abnext );
}
if ((getpref(BOOL,"kmeleon.plugins.adblock.log.auto")) and ( time() > getpref(INT,"kmeleon.plugins.adblock.log.next"))) {
   $__path=getfolder(ProfileFolder)."\\adblock.log";
   ## remove existing adblock.log file
   if (fileexists($__path)) {
     $__return = deletefile($__path);
     if ($__return) {
       $_adblockmacro_text = $_adblockmacro_text ."\n". date( "%Y-%m-%d %H:%M" )." >> "._("Adblock.log file deleted automaticly.");
       } else {
       $_adblockmacro_text = $_adblockmacro_text ."\n". date( "%Y-%m-%d %H:%M" )." >> "._("Adblock clear log (adblock.log) failed. code = ").$__return;
       }
     }
     ## increment the log.next by days
     $__abp = getpref(INT, "kmeleon.plugins.adblock.log.days");
     $__abnext = ($__abp * 86400) + time() ;
     setpref(INT, "kmeleon.plugins.adblock.log.next", $__abnext); 
     $_adblockmacro_text = $_adblockmacro_text ."\n". date( "%Y-%m-%d %H:%M" )." >> "._("Adblock next log delete was set to ").$__abnext." for ". date( "%Y-%m-%d %H:%M",$__abnext );
}
macros("_Adblockplugin_DayCheck3") ;
}

_Adblockplugin_DayCheck3 {
$_BABmacro_path = getfolder(ProfileFolder)."\\adblockmacro.log";
length($_adblockmacro_text) > 1 ? appendfile($_BABmacro_path, $_adblockmacro_text) : 0; ## a single file operation for daycheck
}

_Adblockplugin_QV {
macroinfo=_("Display current settings.");
$__adbQrunning = getpref(BOOL, "kmeleon.plugins.adblock.disabled");
$__adbQrunning ? $__adbQrunning = _("TRUE") : $__adbQrunning = _("FALSE");
$__adbQlogauto = getpref(BOOL, "kmeleon.plugins.adblock.log.auto");
$__adbQlogauto ? $__adbQlogauto = _("TRUE") : $__adbQlogauto = _("FALSE");
$__adbQlogclear = getpref(BOOL, "kmeleon.plugins.adblock.log.cleared");
$__adbQlogclear ? $__adbQlogclear = _("TRUE") : $__adbQlogclear = _("FALSE");
$__adbQloginterval = getpref(INT, "kmeleon.plugins.adblock.log.days");
$__adbQlognext = getpref(INT, "kmeleon.plugins.adblock.log.next");
$__adbQlogging = getpref(BOOL, "kmeleon.plugins.adblock.logging");
$__adbQlogging ? $__adbQlogging = _("TRUE") : $__adbQlogging = _("FALSE");
$__adbQruleauto = getpref(BOOL, "kmeleon.plugins.adblock.rules.auto");
$__adbQruleauto ? $__adbQruleauto = _("TRUE") : $__adbQruleauto = _("FALSE");
$__adbQruleclear = getpref(BOOL, "kmeleon.plugins.adblock.rules.cleared");
$__adbQruleclear ? $__adbQruleclear = _("TRUE") : $__adbQruleclear = _("FALSE");
$__adbQruleinterval = getpref(INT, "kmeleon.plugins.adblock.rules.days");
$__adbQrulenext = getpref(INT, "kmeleon.plugins.adblock.rules.next");
$__adbQtxt = fileexists(getfolder(ProfileFolder))."\\adblock.txt";
$__adbQtxt ? $__adbQtxt = _("AVAILABLE") : $__adbQtxt = _("NOT AVAILABLE");
$__adbQlog = getfolder(ProfileFolder)."\\adblock.log";
$__adbQlog ? $__adbQlog = _("AVAILABLE") : $__adbQlog = _("NOT AVAILABLE");
#	$__adbQicon = getpref(BOOL, "kmeleon.plugins.adblock.icons.alternate");
#	$__adbQicon ? $__adbQicon = _("TRUE") : $__adbQicon = _("FALSE"); 
$__adbQtext = _("Plugin disabled is ").$__adbQrunning;
$__adbQtext = $__adbQtext ."\n". _("Logging is ").$__adbQlogging;
$__adbQtext = $__adbQtext ."\n". _("File adblock.txt is ").$__adbQtxt;
$__adbQtext = $__adbQtext ."\n". _("File adblock.log is ").$__adbQlog;
#	$__adbQtext = $__adbQtext ."\n". _("Displaying alternate icons is ").$__adbQicon;
$__adbQtext = $__adbQtext ."\n\n". _("Automatics");
$__adbQtext = $__adbQtext ."\n". _("Auto delete rules is ").$__adbQruleauto;
$__adbQtext = $__adbQtext ."\n". _("Interval for rules is ").$__adbQruleinterval._(" days.");
$__adbQtext = $__adbQtext ."\n". _("Next date for rules is ").date("%Y-%m-%d %H:%M", $__adbQrulenext);
$__adbQtext = $__adbQtext ."\n". _("Auto delete log is ").$__adbQlogauto;
$__adbQtext = $__adbQtext ."\n". _("Interval for log is ").$__adbQloginterval._(" days.");
$__adbQtext = $__adbQtext ."\n". _("Next date for log is ").date("%Y-%m-%d %H:%M", $__adbQlognext);
alert($__adbQtext, _("Adblock Settings"), INFO);
}

_Adblockplugin_ICONS {
#	Former macro to invert icons.
}


_Adblockplugin_allowDomain {
macroinfo= _("Add an exception to allow all items on this domain.");
$_ABL_domain = hostname($URLBAR);  
$_line="\n\n@@||";
$_line=$_line.$_ABL_domain."^$document\n\n";
$_line = prompt("Click OK to add this exception to your custom rules in adblock_user.txt.","Create Exception",$_line);
if ($_line){
	$_file=getfolder(ProfileFolder)."\\adblock.txt";
	$_x=appendfile($_file, $_line);
	$_allowConfirm="An exception was made to allow items on " . $_ABL_domain ." \n\nIt will take effect after you restart K-Meleon.";
	$_file2=getfolder(ProfileFolder)."\\adblock_user.txt";
	$_x=appendfile($_file2, $_line);
	if ($_x==false) alert(_("AdBlock Locus cannot write to adblock.txt rules."),_("Error"),EXCLAIM);
	alert($_allowConfirm, "AdBlock Locus");
	}
}

_Adblockplugin_allowAddress {
macroinfo= _("Add an exception for the current contents of the URL bar.");
$_line="\n\n@@";
$_line=$_line.$URLBAR."\n\n";
$_file=getfolder(ProfileFolder)."\\adblock.txt";
$_x=appendfile($_file, $_line);
$_allowConfirm="An exception was made for " . $URLBAR ." \n\nIt will be allowed after you restart K-Meleon.";
$_file2=getfolder(ProfileFolder)."\\adblock_user.txt";
$_x=appendfile($_file2, $_line);
if ($_x==false) alert(_("AdBlock Locus cannot write to adblock.txt rules."),_("Error"),EXCLAIM);
alert($_allowConfirm, "Adblock Locus");
}

_Adblockplugin_toggle {
togglepref( BOOL, "kmeleon.plugins.adblock.disabled") ;
macros("_Adblockplugin_toolbar_set");
$__adbdisabled = getpref(BOOL, "kmeleon.plugins.adblock.disabled");
$__adbdisabled ? $__adbdisabled = _("DISABLED") : $__adbdisabled = _("ENABLED");
$_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Ad blocking is ").$__adbdisabled._(" by user.");
appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
statusbar(_("Ad blocking is ").$__adbdisabled);
&_ABL_Sync_PrivacyBar;
}



_Adblockplugin_About{
menuchecked=statusbar( _("AdBlock Locus: GUI for K-Meleon's ad-blocking plugin.") );
macroinfo= _("Display information, version number, and copyright for AdBlock Locus.");
alert(_("AdBlock Locus enables access to K-Meleon's built-in adblocker. The built-in adblocker is contained in the adblock kplugin and does not have a graphical interface. The adblock plugin supports most blocking syntax and can use subscriptions to any text-based list of blocking rules.

AdBlock Locus was created by the community and is not endorsed by K-Meleon or AdBlock Plus. For development information and support visit the K-Meleon forums. AdBlock Locus has been distributed freely and is provided AS IS, WITHOUT WARRANTY OF ANY KIND. In no event shall the authors be liable for any claim, damage, or other liability.

Special thanks to: Dorian, James D, Siria, Rodocop, and the K-Meleon community.

Version 2.1

Copyright R.J.J. III © 2022, all rights reserved."),_("AdBlock Locus 2.1"), INFO);
}



# -----------------------------------------------------------------------------------
# Subscriptions
# -----------------------------------------------------------------------------------

#Setting up subscriptions from menu:
_Adblockplugin_Sub_Core {
macroinfo= _("A lightweight block list for AdBlock Locus. *Recommended Base*");
menuchecked=getpref(BOOL, "kmeleon.plugins.adblock.subs.core");
togglepref(BOOL, "kmeleon.plugins.adblock.subs.core");
$_ABL_Sub_MacroLog=getpref(BOOL, "kmeleon.plugins.adblock.subs.core");
if($_ABL_Sub_MacroLog){
	$_Adblockplugin_Sub_Logging="enabled.";
	}
else{
	$_Adblockplugin_Sub_Logging="disabled.";
	}
$_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("The AdBlock Locus Core base subscription was ".$_Adblockplugin_Sub_Logging);
appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
&_Adblockplugin_Sub_Set;
}

_Adblockplugin_Sub_Easylist {
macroinfo= _("A popular blocklist often used with AdBlock Plus. A heavier alternative to AdBlock Locus Core.");
menuchecked=getpref(BOOL, "kmeleon.plugins.adblock.subs.easylist");
togglepref(BOOL, "kmeleon.plugins.adblock.subs.easylist");
$_ABL_Sub_MacroLog=getpref(BOOL, "kmeleon.plugins.adblock.subs.easylist");
if($_ABL_Sub_MacroLog){
	$_Adblockplugin_Sub_Logging="enabled.";
	}
else{
	$_Adblockplugin_Sub_Logging="disabled.";
	}
$_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("The Easylist base subscription was ".$_Adblockplugin_Sub_Logging);
appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
&_Adblockplugin_Sub_Set;
}

_Adblockplugin_Sub_Sup {
macroinfo= _("Supplemental subscription.");
menuchecked=getpref(BOOL, "kmeleon.plugins.adblock.subs.".$ARG);
togglepref(BOOL, "kmeleon.plugins.adblock.subs.".$ARG);
$_ABL_Sub_MacroLog=getpref(BOOL, "kmeleon.plugins.adblock.subs.".$ARG);
if($_ABL_Sub_MacroLog){
	$_Adblockplugin_Sub_Logging="enabled.";
	}
else{
	$_Adblockplugin_Sub_Logging="disabled.";
	}
$_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("The ".$ARG." subscription was ".$_Adblockplugin_Sub_Logging);
appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
&_Adblockplugin_Sub_Set;
}

_Adblockplugin_Sub_Custom {
macroinfo= _("Add the URL for an additional subscription.");
# One variable below for checked, another for the subscription in string form
menuchecked=getpref(BOOL,"kmeleon.plugins.adblock.subs.customcheck");
$_Adblockplugin_Custom_Input="";
$_Adblockplugin_Custom_Input=$_Adblockplugin_Custom_Input.getpref(STRING,"kmeleon.plugins.adblock.subs.custom");
$_Adblockplugin_Custom_Input=prompt("Copy and paste a subscription URL below.","Custom subscription", $_Adblockplugin_Custom_Input);

# Don't clear if no input. K-Meleon treats "Cancel" as a blank input.
if($_Adblockplugin_Custom_Input!="")
{setpref(STRING, "kmeleon.plugins.adblock.subs.custom", $_Adblockplugin_Custom_Input);
&_Adblockplugin_Sub_Custom_Check;
alert(_("Your custom subscription has been updated to:\n\n".$_Adblockplugin_Custom_Input."\n\nSelect Refresh Rules in the AdBlock Locus menu to re-start K-Meleon and use the new blocklist."),_("Custom Subscription"));
$_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("The custom subscription section was updated to: ".$_Adblockplugin_Custom_Input);
appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
&_Adblockplugin_Sub_Set;
}
else{
&_Adblockplugin_Sub_Custom_Check;
alert(_("No URL was entered. Your custom subscription below was unchanged:\n\n".getpref(STRING, "kmeleon.plugins.adblock.subs.custom")."\n\nTo disable the custom subscription enter a blank space as a new custom subscription."),_("Custom Subscription"), INFO);}
}

# Only place a checkmark if the contents of custom string are long enough to be a URL.
_Adblockplugin_Sub_Custom_Check {
$_Adblockplugin_Check=getpref(STRING, "kmeleon.plugins.adblock.subs.custom");
if(length($_Adblockplugin_Check)>17)
{setpref(BOOL,"kmeleon.plugins.adblock.subs.customcheck",true);}
else{
setpref(BOOL,"kmeleon.plugins.adblock.subs.customcheck",false);
}

}


_Adblockplugin_Sub_Set {
macroinfo= _("Set the above subscriptions to download on next refresh.");
$_Adblockplugin_NewSubs="";

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.core"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://rjjiii.github.io/K-Meleon/AdBlockLocus/Core.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.easylist"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://easylist-downloads.adblockplus.org/easylist_noelemhide.txt|";}

#	if(getpref(BOOL, "kmeleon.plugins.adblock.subs.fallback"))
#	{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://rjjiii.github.io/K-Meleon/AdBlockLocus/Fallback.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.french"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://filters.adtidy.org/extension/ublock/filters/113_optimized.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.spanish"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://filters.adtidy.org/extension/ublock/filters/9_optimized.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.german"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://filters.adtidy.org/extension/ublock/filters/107_optimized.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.chinese"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://filters.adtidy.org/extension/ublock/filters/104_optimized.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.russian"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://filters.adtidy.org/extension/ublock/filters/1_optimized.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.cntblock"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://easylist-downloads.adblockplus.org/cntblock.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.privacy"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://filters.adtidy.org/extension/ublock/filters/118_optimized.txt|";}

if(getpref(BOOL, "kmeleon.plugins.adblock.subs.facebook"))
{$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."https://secure.fanboy.co.nz/fanboy-antifacebook.txt|";}

$_Adblockplugin_usersub=getfolder(ProfileFolder)."\\adblock_user.txt";
$_Adblockplugin_usersub="file://".gsub("\\","/",$_Adblockplugin_usersub);
$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs.$_Adblockplugin_usersub."|";

$_Adblockplugin_NewSubs=$_Adblockplugin_NewSubs."|".getpref(STRING, "kmeleon.plugins.adblock.subs.custom");

$_Adblockplugin_Alert ="";
$_Adblockplugin_Alert=$_Adblockplugin_NewSubs;
setpref(STRING, "kmeleon.plugins.adblock.subscriptions", $_Adblockplugin_Alert ) ;
setpref(STRING, "kmeleon.plugins.adblock.newsubscriptions", $_Adblockplugin_Alert ) ;
&_Adblockplugin_subscriptions;
}

_Adblockplugin_Sub_Restore{
macroinfo=_("Restore subscriptions to their default configuration.");
menuchecked=statusbar( _("Set up blocking rules.") );
setpref(BOOL, "kmeleon.plugins.adblock.subs.core", true); 
delpref("kmeleon.plugins.adblock.subs.easylist");
delpref("kmeleon.plugins.adblock.subs.french");
delpref("kmeleon.plugins.adblock.subs.spanish");
delpref("kmeleon.plugins.adblock.subs.german");
delpref("kmeleon.plugins.adblock.subs.chinese");
delpref("kmeleon.plugins.adblock.subs.russian");
delpref("kmeleon.plugins.adblock.subs.cntblock");
delpref("kmeleon.plugins.adblock.subs.privacy");
delpref("kmeleon.plugins.adblock.subs.facebook");
delpref("kmeleon.plugins.adblock.subs.customcheck");
delpref("kmeleon.plugins.adblock.subs.custom");
&_Adblockplugin_Sub_Set;}



# -----------------------------------------------------------------------------------
# Initial Setup
# -----------------------------------------------------------------------------------
_Adblockplugin_initial {
# setpref(BOOL, "kmeleon.plugins.adblock.rules.auto", true);
$__abpmacro_path = getfolder(ProfileFolder) . "//adblockmacro.log";
$_Adblockplugin_len = length(getpref( STRING, "kmeleon.plugins.adblock.subscriptions") );
$__abrdays = getpref(INT, "kmeleon.plugins.adblock.rules.days");
if ($__abrdays < 1) {
 setpref(INT, "kmeleon.plugins.adblock.rules.days", 5);
 $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Adblock rules delete interval was set to "). 5;
 appendfile($__abpmacro_path, "\n".$_adblockmacro_text);
 $__abnext = (5 * 86400) + time() ;
 setpref(INT, "kmeleon.plugins.adblock.rules.next", $__abnext);
 $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Adblock next rules delete was set to ").$__abnext." for ". date( "%Y-%m-%d %H:%M",$__abnext );
 appendfile($__abpmacro_path, "\n".$_adblockmacro_text);
 }
$__abldays = getpref(INT, "kmeleon.plugins.adblock.log.days");
if ($__abldays < 1) {
 setpref(INT, "kmeleon.plugins.adblock.log.days", 5);
 $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Adblock log delete interval was set to "). 5;
 appendfile($__abpmacro_path, "\n".$_adblockmacro_text);
 $__abnext = (5 * 86400) + time() ;
 setpref(INT, "kmeleon.plugins.adblock.log.next", $__abnext);
 $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Adblock next log delete was set to ").$__abnext." for ". date( "%Y-%m-%d %H:%M",$__abnext );
 appendfile($__abpmacro_path, "\n".$_adblockmacro_text);
 }
 
# Workaround for duplication bug
$_AdblockExistingSubsBug_Check=getpref(STRING, "kmeleon.plugins.adblock.newsubscriptions");
if(length($_AdblockExistingSubsBug_Check)>7)
{
$_Adblockplugin_load=getpref(STRING, "kmeleon.plugins.adblock.newsubscriptions");
}
else{
  $_Adblockplugin_usersub=getfolder(ProfileFolder)."\\adblock_user.txt";
  $_Adblockplugin_usersub="file://".gsub("\\","/",$_Adblockplugin_usersub);
  $_Adblockplugin_load = "https://rjjiii.github.io/K-Meleon/AdBlockLocus/Core.txt";
  $_Adblockplugin_load = $_Adblockplugin_load ."|".   $_Adblockplugin_usersub ; 
  setpref(BOOL, "kmeleon.plugins.adblock.subs.core", true);
  $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("The default subscription was set and downloaded.");
  appendfile($_BABmacro_path, "\n".$_adblockmacro_text); 
}  
  setpref(STRING, "kmeleon.plugins.adblock.subscriptions", $_Adblockplugin_load ) ;

  
  
$_Adblockplugin_len <3 ? &_Adblockplugin_initial_load : 0 ;
}

_Adblockplugin_initial2 {
$__abrdays = getpref(INT, "kmeleon.plugins.adblock.rules.days");
if ($__abrdays < 1) {
 setpref(INT, "kmeleon.plugins.adblock.rules.days", 5);
 $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Adblock rules delete interval was set to "). 5;
 appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
 $__abnext = (5 * 86400) + time() ;
 setpref(INT, "kmeleon.plugins.adblock.rules.next", $__abnext);
 $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Adblock next rules delete was set to ").$__abnext." for ". date( "%Y-%m-%d %H:%M",$__abnext );
 appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
 }
$__abldays = getpref(INT, "kmeleon.plugins.adblock.log.days");
if ($__abldays < 1) {
 setpref(INT, "kmeleon.plugins.adblock.log.days", 5);
 $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Adblock log delete interval was set to "). 5;
 appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
 $__abnext = (5 * 86400) + time() ;
 setpref(INT, "kmeleon.plugins.adblock.log.next", $__abnext);
 $_adblockmacro_text = date( "%Y-%m-%d %H:%M" )." >> "._("Adblock next log delete was set to ").$__abnext." for ". date( "%Y-%m-%d %H:%M",$__abnext );
 appendfile($_BABmacro_path, "\n".$_adblockmacro_text);
 }
}

_Adblockplugin_initial_load {
  macros("_Adblockplugin_initial2");
  
removebutton("Adblock_plugin", "macros(_Adblockplugin_toggle)" );
# ?? remove or change?
addbutton("Adblock_plugin", "macros(basic_ab_Dummy)", "Adblock Locus", "No blocking rules are available. \nRestart K-Meleon to download new rules.");
setcmdicon("macros(basic_ab_Dummy)", "km-ab-dead.ico" );
}

basic_ab_Dummy{
alert(_("The ad-blocking plugin is inactive. When you restart K-Meleon it will load new blocking rules and become active."), _("AdBlock Locus"), INFO);
}



# -----------------------------------------------------------------------------------
# Restart
# -----------------------------------------------------------------------------------
_Adblockplugin_restart_sessions{
macroinfo= _("Restart K-Meleon with current session.");
$sessdef=getpref(BOOL, "kmeleon.plugins.sessions.autoload");
$sesstyp=getpref(STRING , "kmeleon.plugins.sessions.openStart");
$sessprompt=getpref(BOOL, "kmeleon.plugins.sessions.ask_autoload");
setpref(BOOL, "kmeleon.plugins.sessions.autoload", true);
setpref(STRING , "kmeleon.plugins.sessions.openStart", "Previous Session");
setpref(BOOL, "kmeleon.plugins.sessions.ask_autoload", false);
setpref(BOOL, "kmeleon.extensions.restart.autoload", $sessdef);
setpref(STRING , "kmeleon.extensions.restart.openStart", $sesstyp);
setpref(BOOL, "kmeleon.extensions.restart.ask_autoload", $sessprompt);
setpref(BOOL, "kmeleon.extensions.restart", true);
id(ID_APP_RESTART);
}

_Adblockplugin_Refresh{
macroinfo= _("Clear old rules, download new rules, and restart K-Meleon.");
&_Adblockplugin_clear_rules;
$_Adblock_Refresh = confirm( "To refresh adblocking rules, AdBlock Locus needs to restart K-Meleon. Are you ready to restart K-Meleon?" , _("Restart K-Meleon") , YESNO , QUESTION ); 
if ( $_Adblock_Refresh == "YES" ) {
	&_Adblockplugin_restart_sessions;
	} 
else {
	alert(_("Old adblocking rules have been cleared. New rules will be available the next time you start K-Meleon.", "Adblock Locus"), _("Old Rules Cleared") );
	}
setpref(BOOL, "kmeleon.plugins.adblock.rulesnew", true);
}

_Adblockplugin_restartcheck{
$restartact=getpref(BOOL, "kmeleon.extensions.restart");
$restactive=("true");
$restartact==$restactive?&_Adblockplugin_restoreuserses:0;
}

_Adblockplugin_restoreuserses{
setpref(BOOL, "kmeleon.extensions.restart", false);
$sessdef=getpref(BOOL, "kmeleon.extensions.restart.autoload");
$sesstyp=getpref(STRING, "kmeleon.extensions.restart.openStart");
$sessprompt=getpref(BOOL, "kmeleon.extensions.restart.ask_autoload");
setpref(BOOL, "kmeleon.plugins.sessions.autoload", $sessdef);
setpref(STRING , "kmeleon.plugins.sessions.openStart", $sesstyp);
setpref(BOOL, "kmeleon.plugins.sessions.ask_autoload", $sessprompt);
}

# The macro below is a workaround for the BAB. To download rules the BAB must start
# with adblock.txt deleted. The BAB then creates adblock.txt from subscriptions. BUT
# the BAB cannot use any rules added after K-Meleon starts, so every time rules are
# updated, the BAB starts with no rules and won't have rules until it restarts again.
# This will only trigger if the user chooses "Refresh" from the menu. The user should
# always see the clear cause and effect. If this happened for auto-deletion, it
# could be more of a problem than the BAB's quirks.
_ABL_Refresh_Restart2{
	$_ABL_RulesNew=getpref(BOOL, "kmeleon.plugins.adblock.rulesnew");
	if($_ABL_RulesNew){
		&_Adblockplugin_restart_sessions;
		togglepref(BOOL, "kmeleon.plugins.adblock.rulesnew");
	}
	}



# -----------------------------------------------------------------------------------
# Menus, Buttons, Toolbars
# -----------------------------------------------------------------------------------
_Adblockplugin_BuildMenu {
if (($VERSION >= 33685507) and (pluginexist(adblock)) ) {  # K-Meleon 75.1 or greater and adblock plugin
    ## DO NOT set rules cleared to false if adblock.txt contains dummy string
	$_BABmacro_path = getfolder(ProfileFolder)."\\adblockmacro.log";
    $_Adblockplugin_IcoChg = false;
	setpref(BOOL, "kmeleon.plugins.adblock.rules.cleared", false);
	$__ABL_Dummyfix = getpref(BOOL, "kmeleon.plugins.adblock.rules.deleted"); 
	if ($__ABL_Dummyfix){
		setpref(BOOL, "kmeleon.plugins.adblock.rules.cleared", true);
	}
    setpref(BOOL, "kmeleon.plugins.adblock.log.cleared", false); 
    $_adp= "AdBlock Locus";
	setmenu("PrivacySecurity", popup, $_adp, -1);
	setmenu($_adp, macro, "Allow Globally", "_Adblockplugin_disable", 0);
    setmenu($_adp, macro, "Allow Domain", "_Adblockplugin_allowDomain", 1);
    setmenu($_adp, macro, "Restart K-Meleon", "_Adblockplugin_restart_sessions", 2);
	setmenu($_adp, separator, 3);
    setmenu($_adp, macro, "About", "_Adblockplugin_About", 4);		
    $_adA= "Advanced";  $_adAm= "Automatic Settings"; $_adSub= "Subscriptions";
    setmenu($_adp, macro, "View Settings", "_Adblockplugin_QV", 5);
    setmenu($_adp, macro, "Custom Rules", "_Adblockplugin_user_rules(adblock_user)", 6);
    setmenu($_adp, macro, "Refresh Rules", "_Adblockplugin_Refresh", 7);
    setmenu($_adp, separator, 8);  	
	setmenu($_adp, popup, $_adA, 9);
	setmenu($_adp, popup, $_adAm, 10);   
	setmenu($_adp, popup, $_adSub, 11);	  
    setmenu($_adA, macro, "View the Rules", "_Adblockplugin_rules(adblock)", 0);
    setmenu($_adA, macro, "Clear the Rules", "_Adblockplugin_clear_rules", 1);
    setmenu($_adA, macro, "List Subscriptions", "_Adblockplugin_subscriptions", 2);
	setmenu($_adA, separator, 3);
    setmenu($_adA, macro, "Log Blocked Elements", "_Adblockplugin_logging", 4);
    setmenu($_adA, macro, "Clear the Log", "_Adblockplugin_clear_log", 5);
    setmenu($_adA, macro, "View the Log", "_Adblockplugin_logs(adblock)", 6);
	setmenu($_adA, separator, 7);
	setmenu($_adA, macro, "View the Macro's Log", "_Adblockplugin_macro_log(adblockmacro)", 8);
# Subscriptions menu
    setmenu($_adSub, macro, "Core", "_Adblockplugin_Sub_Core", 0);		
    setmenu($_adSub, macro, "Easylist (ABP)", "_Adblockplugin_Sub_Easylist", 1);
    setmenu($_adSub, separator, 2);     
	$_adSupp = "Supplemental";
	setmenu($_adSub, popup, $_adSupp, 3);		
    setmenu($_adSub, macro, "Custom", "_Adblockplugin_Sub_Custom", 4);
    setmenu($_adSub, separator, 5);
	setmenu($_adSub, macro, "Restore Defaults", "_Adblockplugin_Sub_Restore", 6);	
# Supplemental subscriptions
    setmenu($_adSupp, macro, "&French", "_Adblockplugin_Sub_Sup(french)", 0);			
    setmenu($_adSupp, macro, "&Spanish", "_Adblockplugin_Sub_Sup(spanish)", 1);			
    setmenu($_adSupp, macro, "&German", "_Adblockplugin_Sub_Sup(german)", 2);			
    setmenu($_adSupp, macro, "Chinese", "_Adblockplugin_Sub_Sup(chinese)", 3);			
    setmenu($_adSupp, macro, "&Italian", "_Adblockplugin_Sub_Sup(italian)", 4);			
    setmenu($_adSupp, macro, "&Russian", "_Adblockplugin_Sub_Sup(russian)", 5);			
    setmenu($_adSupp, macro, "- RU AdList: Counters", "_Adblockplugin_Sub_Sup(cntblock)", 6);	
    setmenu($_adSupp, separator, 7);     	
    setmenu($_adSupp, macro, "EasyPrivacy (Optimized)", "_Adblockplugin_Sub_Sup(privacy)", 8);			
    setmenu($_adSupp, macro, "Anti-Facebook", "_Adblockplugin_Sub_Sup(facebook)", 9);	
    macros("_Adblockplugin_BuildMenuAs");	
    ## create toolbar and set button
    # check icon and set tool tip
    $_adblockmacro_TTip = "Block ads. Right click for more options." ; 
    addtoolbar("AdBlock Locus") ;
    addbutton("AdBlock Locus", "macros(_Adblockplugin_toggle)", "AdBlock Locus", $_adblockmacro_TTip);
    macros("_Adblockplugin_toolbar_set");
    }
}

_Adblockplugin_BuildMenuAs {
#Automatic settings menu
    setmenu($_adAm, macro, "Update Rules", "_Adblockplugin_Aclear_rules", 0);
    setmenu($_adAm, macro, "Set Interval: ".getpref(INT,"kmeleon.plugins.adblock.rules.days")." Days", "_Adblockplugin_Aclear_rules_I", 1);
    setmenu($_adAm, separator, 2);     
    setmenu($_adAm, macro, "Clear Logs", "_Adblockplugin_Aclear_log", 3); 
    setmenu($_adAm, macro, "Set Interval: ".getpref(INT,"kmeleon.plugins.adblock.log.days")." Days", "_Adblockplugin_Aclear_log_I", 4);		
}

_Adblockplugin_toolbar_set {
$__abptog = getpref( BOOL, "kmeleon.plugins.adblock.disabled");
$_Adblockplugin_rules = getpref(BOOL, "kmeleon.plugins.adblock.rules.cleared");
# Icons are base64 to fit inside macro file.
$_km_path=getfolder(RootFolder)."\\skins\\shared\\Basic_Adblock.png";
$EXISTS = fileexists($_km_path);
if ($EXISTS){
	$_adblockmacro_EIcon = "Basic_Adblock.png[".0.", 32 ,32]"; 
	$_adblockmacro_DIcon = "Basic_Adblock.png[".1.", 32 ,32]"; 
	$_adblockmacro_XIcon = "Basic_Adblock.png[".2.", 32 ,32]";
}
else{
# Disabled icon:
	$_adblockmacro_DIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAAEEfUpiAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAE60AABOtARwYTUoAAAebSURBVEhLzZd7UFTXHce/995leQnr8hK1RmB5CIOPouIjggIbwTbTcWpMO03a6fSh2KaZqs10bMUgjTW2zaP/WJt2GjvGOonGvNoaKA+r4f2QcQF5wxrFALLLc9+7t+ece/fKsquTdPpHPzs/7vn9zjm/87vn8bsHBKT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QV7KioqhIlrlHaFCuWA0kAQdxbUPm/evHFrXKdKTkAaU3aHmpFUEB/RQBD7pk6dKt8nT55M+fn5oh3O4l40keX4wi3QgPKBCDZBFFKfJ1Asb9u2zcvrvwVkhp07d4pTevrD5cuXIXQF+0C1MkEzL0RB1VrxLQARFHOKOWpSxOnIyEiZe6KqqorWrl1L/N9BfGX+/Pnyl0D5DYDqUjNBM3500bTS/BfWhHXu3LkS8ZAAuOrUdhACiiRKJEgjQOWcMKhv377aCokJ4uPjZXz27Fk8wRZWf4mq0LzeigpGLIB14cKFeor/t4AJ8b+H44RhNDR+rAxXQVCQTJyIBPf9QEGTnZ3dI2OFHgVQwH9B9v5oHn4x5Pehns3J/1bKekxE/wMQ/Q2ecoXAvtL5vAAAAABJRU5ErkJggg==";

}
$__abptog==0 ? setcmdicon( "macros(_Adblockplugin_toggle)", $_adblockmacro_EIcon ) : setcmdicon("macros(_Adblockplugin_toggle)", $_adblockmacro_DIcon );
if (getpref(BOOL, "kmeleon.plugins.adblock.rules.cleared")) {
  removebutton("AdBlock Locus", "macros(_Adblockplugin_toggle)" );
  addbutton("AdBlock Locus", "macros(basic_ab_Dummy)", "AdBlock Locus", "New ad-blocking rules have not activated yet. \nRestart K-Meleon to activate the plugin.");
  }  
  setcmdicon("macros(basic_ab_Dummy)", $_adblockmacro_XIcon );
}

# Privacy Bar option
# Add the below entry to "toolbars.cfg" to block ads from the Privacy Bar.
# Only works on the default theme and other newer 75-style themes.
#	!Ads{
#	macros(_Adblockplugin_toggle)|&Privacy
#	Block ads with K-Meleon's built-in ad blocker.
#	check.png[0,32,32]
#	}
_ABL_Sync_PrivacyBar{
pluginmsg(toolbars,"CheckButton","&Privacy Bar".",macros(_Adblockplugin_toggle),".(!getpref(BOOL,"kmeleon.plugins.adblock.disabled")?1:0));	
}






# -----------------------------------------------------------------------------------
# Startup
# -----------------------------------------------------------------------------------
$OnInit=$OnInit."_Adblockplugin_BuildMenu;";
$OnSetup=$OnSetup."_Adblockplugin_initial;";
$OnStartup=$OnStartup."_Adblockplugin_restartcheck;";
$OnLoad=$OnLoad."_ABL_Sync_PrivacyBar;";
$OnQuit=$OnQuit."_Adblockplugin_DayCheck;";
$OnOpenWindow=$OnOpenWindow."_ABL_Refresh_Restart2;";
$macroModules=$macroModules."Adblockplugin;";




K-Meleon Tools Home

Copyright © 2022 R.J.J. III. AdBlock Locus is a community project. It includes macro code from several K-Meleon community members. The code was shared freely on the K-Meleon forums and extension repository. It is hosted here for the K-Meleon community. AdBlock Locus is distributed freely on an as-is basis and without warranty of any kind. AdBlock Locus cannot be distributed under an open-source license because the code lacks explicit license grants. Nothing in this disclaimer is intended as any additional restriction on your usage of AdBlock Locus.