summaryrefslogtreecommitdiff
path: root/js/forced-anon.js
blob: 86af40633433d0f064488f7c21075f62f7a0833f (plain)
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
/*
 * forced-anon.js
 * https://github.com/savetheinternet/Tinyboard-Tools/blob/master/js/forced-anon.js
 *
 * Released under the MIT license
 * Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
 *
 * Usage:
 *   $config['additional_javascript'][] = $config['root'] . 'jquery.min.js';
 *   $config['additional_javascript'][] = $config['root'] . 'forced-anon.js';
 *
 */

$(document).ready(function(){
	var enable_fa = function() {
		$('p.intro label').each(function() {
			if($(this).children('a.capcode').length == 0) {
				var id = $(this).parent().children('a.post_no:eq(1)').text();
				
				if($(this).children('a.email').length != 0)
					var p = $(this).children('a.email');
				else
					var p = $(this);
				
				old_info[id] = {'name': p.children('span.name').text(), 'trip': p.children('span.trip').text()};
				
				p.children('span.name').text('Anonymous');
				if(p.children('span.trip').length != 0)
					p.children('span.trip').text('');
			}
		});
	};
	
	var disable_fa = function() {
		$('p.intro label').each(function() {
			if($(this).children('a.capcode').length == 0) {
				var id = $(this).parent().children('a.post_no:eq(1)').text();
				
				if(old_info[id]) {
					if($(this).children('a.email').length != 0)
						var p = $(this).children('a.email');
					else
						var p = $(this);
					
					p.children('span.name').text(old_info[id]['name']);
					if(p.children('span.trip').length != 0)
						p.children('span.trip').text(old_info[id]['trip']);
				}
			}
		});
	};
	
	old_info = {};
	forced_anon = localStorage['forcedanon'] ? true : false;
	
	$('hr:first').before('<div id="forced-anon" style="text-align:right"><a class="unimportant" href="javascript:void(0)">-</a></div>');
	$('div#forced-anon a').text('Forced anonymity (' + (forced_anon ? 'enabled' : 'disabled') + ')');
	
	$('div#forced-anon a').click(function() {
		forced_anon = !forced_anon;
		
		if(forced_anon) {
			$('div#forced-anon a').text('Forced anonymity (enabled)');
			localStorage.forcedanon = true;
			enable_fa();
		} else {
			$('div#forced-anon a').text('Forced anonymity (disabled)');
			delete localStorage.forcedanon;
			disable_fa();
		}
		
		return false;
	});
	
	if(forced_anon)
		enable_fa();
	
});