public
Last active

Extension code to create a personal blocklist for search results

  • Download Gist
PersonalBlocklist.krl
KRL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
ruleset a169x230 {
meta {
name "Personal Search Blocklist"
description <<
Personal Search Blocklist
>>
author "Ed Orcutt"
logging on
}
 
dispatch {
domain "google.com"
domain "yahoo.com"
domain "bing.com"
domain "www.lobosllc.com"
}
 
global {
css <<
.blocked {
display: none;
}
.blockedVisible {
display: block;
background-color: #FFD2D2;
}
.notifyVisible {
display: block;
font-style:italic;
margin-top:1em;
margin-bottom:1em;
}
.notifyHide {
display: none;
}
>>;
blocklistNotification = <<
<div id="blocklistNotification" class="notifyVisible">Some results were removed by the Personal Blocklist extension (<a href="javascript:;">show</a>).</div>
>>;
}
 
// ====================================================================
rule show_blocklist_domains {
select when pageview "www\.lobosllc\.com/example/"
foreach ent:blackdomains setting (thedomain)
{
prepend("body", "#{thedomain}<br/>");
}
}
// ====================================================================
rule Blocklist_Init {
select when pageview "[google|bing|yahoo].com"
every {
emit <|
// get app object for raising web event
app = KOBJ.get_application("a169x230");
// ------------------------------------------------
$K("span.blockDomain").live("click", function() {
var domain = $K(this).attr("w0domain");
 
// raise web event to submit domain
app.raise_event("add_blocklist_domain", {"thedomain":domain});
});
// ------------------------------------------------
$K("span.unblockDomain").live("click", function() {
var domain = $K(this).attr("w0domain");
 
// raise web event to submit domain
app.raise_event("remove_blocklist_domain", {"thedomain":domain});
});
|>;
}
}
// ====================================================================
rule Blocklist_Google_Init {
select when pageview "google.com"
every {
notify("Google Blocklist", "processing ...");
emit <|
// ------------------------------------------------
// iterate thru each search result list item
$K('div#ires ol li.w0').each(function() {
// grab the full URL of the search result
var fullURL = $K(this).find('.l').attr('href');
var thisDomain = KOBJ.get_host(fullURL);
// console.log("urlTemp: ", fullURL);
// console.log("thisDomain: ", thisDomain);
$K(this).find('span.f').append('<span class="lobosdomain" w0domain="'+thisDomain+'">init</span>');
});
|>;
after("#res", blocklistNotification);
watch("div#blocklistNotification", "click");
}
}
// ====================================================================
rule Blocklist_Bing_Init {
select when pageview "bing.com"
every {
notify("Bing Blocklist", "processing ...");
emit <|
// ------------------------------------------------
// iterate thru each search result list item
// ul#wg0 li.sa_wr
$K('ul#wg0 li.sa_wr').each(function() {
// grab the full URL of the search result
var fullURL = $K(this).find('.nc_tc a, .sb_tlst a').attr('href');
var thisDomain = KOBJ.get_host(fullURL);
// console.log("urlTemp: ", fullURL);
// console.log("thisDomain: ", thisDomain);
$K(this).find('div.sb_meta cite').append('<span class="lobosdomain" w0domain="'+thisDomain+'">init</span>');
// $K(this).find('span.f').append('<span class="lobosdomain" w0domain="'+thisDomain+'">init</span>');
});
|>;
after("#results", blocklistNotification);
watch("div#blocklistNotification", "click");
}
}
// ====================================================================
rule Blocklist_Yahoo_Init {
select when pageview "yahoo.com"
every {
notify("Yahoo Blocklist", "processing ...");
emit <|
// ------------------------------------------------
// iterate thru each search result list item
// div#web ol li
$K('div#web ol li').each(function() {
// grab the full URL of the search result
var fullURL = $K(this).find('.yschttl').attr('href');
var thisDomain = KOBJ.get_host(fullURL);
// console.log("urlTemp: ", fullURL);
// console.log("thisDomain: ", thisDomain);
$K(this).find('div.res').append('<span class="lobosdomain" w0domain="'+thisDomain+'">init</span>');
});
|>;
after("div#web", blocklistNotification);
watch("div#blocklistNotification", "click");
}
}
// ====================================================================
rule Blocklist_Apply {
select when pageview "[google|bing|yahoo].com"
// select when pageview "google.com"
pre {
blackdomains = ent:blackdomains || [];
}
every {
emit <|
var domainsHidden = false;
$K('span.lobosdomain').each(function() {
var current = this;
var parent = $K(current).parents('li');
// GOOGLE: var parent = $K(current).parents('li.w0');
var thisDomain = $K(current).attr('w0domain');
// console.log("thisDomain: ", thisDomain);
// console.log("blackdomains: ", blackdomains);
if ($K.inArray(thisDomain, blackdomains) > -1) {
$K(current).addClass('unblockDomain');
$K(current).html(' - <a href="javascript:;">Unblock '+ thisDomain +'</a>');
$K(parent).addClass('blocked');
domainsHidden = true;
}
else {
$K(current).addClass('blockDomain');
$K(current).html(' - <a href="javascript:;">Block '+ thisDomain +'</a>');
}
if (domainsHidden) {
$K('div#blocklistNotification').addClass('notifyVisible').removeClass('notifyHide');
}
else {
$K('div#blocklistNotification').addClass('notifyHide').removeClass('notifyVisible');
}
});
|>;
}
}
// ====================================================================
rule Show_Blocked_Domains {
select when web click "div#blocklistNotification"
every {
// notify("Clicked Show Blocked", "") with stick = true;
emit <|
//$K('div#ires ol li.blocked').addClass('blockedVisible').removeClass('blocked');
$K('li.blocked').addClass('blockedVisible').removeClass('blocked');
$K('div#blocklistNotification').addClass('notifyHide').removeClass('notifyVisible');
|>;
}
}
// ====================================================================
rule add_blocklist_domain {
select when web add_blocklist_domain
pre {
thedomain = event:param("thedomain");
blackdomains = ent:blackdomains || [];
newblackdoms = blackdomains.union(thedomain);
}
every {
// notify("domain blocked", thedomain) with sticky = true;
noop();
}
fired {
set ent:blackdomains newblackdoms;
raise explicit event update_blocklist_display;
}
}
// ====================================================================
rule remove_blocklist_domain {
select when web remove_blocklist_domain
pre {
thedomain = event:param("thedomain");
blackdomains = ent:blackdomains || [];
newblackdoms = blackdomains.difference(thedomain);
}
every {
// notify("domain removed", thedomain) with sticky = true;
noop();
}
fired {
set ent:blackdomains newblackdoms;
raise explicit event update_blocklist_display;
}
}
// ====================================================================
rule Blocklist_Google_Revise {
select when explicit update_blocklist_display
pre {
blackdomains = ent:blackdomains || [];
}
every {
emit <|
var domainsHidden = false;
 
$K('span.lobosdomain').each(function() {
var current = this;
var parent = $K(current).parents('li');
// var parent = $K(current).parents('li.w0');
var thisDomain = $K(current).attr('w0domain');
// console.log("thisDomain: ", thisDomain);
// console.log("blackdomains: ", blackdomains);
if ($K.inArray(thisDomain, blackdomains) > -1) {
$K(current).addClass('unblockDomain').removeClass('blockDomain');
$K(current).html(' - <a href="javascript:;">Unblock '+ thisDomain +'</a>');
$K(parent).addClass('blocked');
domainsHidden = true;
}
else {
$K(current).addClass('blockDomain').removeClass('unblockDomain');
$K(current).html(' - <a href="javascript:;">Block '+ thisDomain +'</a>');
$K(parent).removeClass('blocked').removeClass('blockedVisible');
}
});
if (domainsHidden) {
$K('div#blocklistNotification').addClass('notifyVisible').removeClass('notifyHide');
}
else {
$K('div#blocklistNotification').addClass('notifyHide').removeClass('notifyVisible');
}
|>;
}
}
 
 
 
 
 
 
 
 
 
 
 
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.