From 595a165fa317c5fa967345dd6fdb10bd2a585a2a Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 26 Jul 2013 18:22:48 -0400 Subject: [PATCH 1/9] install.sql mistake --- install.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sql b/install.sql index d32c3e3e..ee2ca8a9 100644 --- a/install.sql +++ b/install.sql @@ -143,7 +143,7 @@ CREATE TABLE IF NOT EXISTS `mods` ( -- Dumping data for table `mods` -- -INSERT INTO `mods` (`id`, `username`, `password`, `type`, `boards`) VALUES +INSERT INTO `mods` (`id`, `username`, `password`, `salt`, `type`, `boards`) VALUES (1, 'admin', 'cedad442efeef7112fed0f50b011b2b9bf83f6898082f995f69dd7865ca19fb7', '4a44c6c55df862ae901b413feecb0d49', 2, '*'); -- -------------------------------------------------------- From baa6793516242890222d3b4c94cac3f31649bd3b Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 26 Jul 2013 19:39:11 -0400 Subject: [PATCH 2/9] toggle-images.js (this was written last year, but I never pushed it to git) --- js/toggle-images.js | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 js/toggle-images.js diff --git a/js/toggle-images.js b/js/toggle-images.js new file mode 100644 index 00000000..006b3622 --- /dev/null +++ b/js/toggle-images.js @@ -0,0 +1,50 @@ +/* + * toggle-images.js + * + * Released under the MIT license + * Copyright (c) 2012 Michael Save + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/toggle-images.js'; + * + */ + +$(document).ready(function(){ + var hide_images = localStorage['hideimages'] ? true : false; + + $('').appendTo($('head')); + + var hideImage = function() { + $(this) + .attr('data-orig', this.src) + .attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==') + .addClass('hidden'); + }; + + var restoreImage = function() { + $(this) + .attr('src', $(this).attr('data-orig')) + .removeClass('hidden'); + }; + + $('hr:first').before(''); + $('div#toggle-images a') + .text((hide_images ? 'Show' : 'Hide') + ' images') + .click(function() { + hide_images = !hide_images; + if (hide_images) { + $('div > a > img').each(hideImage); + localStorage.hideimages = true; + } else { + $('div > a > img').each(restoreImage); + delete localStorage.hideimages; + } + + $(this).text((hide_images ? 'Show' : 'Hide') + ' images') + }); + + if (hide_images) { + $('div > a > img').each(hideImage); + } +}); From a11c8981fe87f58d7205fc478c8ba68dca9aa3c2 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 26 Jul 2013 19:55:28 -0400 Subject: [PATCH 3/9] js/hide-images.js: Hide individual images --- js/hide-images.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 js/hide-images.js diff --git a/js/hide-images.js b/js/hide-images.js new file mode 100644 index 00000000..75dc07c2 --- /dev/null +++ b/js/hide-images.js @@ -0,0 +1,81 @@ +/* + * hide-images.js + * https://github.com/savetheinternet/Tinyboard/blob/master/js/hide-images.js + * + * Hide individual images. + * + * Released under the MIT license + * Copyright (c) 2013 Michael Save + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/hide-images.js'; + * + */ + +$(document).ready(function(){ + $('').appendTo($('head')); + + var board = $('form input[name="board"]').val().toString(); + + if (!localStorage.hiddenimages) + localStorage.hiddenimages = '{}'; + + // Load data from HTML5 localStorage + var hidden_data = JSON.parse(localStorage.hiddenimages); + + var store_data = function() { + localStorage.hiddenimages = JSON.stringify(hidden_data); + }; + + // Delete old hidden images (30+ days old) + for (var key in hidden_data) { + for (var id in hidden_data[key]) { + if (hidden_data[key][id] < Math.round(Date.now() / 1000) - 60 * 60 * 24 * 30) { + delete hidden_data[key][id]; + store_data(); + } + } + } + + if (!hidden_data[board]) { + hidden_data[board] = {}; // id : timestamp + } + + $('div.post > a > img, div > a > img').each(function() { + var img = this; + var fileinfo = $(this).parent().prev(); + var id = $(this).parent().parent().find('>p.intro>a.post_no:eq(1),>div.post.op>p.intro>a.post_no:eq(1)').text(); + + var replacement = $('File (hide): '); + + replacement.find('a').click(function() { + hidden_data[board][id] = Math.round(Date.now() / 1000); + store_data(); + + var show_link = $('show').click(function() { + delete hidden_data[board][id]; + store_data(); + + $(img) + .removeClass('hidden') + .attr('src', $(img).data('orig')); + $(this).prev().show(); + $(this).remove(); + }); + + $(this).hide().after(show_link); + + $(img) + .data('orig', img.src) + .attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==') + .addClass('hidden'); + }); + + $(this).parent().prev().contents().first().replaceWith(replacement); + + if (hidden_data[board][id]) + $(this).parent().prev().find('.hide-image-link').click(); + + }); +}); From c0a45ba1237fd54c0d5050d3a70abdea022ff6c3 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sat, 27 Jul 2013 00:14:43 -0400 Subject: [PATCH 4/9] Allow hide-images.js, toggle-images.js and inline-expanding.js to work together --- js/hide-images.js | 5 ++++- js/inline-expanding.js | 33 ++++++++++++++++++++------------- js/toggle-images.js | 29 ++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/js/hide-images.js b/js/hide-images.js index 75dc07c2..7344cd8f 100644 --- a/js/hide-images.js +++ b/js/hide-images.js @@ -53,7 +53,7 @@ $(document).ready(function(){ hidden_data[board][id] = Math.round(Date.now() / 1000); store_data(); - var show_link = $('show').click(function() { + var show_link = $('show').click(function() { delete hidden_data[board][id]; store_data(); @@ -66,6 +66,9 @@ $(document).ready(function(){ $(this).hide().after(show_link); + if ($(img).parent()[0].dataset.expanded == 'true') { + $(img).parent().click(); + } $(img) .data('orig', img.src) .attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==') diff --git a/js/inline-expanding.js b/js/inline-expanding.js index f6714d7f..2e924f05 100644 --- a/js/inline-expanding.js +++ b/js/inline-expanding.js @@ -3,7 +3,7 @@ * https://github.com/savetheinternet/Tinyboard/blob/master/js/inline-expanding.js * * Released under the MIT license - * Copyright (c) 2012 Michael Save + * Copyright (c) 2012-2013 Michael Save * * Usage: * $config['additional_javascript'][] = 'js/inline-expanding.js'; @@ -13,30 +13,37 @@ onready(function(){ var link = document.getElementsByTagName('a'); - for(var i = 0; i < link.length; i++) { - if(typeof link[i] == "object" && link[i].childNodes[0].src && link[i].className != 'file') { + for (var i = 0; i < link.length; i++) { + if (typeof link[i] == "object" && link[i].childNodes && link[i].childNodes[0].src && link[i].className != 'file') { link[i].childNodes[0].style.maxWidth = '95%'; link[i].childNodes[0].style.maxHeight = '95%'; link[i].onclick = function(e) { - if(e.which == 2) { + if (this.childNodes[0].className == 'hidden') + return false; + if (e.which == 2) return true; - } - if(!this.tag) { - this.tag = this.childNodes[0].src; + if (!this.dataset.src) { + this.dataset.expanded = 'true'; + this.dataset.src= this.childNodes[0].src; + this.dataset.width = this.childNodes[0].style.width; + this.dataset.height = this.childNodes[0].style.height; this.childNodes[0].src = this.href; this.childNodes[0].style.width = 'auto'; this.childNodes[0].style.height = 'auto'; this.childNodes[0].style.opacity = '0.4'; this.childNodes[0].style.filter = 'alpha(opacity=40)'; this.childNodes[0].onload = function() { - this.style.opacity = '1'; - this.style.filter = ''; + this.style.opacity = ''; + delete this.style.filter; } } else { - this.childNodes[0].src = this.tag; - this.childNodes[0].style.width = 'auto'; - this.childNodes[0].style.height = 'auto'; - this.tag = ''; + this.childNodes[0].src = this.dataset.src; + this.childNodes[0].style.width = this.dataset.width; + this.childNodes[0].style.height = this.dataset.height; + delete this.dataset.expanded; + delete this.dataset.src; + delete this.childNodes[0].style.opacity; + delete this.childNodes[0].style.filter; } return false; } diff --git a/js/toggle-images.js b/js/toggle-images.js index 006b3622..74f2fab4 100644 --- a/js/toggle-images.js +++ b/js/toggle-images.js @@ -16,6 +16,9 @@ $(document).ready(function(){ $('').appendTo($('head')); var hideImage = function() { + if ($(this).parent()[0].dataset.expanded == 'true') { + $(this).parent().click(); + } $(this) .attr('data-orig', this.src) .attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==') @@ -28,6 +31,27 @@ $(document).ready(function(){ .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(); + } + }); + } + }; + $('hr:first').before(''); $('div#toggle-images a') .text((hide_images ? 'Show' : 'Hide') + ' images') @@ -40,11 +64,14 @@ $(document).ready(function(){ $('div > a > img').each(restoreImage); delete localStorage.hideimages; } - + + show_hide_hide_images_buttons(); + $(this).text((hide_images ? 'Show' : 'Hide') + ' images') }); if (hide_images) { $('div > a > img').each(hideImage); + show_hide_hide_images_buttons(); } }); From 6bf217941a3342cdcf7768ab5269f7d35b050984 Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 26 Jul 2013 22:34:06 -0400 Subject: [PATCH 5/9] expand.js: fix a weird bug - thread expand not always worked due to post being loaded in DOM, but not put in a right place in a thread, or so, so check if it has been loaded in a thread instead of if it exists in DOM --- js/expand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/expand.js b/js/expand.js index 05aece95..d0b4583c 100644 --- a/js/expand.js +++ b/js/expand.js @@ -27,7 +27,7 @@ $(document).ready(function(){ success: function(data) { var last_expanded = false; $(data).find('div.post.reply').each(function() { - if($('#' + $(this).attr('id')).length == 0) { + if(thread.find('#' + $(this).attr('id')).length == 0) { if(last_expanded) { $(this).addClass('expanded').insertAfter(last_expanded).before('
'); } else { From d82cd9b7bd03708f4940b4508acd0394713b8869 Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 26 Jul 2013 22:39:00 -0400 Subject: [PATCH 6/9] expand.js: fix post order when new posts appear between loading index and expanding --- js/expand.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/expand.js b/js/expand.js index d0b4583c..16a0efb2 100644 --- a/js/expand.js +++ b/js/expand.js @@ -27,7 +27,8 @@ $(document).ready(function(){ success: function(data) { var last_expanded = false; $(data).find('div.post.reply').each(function() { - if(thread.find('#' + $(this).attr('id')).length == 0) { + var post_in_doc = thread.find('#' + $(this).attr('id')); + if(post_in_doc.length == 0) { if(last_expanded) { $(this).addClass('expanded').insertAfter(last_expanded).before('
'); } else { @@ -36,6 +37,9 @@ $(document).ready(function(){ last_expanded = $(this); } + else { + last_expanded = post_in_doc; + } }); $('Hide expanded replies.') .insertAfter(thread.find('span.omitted').css('display', 'none')) From c51dc146e2248a09d97941a73ac5ef65ee4e1085 Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 26 Jul 2013 14:27:38 -0400 Subject: [PATCH 7/9] hide-threads.js: show post hider even in posts without an image --- js/hide-threads.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/hide-threads.js b/js/hide-threads.js index 734dfe78..03c33a3f 100644 --- a/js/hide-threads.js +++ b/js/hide-threads.js @@ -45,7 +45,7 @@ $(document).ready(function(){ var id = $(this).children('p.intro').children('a.post_no:eq(1)').text(); var thread_container = $(this).parent(); $('[–] ') - .insertBefore(thread_container.find('p.fileinfo:first')) + .insertBefore(thread_container.find(':first')) .click(function() { hidden_data[board][id] = Math.round(Date.now() / 1000); store_data(); From 4b50f1475e5cdf6afa2db0aef0345ad00a9d6a7f Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 26 Jul 2013 14:57:08 -0400 Subject: [PATCH 8/9] hide-threads.js: fix previous commit --- js/hide-threads.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/hide-threads.js b/js/hide-threads.js index 03c33a3f..14893e05 100644 --- a/js/hide-threads.js +++ b/js/hide-threads.js @@ -67,7 +67,7 @@ $(document).ready(function(){ hidden_div.remove(); }); - hidden_div.insertAfter(thread_container.find('p.fileinfo:first')); + hidden_div.insertAfter(thread_container.find(':first')); }); if (hidden_data[board][id]) thread_container.find('.hide-thread-link').click(); From 1c33285c81efe174f09e99b15be81f527c0f8ae0 Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 26 Jul 2013 15:31:20 -0400 Subject: [PATCH 9/9] hide-threads.js: further fixes and customisations, mainly due to unexpanding previously not working here, but working on another boards (4chon, etc.) Conflicts: stylesheets/style.css --- js/hide-threads.js | 7 ++++--- stylesheets/style.css | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/js/hide-threads.js b/js/hide-threads.js index 14893e05..faa1289c 100644 --- a/js/hide-threads.js +++ b/js/hide-threads.js @@ -54,11 +54,12 @@ $(document).ready(function(){ var hidden_div = thread_container.find('div.post.op > p.intro').clone(); hidden_div.addClass('thread-hidden'); - hidden_div.find('a[href],input').remove(); + hidden_div.find('a[href]:not([href$=".html"]),input').remove(); + hidden_div.html(hidden_div.html().replace(' [] ', ' ')); hidden_div.html(hidden_div.html().replace(' [] ', ' ')); - $('[+] ') - .insertAfter(thread_container.find('a.hide-thread-link')) + $('[+] ') + .insertBefore(hidden_div.find(':first')) .click(function() { delete hidden_data[board][id]; store_data(); diff --git a/stylesheets/style.css b/stylesheets/style.css index 12cc54d5..c0430b7c 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -404,3 +404,8 @@ table.mod.config-editor td { table.mod.config-editor input[type="text"] { width: 98%; } +p.intro.thread-hidden { + margin: 0px; + padding: 0px; +} +