lainchan/js/forced-anon.js

88 lines
2.5 KiB
JavaScript
Raw Normal View History

2012-03-14 01:05:39 -04:00
/*
* forced-anon.js
2012-03-30 20:13:11 -04:00
* https://github.com/savetheinternet/Tinyboard/blob/master/js/forced-anon.js
2012-03-14 01:05:39 -04:00
*
* Released under the MIT license
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
2012-03-14 01:05:39 -04:00
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/forced-anon.js';
2012-03-14 01:05:39 -04:00
*
*/
if (active_page == 'ukko' || active_page == 'thread' || active_page == 'index')
$(document).ready(function() {
var force_anon = 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 enable_fa = function() {
$('p.intro label').each(force_anon);
2012-03-14 01:01:52 -04:00
};
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>');
2013-07-03 01:48:24 -04:00
$('div#forced-anon a').text(_('Forced anonymity')+' (' + (forced_anon ? _('enabled') : _('disabled')) + ')');
2012-03-14 01:01:52 -04:00
$('div#forced-anon a').click(function() {
forced_anon = !forced_anon;
if(forced_anon) {
2013-07-03 01:48:24 -04:00
$('div#forced-anon a').text(_('Forced anonymity')+' ('+_('enabled')+')');
2012-03-14 01:01:52 -04:00
localStorage.forcedanon = true;
enable_fa();
} else {
2013-07-03 01:48:24 -04:00
$('div#forced-anon a').text(_('Forced anonymity')+' ('+_('disabled')+')');
2012-03-14 01:01:52 -04:00
delete localStorage.forcedanon;
disable_fa();
}
return false;
});
if(forced_anon)
enable_fa();
$(document).on('new_post', function(e, post) {
if(forced_anon)
$(post).find('p.intro label').each(force_anon);
});
2012-03-14 01:01:52 -04:00
});