Created
February 15, 2011 21:20
-
-
Save bradhintze/828270 to your computer and use it in GitHub Desktop.
Extension code to create a personal blocklist for search results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruleset a169x230 { | |
meta { | |
name "Personal Search Blocklist" | |
description << | |
Personal Search Blocklist | |
>> | |
author "Ed Orcutt" | |
logging off | |
key errorstack "52f54bf3c4deb3cbb41ba8b1ac7d5832" | |
} | |
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 show_blocklist_stats { | |
select when pageview "www\.lobosllc\.com/example/" | |
pre { | |
stat_bing_init = app:stat_bing_init; | |
stat_google_init = app:stat_google_init; | |
stat_yahoo_init = app:stat_yahoo_init; | |
stat_blocked_domains = app:stat_blocked_domains; | |
} | |
{ | |
prepend("body", "<b>Your Domain Blocklist</b><br/>"); | |
prepend("body", "<br/>"); | |
prepend("body", "YahooInits: #{stat_yahoo_init}<br/>"); | |
prepend("body", "BingInits: #{stat_bing_init}<br/>"); | |
prepend("body", "GoogleInits: #{stat_google_init}<br/>"); | |
prepend("body", "Blocked Domains: #{stat_blocked_domains}<br/>"); | |
prepend("body", "<b>Application Statistics (since 17 Feb 2011)</b><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 <| | |
// get app object for raising web event | |
app = KOBJ.get_application("a169x230"); | |
// ------------------------------------------------ | |
var StableTimerID = 0; | |
function watch_google_instant(delay) { | |
delay = typeof(delay) != 'undefined' ? delay : 1000; | |
clearTimeout(StableTimerID); | |
StableTimerID = window.setTimeout( function() { | |
// console.log("Watch Google Instant: ", StableTimerID); | |
$K('div#ires ol li.g:not([lobosinit])').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("INSTANT urlTemp: ", fullURL); | |
// console.log("INSTANT thisDomain: ", thisDomain); | |
$K(this).attr('lobosinit', thisDomain); | |
$K(this).find('span.f').append('<span class="lobosdomain" w0domain="'+thisDomain+'">init</span>'); | |
}); | |
// update blocklist display | |
app.raise_event("update_blocklist_display"); | |
// (re)plant blocklist notification | |
notifyPlanted = $K('div#blocklistNotification').length; | |
if (!notifyPlanted) { | |
$K('#res').after(blocklistNotification); | |
// console.log("INSTANT ", "RePlant show notifications"); | |
} | |
}, delay); | |
} | |
KOBJ.watchDOM("#rso", watch_google_instant); | |
// Prime the pump, to catch the first time | |
watch_google_instant(10000); | |
// ------------------------------------------------ | |
// iterate thru each search result list item | |
$K('div#ires ol li.g:not([lobosinit])').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).attr('lobosinit', thisDomain); | |
$K(this).find('span.f').append('<span class="lobosdomain" w0domain="'+thisDomain+'">init</span>'); | |
}); | |
|>; | |
after("#res", blocklistNotification); | |
watch("div#blocklistNotification", "click"); | |
} | |
fired { | |
raise explicit event update_blocklist_display; | |
app:stat_google_init += 1 from 1; | |
} | |
} | |
// ==================================================================== | |
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"); | |
} | |
fired { | |
raise explicit event update_blocklist_display; | |
app:stat_bing_init += 1 from 1; | |
} | |
} | |
// ==================================================================== | |
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"); | |
} | |
fired { | |
raise explicit event update_blocklist_display; | |
app:stat_yahoo_init += 1 from 1; | |
} | |
} | |
// ==================================================================== | |
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; | |
app:stat_blocked_domains += 1 from 1; | |
} | |
} | |
// ==================================================================== | |
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 or web 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'); | |
} | |
|>; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment