This repository has been archived by the owner on Nov 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tinted-sheen.js
executable file
·111 lines (85 loc) · 5.19 KB
/
tinted-sheen.js
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
/*
TINTED SHEEN
Bookmarklet, & browser extensions to cure that winning Charlie Sheen hangover.
by Greg Leuch <http://gleuch.com> / @gleuch
MIT License - http://creativecommons.org/licenses/MIT
------------------------------------------------------------------------------------
*/
Array.prototype.in_array = function(p_val, sensitive) {for(var i = 0, l = this.length; i < l; i++) {if ((sensitive && this[i] == p_val) || (!sensitive && this[i].toLowerCase() == p_val.toLowerCase())) {return true;}} return false;};
function rgb2hex(rgb) {rgb = rgb.replace(/\s/g, "").replace(/^(rgb\()(\d+),(\d+),(\d+)(\))$/, "$2|$3|$4").split("|"); return "#" + hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);}
function hex(x) {var hexDigits = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8","9", "A", "B", "C", "D", "E", "F"); return isNaN(x) ? "00" : hexDigits[(x-x%16)/16] + hexDigits[x%16];}
var $_ = false, $tinted_sheen = document.createElement('script'), local = true;
$tinted_sheen.src = 'http://assets.gleuch.com/jquery-latest.js';
$tinted_sheen.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild($tinted_sheen);
function tinted_sheen_wait() {
if ((local && typeof(jQuery) == 'undefined') || (!local && typeof(unsafeWindow.jQuery) == 'undefined')) {
window.setTimeout(tinted_sheen_wait,100);
} else {
tinted_sheen_start(local ? jQuery : unsafeWindow.jQuery);
}
}
function tinted_sheen_start($_) {
$_.fn.reverse = function(){return this.pushStack(this.get().reverse(), arguments);};
(function($_) {
$_.tinted_sheen = function(data, c) {
if (!$_.tinted_sheen.settings.finish) $_.tinted_sheen.init();
$_(data).tinted_sheen(c);
if (!$_.tinted_sheen.settings.finish) $_.tinted_sheen.finish();
};
$_.fn.tinted_sheen = function(c) {
return this.filter(function() {return $_.tinted_sheen.filter(this);}).each(function() {$_.tinted_sheen.tint(this, c);});
};
$_.extend($_.tinted_sheen, {
settings : {hide_bg : true, search: /(charlie(\s|\-|\_)?)?(sheen|porn\sfamily|\#winning|\#tigerblood|tiger\sblood|adonis\sdna|\#sheenskorner|sheen\'s\skorner|\#fastball)/img, replace: '<span class="tinted_sheen" style="color: %C; background-color: %C;">$1$2$3</span>', starred: '****** ******', init : false, finish : false},
pluck : function(str) {return str.replace(/(charlie\s)(sheen)/img, '****** ******').replace(/(sheen|\#winning)/img, '******');},
filter : function(self) {
if (self.nodeType == 1) {
var tag = self.tagName.toLowerCase();
return !(self.className.match('tinted_sheen') || tag == 'head' || tag == 'img' || tag == 'textarea' || tag == 'option' || tag == 'style' || tag == 'script');
} else {
return true;
}
},
tint : function(self, c) {
$_(self).css({'text-shadow' : 'none'});
if (self.nodeType == 3) {
if (self.nodeValue.replace(/\s/ig, '') != '') {
if (!c) c = $_(self).parent() ? $_(self).parent().css('color') : '#000000';
text = self.nodeValue.replace($_.tinted_sheen.settings.search, $_.tinted_sheen.settings.replace.replace(/\%C/mg, c) );
$_(self).after(text);
self.nodeValue = '';
}
} else if (self.nodeType == 1) {
c = rgb2hex($_(self).css('color'));
if ($_(self).children().length > 0) {
$_.tinted_sheen($_(self).contents(), c);
} else if ($_(self).children().length == 0) {
text = $_(self).html().replace($_.tinted_sheen.settings.search, $_.tinted_sheen.settings.replace.replace(/\%C/mg, c) );
$_(self).html(text);
}
}
},
init : function() {
$_.tinted_sheen.settings.init = true;
},
finish : function() {
$_(document).each(function() {this.title = $_.tinted_sheen.pluck(this.title);});
$_('img, input[type=image]').each(function() {
if ($_(this).attr('alt').match($_.tinted_sheen.settings.search) || $_(this).attr('title').match($_.tinted_sheen.settings.search) || $_(this).attr('src').match($_.tinted_sheen.settings.search)) {
var r = $_(this), w = r.width(), h = r.height(), c = rgb2hex($_(this).css('color'));
r.css({background: c, width: r.width(), height: r.height()}).attr('src', 'http://assets.gleuch.com/blank.png').width(w).height(h);
}
});
$_('input[type=text]').each(function() {if ($_(this).val().match($_.tinted_sheen.settings.search) ) $_(this).val( $_.tinted_sheen.pluck($_(this).val()) );});
$_('textarea, option').each(function() {if ($_(this).html().match($_.tinted_sheen.settings.search) ) $_(this).html( $_.tinted_sheen.pluck($_(this).html()) );});
var s = document.createElement("style");
s.innerHTML = ".tinted_sheen {font-size: inherit !important; "+ ($_.tinted_sheen.settings.hide_bg ? "background-image: none !important;" : "") +"} .bg_tinted_sheen {"+ ($_.tinted_sheen.settings.hide_bg ? "background-image: none !important;" : "") +"}";
$_('head').append(s);
$_.tinted_sheen.settings.finish = true;
}
});
})($_);
$_.tinted_sheen('html', '#000000');
}
if (typeof($_tiger_blood) == 'undefined' || !$_tiger_blood) {tinted_sheen_wait();}