This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
/
dick_bar_blocker.rb
69 lines (66 loc) · 1.97 KB
/
dick_bar_blocker.rb
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
module Rack
module Contrib
class DickBarBlocker
def initialize(app, name = nil, &block)
raise ArgumentError, "You need to supply a name or a block" if name.nil? and block.nil?
@app = app
@name = name
@block = block
end
def call(env)
referrer = env['HTTP_REFERER']
# Regex courtesy of John Gruber: http://daringfireball.net/2009/04/how_to_block_the_diggbar
if referrer && referrer =~ %r{http://digg.com/\w{1,8}/*(\?.*)?$}
if @block
body = @block.call.to_s
else
body = <<BODY
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Don't be a dick, say no to the DiggBar</title>
<style type="text/css">
body {
font-family: "Lucida Grande";
font-size: 12px;
line-height: 1.8em;
/* So it doesn't stick to the top of the page */
margin-top: 12em;
}
/* I am no CSS master, but this seems to center the text on the page */
p {
margin-left: auto;
margin-right: auto;
width: 32em;
}
</style>
</head>
<body>
<p>
Dear Digg,<br>
Framing sites is bullshit.<br>
<br>
Your pal,<br>
—#{@name}
</p>
<p>
p.s. Firefox users may enjoy the<br>
<a href='http://userscripts.org/scripts/show/45795'>DiggBar Killer script for Greasemonkey</a>.
</p>
<p>
p.p.s. Digg users can disable the DiggBar under<br>
My Profile → Settings → <a href='http://digg.com/settings/viewing'>Viewing Preferences</a>.
</p>
</body>
</html>
BODY
end
[200, {'Content-Length' => body.size.to_s, 'Content-Type' => 'text/html'}, body]
else
@app.call(env)
end
end
end
end
end