From b9133416604bd11f3e7e147e5f963053f08ae13f Mon Sep 17 00:00:00 2001 From: discomrade Date: Fri, 15 Oct 2021 06:05:03 -0100 Subject: [PATCH] Add blur images option --- js/blur-images.js | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 js/blur-images.js diff --git a/js/blur-images.js b/js/blur-images.js new file mode 100644 index 00000000..4e7aca1b --- /dev/null +++ b/js/blur-images.js @@ -0,0 +1,102 @@ +/* + * blur-images.js (edit of toggle-images.js) + * + * Released under the MIT license + * Copyright (c) 2012 Michael Save + * Copyright (c) 2013-2014 Marcin Ɓabanowski + * + * 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/toggle-images.js'; + * + * Note: I put it immediately under options/general and make the opacity !important to ensure fast loading time + * Intended for anti-raid protection + */ + +$(document).ready(function(){ + var hide_images = localStorage['hideimages'] ? true : false; + + $('').appendTo($('head')); + + var hideImage = function() { + if ($(this).parent().data('expanded') == 'true') { + $(this).parent().click(); + } + $(this).addClass('hidden'); + }; + + var restoreImage = function() { + $(this) + .attr('src', $(this).attr('data-orig')) + .removeClass('hidden'); + }; + + // Fix for hide-images.js + var show_hide_hide_images_buttons = function() { + if (hide_images) { + $('a.hide-image-link').each(function() { + if ($(this).next().hasClass('show-image-link')) { + $(this).next().hide(); + } + $(this).hide().after(''+_('hidden')+''); + }); + } else { + $('span.toggle-images-placeholder').remove(); + $('a.hide-image-link').each(function() { + if ($(this).next().hasClass('show-image-link')) { + $(this).next().show(); + } else { + $(this).show(); + } + }); + } + }; + + var selector, event; + if (window.Options && Options.get_tab('general')) { + selector = '#toggle-images>input'; + event = 'change'; + Options.extend_tab("general", ""); + } + else { + selector = '#toggle-images a'; + event = 'click'; + $('hr:first').before(''); + $('div#toggle-images a') + .text(hide_images ? _('Show images') : _('Hide images')); + } + + $(selector) + .on(event, function() { + hide_images = !hide_images; + if (hide_images) { + $('img.post-image, .theme-catalog .thread>a>img').each(hideImage); + localStorage.hideimages = true; + } else { + $('img.post-image, .theme-catalog .thread>a>img').each(restoreImage); + delete localStorage.hideimages; + } + + show_hide_hide_images_buttons(); + + $(this).text(hide_images ? _('Show images') : _('Hide images')) + }); + + if (hide_images) { + $('img.post-image, .theme-catalog .thread>a>img').each(hideImage); + show_hide_hide_images_buttons(); + + if (window.Options && Options.get_tab('general')) { + $('#toggle-images>input').prop('checked', true); + } + } + + $(document).on('new_post', function(e, post) { + if (hide_images) { + $(post).find('img.post-image').each(hideImage); + } + }); +});