1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-14 00:23:04 +01:00
vichan/js/forced-anon.js

129 lines
4.2 KiB
JavaScript
Raw Normal View History

2012-03-14 06:05:39 +01:00
/*
* forced-anon.js
2012-03-31 02:13:11 +02:00
* https://github.com/savetheinternet/Tinyboard/blob/master/js/forced-anon.js
2012-03-14 06:05:39 +01: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 06:05:39 +01:00
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* //$config['additional_javascript'][] = 'js/options.js';
* //$config['additional_javascript'][] = 'js/style-select.js';
* //$config['additional_javascript'][] = 'js/options/general.js';
* $config['additional_javascript'][] = 'js/forced-anon.js';
2012-03-14 06:05:39 +01:00
*
*/
if (active_page == 'ukko' || active_page == 'thread' || active_page == 'index' || (window.Options && Options.get_tab('general')))
$(document).ready(function() {
var force_anon = function() {
2014-11-03 09:28:04 +01:00
if ($(this).children('a.capcode').length == 0) {
var id = $(this).parent().children('a.post_no:eq(1)').text();
2014-11-03 09:28:04 +01:00
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');
2014-11-03 09:28:04 +01:00
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 06:01:52 +01:00
};
var disable_fa = function() {
$('p.intro label').each(function() {
2014-11-03 09:28:04 +01:00
if ($(this).children('a.capcode').length == 0) {
2012-03-14 06:01:52 +01:00
var id = $(this).parent().children('a.post_no:eq(1)').text();
if(old_info[id]) {
2014-11-03 09:28:04 +01:00
if ($(this).children('a.email').length != 0)
2012-03-14 06:01:52 +01:00
var p = $(this).children('a.email');
else
var p = $(this);
p.children('span.name').text(old_info[id]['name']);
2014-11-03 09:28:04 +01:00
if (p.children('span.trip').length != 0)
2012-03-14 06:01:52 +01:00
p.children('span.trip').text(old_info[id]['trip']);
}
}
});
};
2014-11-03 09:28:04 +01:00
var toggle_id = function() {
if (localStorage.hideids == 'true'){
$(this).addClass('hidden');
} else {
$(this).removeClass('hidden');
}
};
2012-03-14 06:01:52 +01:00
old_info = {};
forced_anon = localStorage['forcedanon'] ? true : false;
2014-11-03 09:28:04 +01:00
if (window.Options && Options.get_tab('general')) {
var s1 = '#hide-ids', s2 = '#forced-anon', e = 'change';
Options.extend_tab("general", "<label id='hide-ids'><input type='checkbox' /> "+_('Hide IDs')+"</label>");
Options.extend_tab("general", "<label id='forced-anon'><input type='checkbox' /> "+_('Forced anonymity')+"</label>");
}
else {
var s1 = '#hide-ids', s2 = '#forced-anon', e = 'click';
$('hr:first').before('<div id="hide-ids" style="text-align:right"><a class="unimportant" href="javascript:void(0)">Hide IDs</a></div>');
$('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')) + ')');
2014-11-03 09:28:04 +01:00
}
2012-03-14 06:01:52 +01:00
2014-11-03 09:28:04 +01:00
$(s1).on(e, function(e) {
if (!localStorage.hideids || localStorage.hideids == 'false') {
localStorage.hideids = 'true';
if (window.Options && Options.get_tab('general')) e.target.checked = true;
} else {
localStorage.hideids = 'false';
if (window.Options && Options.get_tab('general')) e.target.checked = false;
}
$('.poster_id').each(toggle_id);
});
2012-03-14 06:01:52 +01:00
2014-11-03 09:28:04 +01:00
$(s2).on(e, function() {
2012-03-14 06:01:52 +01:00
forced_anon = !forced_anon;
2014-11-03 09:28:04 +01:00
if (forced_anon) {
2013-07-03 07:48:24 +02:00
$('div#forced-anon a').text(_('Forced anonymity')+' ('+_('enabled')+')');
2012-03-14 06:01:52 +01:00
localStorage.forcedanon = true;
enable_fa();
} else {
2013-07-03 07:48:24 +02:00
$('div#forced-anon a').text(_('Forced anonymity')+' ('+_('disabled')+')');
2012-03-14 06:01:52 +01:00
delete localStorage.forcedanon;
disable_fa();
}
return false;
});
2014-11-03 09:28:04 +01:00
// initial option setup on script load
if (localStorage.hideids == 'true'){
if (window.Options && Options.get_tab('general')) $('#hide-ids>input').prop('checked',true);
$('.poster_id').each(toggle_id);
}
if(forced_anon) {
2012-03-14 06:01:52 +01:00
enable_fa();
2014-11-03 09:28:04 +01:00
if (window.Options && Options.get_tab('general')) {
$('#toggle-locked-threads>input').prop('checked', true);
}
}
2012-03-14 06:01:52 +01:00
$(document).on('new_post', function(e, post) {
2014-11-03 09:28:04 +01:00
if (forced_anon)
$(post).find('p.intro label').each(force_anon);
2014-11-03 09:28:04 +01:00
if (localStorage.hideids == 'true')
$(post).find('.poster_id').each(toggle_id);
});
2012-03-14 06:01:52 +01:00
});