From 1ea3da1db6c5291abfbd99aa8f5f7e28de8ed9ed Mon Sep 17 00:00:00 2001 From: 8chan Date: Sun, 10 Aug 2014 14:51:45 +0000 Subject: [PATCH 01/11] Merge Barrucadu/diceroll into master --- inc/config.php | 4 ++++ inc/functions.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/inc/config.php b/inc/config.php index 91e53a6d..802a1471 100644 --- a/inc/config.php +++ b/inc/config.php @@ -549,6 +549,10 @@ 'eu' => 'Europe' ); */ + + // Allow dice rolling: an email field of the form "dice XdY+/-Z" will result in X Y-sided dice rolled and summed, + // with the modifier Z added, with the result displayed at the top of the post body. + $config['allow_roll'] = false; /* * ==================== diff --git a/inc/functions.php b/inc/functions.php index af2136bb..24ec3863 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -243,6 +243,9 @@ function loadConfig() { if (is_array($config['anonymous'])) $config['anonymous'] = $config['anonymous'][array_rand($config['anonymous'])]; + if ($config['allow_roll']) + event_handler('post', 'diceRoller'); + event('load-config'); if ($config['debug']) { @@ -2323,3 +2326,61 @@ function shell_exec_error($command, $suppress_stdout = false) { return $return === 'TB_SUCCESS' ? false : $return; } + +/* Die rolling: + * If "dice XdY+/-Z" is in the email field (where X or +/-Z may be + * missing), X Y-sided dice are rolled and summed, with the modifier Z + * added on. The result is displayed at the top of the post. + */ +function diceRoller($post) { + if(strpos(strtolower($post->email), 'dice%20') === 0) { + $dicestr = str_split(substr($post->email, strlen('dice%20'))); + + // Get params + $diceX = ''; + $diceY = ''; + $diceZ = ''; + + $curd = 'diceX'; + for($i = 0; $i < count($dicestr); $i ++) { + if(is_numeric($dicestr[$i])) { + $$curd .= $dicestr[$i]; + } else if($dicestr[$i] == 'd') { + $curd = 'diceY'; + } else if($dicestr[$i] == '-' || $dicestr[$i] == '+') { + $curd = 'diceZ'; + $$curd = $dicestr[$i]; + } + } + + // Default values for X and Z + if($diceX == '') { + $diceX = '1'; + } + + if($diceZ == '') { + $diceZ = '+0'; + } + + // Intify them + $diceX = intval($diceX); + $diceY = intval($diceY); + $diceZ = intval($diceZ); + + // Continue only if we have valid values + if($diceX > 0 && $diceY > 0) { + $dicerolls = array(); + $dicesum = $diceZ; + for($i = 0; $i < $diceX; $i++) { + $roll = rand(1, $diceY); + $dicerolls[] = $roll; + $dicesum += $roll; + } + + // Prepend the result to the post body + $modifier = ($diceZ != 0) ? ((($diceZ < 0) ? ' - ' : ' + ') . abs($diceZ)) : ''; + $dicesum = ($diceX > 1) ? ' = ' . $dicesum : ''; + $post->body = 'Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '
' . $post->body; + } + } +} From e28f233e3de6d471ab2ce9c178ba8d626bbeb563 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sun, 10 Aug 2014 15:14:11 +0000 Subject: [PATCH 02/11] Close #51: Prevent players from cheating the dice roller by using markup --- inc/functions.php | 3 +- static/d10.svg | 161 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 static/d10.svg diff --git a/inc/functions.php b/inc/functions.php index 24ec3863..a88e8fc8 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2333,6 +2333,7 @@ function shell_exec_error($command, $suppress_stdout = false) { * added on. The result is displayed at the top of the post. */ function diceRoller($post) { + global $config; if(strpos(strtolower($post->email), 'dice%20') === 0) { $dicestr = str_split(substr($post->email, strlen('dice%20'))); @@ -2380,7 +2381,7 @@ function diceRoller($post) { // Prepend the result to the post body $modifier = ($diceZ != 0) ? ((($diceZ < 0) ? ' - ' : ' + ') . abs($diceZ)) : ''; $dicesum = ($diceX > 1) ? ' = ' . $dicesum : ''; - $post->body = 'Rolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '
' . $post->body; + $post->body = '
Dice rollRolled ' . implode(', ', $dicerolls) . $modifier . $dicesum . '

' . $post->body; } } } diff --git a/static/d10.svg b/static/d10.svg new file mode 100644 index 00000000..4d608be7 --- /dev/null +++ b/static/d10.svg @@ -0,0 +1,161 @@ + + + + Ten Side Dice + + + + + + + + image/svg+xml + + + + + Openclipart + + + Ten Sided Dice + 2010-11-06T04:13:53 + A single-colour graphic of a 10-sided die (d10) as used in roleplaying and wargaming. + https://openclipart.org/detail/94495/ten-sided-dice-by-wirelizard + + + wirelizard + + + + + RPG + d10 + dice + die + game + gamer + gaming + roleplay + ten side + + + + + + + + + + + From 91519d90529c60f3d11b33b1b9ab055f339c2968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=81abanowski?= Date: Sun, 10 Aug 2014 18:44:23 +0200 Subject: [PATCH 03/11] hopefully optimize watch.js a lot. fixes #24 --- js/watch.js | 83 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/js/watch.js b/js/watch.js index 5c111bcd..0d65839b 100644 --- a/js/watch.js +++ b/js/watch.js @@ -152,12 +152,21 @@ $(function(){ }; var update_pinned = function() { + if (updating_suspended) return; + if (typeof update_title != "undefined") update_title(); var bl = $('.boardlist').first(); $('#watch-pinned, .watch-menu').remove(); var pinned = $('
').appendTo(bl); + if (device_type == "desktop") + bl.off().on("mouseenter", function() { + updating_suspended = true; + }).on("mouseleave", function() { + updating_suspended = false; + }); + var st = storage(); for (var i in st) { if (is_pinned(st[i])) { @@ -198,7 +207,6 @@ $(function(){ if (device_type == "desktop") link.off().mouseenter(function() { - updating_suspended = true; $('.cb-menu').remove(); var board = $(this).attr("data-board"); @@ -216,7 +224,6 @@ $(function(){ wl.find("a.cb-menuitem").each(init_hover); }).mouseleave(function() { - updating_suspended = false; $('.boardlist .cb-menu').remove(); }); } @@ -232,30 +239,45 @@ $(function(){ } }; var fetch_jsons = function() { - if (updating_suspended) return; if (window_active) check_scroll(); var st = storage(); + + var sched = 0; + var sched_diff = 100; + for (var i in st) { if (st[i].watched) { - var r = $.getJSON(configRoot+i+"/threads.json", function(j, x, r) { - handle_board_json(r.board, j); - }); - r.board = i; + (function(i) { + setTimeout(function() { + var r = $.getJSON(configRoot+i+"/threads.json", function(j, x, r) { + handle_board_json(r.board, j); + }); + r.board = i; + }, sched); + sched += sched_diff; + })(i); } else if (st[i].threads) { for (var j in st[i].threads) { - var r = $.getJSON(configRoot+i+"/res/"+j+".json", function(k, x, r) { - handle_thread_json(r.board, r.thread, k); - }).error(function(r) { - if(r.status == 404) handle_thread_404(r.board, r.thread); - }); - - r.board = i; - r.thread = j; + (function(i,j) { + setTimeout(function() { + var r = $.getJSON(configRoot+i+"/res/"+j+".json", function(k, x, r) { + handle_thread_json(r.board, r.thread, k); + }).error(function(r) { + if(r.status == 404) handle_thread_404(r.board, r.thread); + }); + + r.board = i; + r.thread = j; + }, sched); + })(i,j); + sched += sched_diff; } } } + + setTimeout(fetch_jsons, sched + sched_diff); }; var handle_board_json = function(board, json) { @@ -293,31 +315,39 @@ $(function(){ status = status || {}; status[board] = status[board] || {}; - status[board].last_thread = last_thread; - status[board].new_threads = new_threads; - update_pinned(); + if (status[board].last_thread != last_thread || status[board].new_threads != new_threads) { + status[board].last_thread = last_thread; + status[board].new_threads = new_threads; + update_pinned(); + } }; var handle_thread_json = function(board, threadid, json) { + var new_posts = 0; for (var i in json.posts) { var post = json.posts[i]; - var new_posts = 0; if (post.time > storage()[board].threads[threadid] / 1000) { new_posts++; } - status = status || {}; - status[board] = status[board] || {}; - status[board].threads = status[board].threads || {}; + } + + status = status || {}; + status[board] = status[board] || {}; + status[board].threads = status[board].threads || {}; + + if (status[board].threads[threadid] != new_posts) { status[board].threads[threadid] = new_posts; update_pinned(); - } + } }; var handle_thread_404 = function(board, threadid) { status = status || {}; status[board] = status[board] || {}; status[board].threads = status[board].threads || {}; - status[board].threads[threadid] = -404; //notify 404 - update_pinned(); + if (status[board].threads[threadid] != -404) { + status[board].threads[threadid] = -404; //notify 404 + update_pinned(); + } }; if (active_page == "thread") { @@ -386,7 +416,7 @@ $(function(){ $(window).scroll(function() { var refresh = check_scroll(); if (refresh) { - fetch_jsons(); + //fetch_jsons(); refresh = false; } }); @@ -417,5 +447,4 @@ $(function(){ update_pinned(); fetch_jsons(); - setInterval(fetch_jsons, 10000); }); From 4d25ca85ce670e59806ea392855c6b3878519ee8 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 10 Aug 2014 20:55:37 +0200 Subject: [PATCH 04/11] live-index.js: initial commit --- js/expand.js | 16 +++++---- js/live-index.js | 84 +++++++++++++++++++++++++++++++++++++++++++ stylesheets/style.css | 9 +++++ 3 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 js/live-index.js diff --git a/js/expand.js b/js/expand.js index 0256aebe..0fa8de05 100644 --- a/js/expand.js +++ b/js/expand.js @@ -20,8 +20,8 @@ $(document).ready(function(){ var do_expand = function() { $(this) .html($(this).text().replace(_("Click reply to view."), ''+_("Click to expand")+'.')) - .find('a').click(function() { - var thread = $(this).parent().parent().parent(); + .find('a').click(window.expand_fun = function() { + var thread = $(this).parents('[id^="thread_"]'); var id = thread.attr('id').replace(/^thread_/, ''); $.ajax({ url: thread.find('p.intro a.post_no:first').attr('href'), @@ -43,12 +43,16 @@ $(document).ready(function(){ last_expanded = post_in_doc; } }); - $('' + _('Hide expanded replies') + '.') - .insertAfter(thread.find('span.omitted').css('display', 'none')) + + + thread.find("span.omitted").css('display', 'none'); + + $('' + _('Hide expanded replies') + '.') + .insertAfter(thread.find('.op div.body, .op span.omitted').last()) .click(function() { thread.find('.expanded').remove(); - $(this).prev().css('display', ''); - $(this).remove(); + $(this).parent().find(".omitted:not(.hide-expanded)").css('display', ''); + $(this).parent().find(".hide-expanded").remove(); }); } }); diff --git a/js/live-index.js b/js/live-index.js new file mode 100644 index 00000000..dabb34fc --- /dev/null +++ b/js/live-index.js @@ -0,0 +1,84 @@ +/* + * live-index.js + * https://github.com/vichan-devel/Tinyboard/blob/master/js/live-index.js + * + * Released under the MIT license + * Copyright (c) 2014 Marcin Ɓabanowski + * + * Usage: + * $config['api']['enabled'] = true; + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/expand.js'; + * $config['additional_javascript'][] = 'js/live-index.js'; + * + */ + +if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?|$)/)) ++function() { + var board_name = (""+document.location).match(/\/([^\/])\/[^/]*$/)[1]; + + var handle_one_thread = function() { + $(this).find("br.clear").before("
"+_("No new posts.")+"
") + }; + + $(function() { + $("hr:first").before("
"+_("No new threads.")+"
"); + + $('div[id^="thread_"]').each(handle_one_thread); + }); + + $(document).on("new_post", function(e, post) { + if (!$(post).hasClass("reply")) { + handle_one_thread.bind(post); + } + }); + + var update_new_threads = function(i) { + var msg = i ? + fmt(_("There are {0} new threads."), [i]) : + _("No new threads."); + + if ($(".new-threads").html() != msg) + $(".new-threads").html(msg); + }; + + var update_new_posts = function(i, th) { + var msg = (i>0) ? + (fmt(_("There are {0} new posts in this thread."), [i])+" "+_("Click to expand")+".") : + _("No new posts."); + + if ($(th).find(".new-posts").html() != msg) { + $(th).find(".new-posts").html(msg); + $(th).find(".new-posts a").click(window.expand_fun); + } + }; + + setInterval(function() { + $.getJSON(configRoot+board_name+"/0.json", function(j, x, r) { + var new_threads = 0; + + j.threads.forEach(function(t) { + var s_thread = $("#thread_"+t.posts[0].no); + + if (s_thread.length) { + var my_posts = s_thread.find(".post.reply").length; + + var omitted_posts = s_thread.find(".omitted"); + if (omitted_posts.length) { + omitted_posts = omitted_posts.html().match("^[^0-9]*([0-9]+)")[1]|0; + my_posts += omitted_posts; + } + + my_posts -= t.posts[0].replies|0; + my_posts *= -1; + update_new_posts(my_posts, s_thread); + } + else { + new_threads++; + } + }); + + update_new_threads(new_threads); + }); + }, 500); +}(); diff --git a/stylesheets/style.css b/stylesheets/style.css index 4d6ee5ab..3688b939 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -627,3 +627,12 @@ form.ban-appeal textarea { padding: 0; margin: 5px 25px 5px 5px; } + +/* live-index.js */ +.new-posts { + opacity: 0.6; + margin-top: 1em; +} +.new-threads { + text-align: center; +} From 169d088c5024bdef407434b8df624a81876c1738 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 10 Aug 2014 21:00:31 +0200 Subject: [PATCH 05/11] increase waiting times for watch.js and live-index.js --- js/live-index.js | 2 +- js/watch.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/live-index.js b/js/live-index.js index dabb34fc..db7b141d 100644 --- a/js/live-index.js +++ b/js/live-index.js @@ -80,5 +80,5 @@ if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?| update_new_threads(new_threads); }); - }, 500); + }, 2000); }(); diff --git a/js/watch.js b/js/watch.js index 0d65839b..4c36dbc4 100644 --- a/js/watch.js +++ b/js/watch.js @@ -244,7 +244,7 @@ $(function(){ var st = storage(); var sched = 0; - var sched_diff = 100; + var sched_diff = 300; for (var i in st) { if (st[i].watched) { From e1d99e66b558f53ca23870bcf8ffc1858e249207 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 10 Aug 2014 22:45:12 +0200 Subject: [PATCH 06/11] hide-threads.js: hide field from live-index as well --- 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 b26feca3..c8aa2a03 100644 --- a/js/hide-threads.js +++ b/js/hide-threads.js @@ -36,7 +36,7 @@ $(document).ready(function(){ } } - var fields_to_hide = 'div.post,div.video-container,video,img,p.fileinfo,a.hide-thread-link,br'; + var fields_to_hide = 'div.post,div.video-container,video,img,p.fileinfo,a.hide-thread-link,div.new-posts,br'; var do_hide_threads = function() { var id = $(this).children('p.intro').children('a.post_no:eq(1)').text(); From 48c1de637c8371253636eea25c7c046353a3d1ed Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 10 Aug 2014 22:47:05 +0200 Subject: [PATCH 07/11] live-index.js: load new thread functionality; bugfixes --- js/live-index.js | 77 ++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/js/live-index.js b/js/live-index.js index db7b141d..8bce94f0 100644 --- a/js/live-index.js +++ b/js/live-index.js @@ -13,33 +13,69 @@ * */ -if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?|$)/)) +if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?|$|#)/)) +function() { + // Make jQuery respond to reverse() + $.fn.reverse = [].reverse; + var board_name = (""+document.location).match(/\/([^\/])\/[^/]*$/)[1]; var handle_one_thread = function() { - $(this).find("br.clear").before("
"+_("No new posts.")+"
") + if ($(this).find(".new-posts").length <= 0) { + $(this).find("br.clear").before("
"+_("No new posts.")+"
"); + } }; $(function() { $("hr:first").before("
"+_("No new threads.")+"
"); $('div[id^="thread_"]').each(handle_one_thread); + + setInterval(function() { + $.getJSON(configRoot+board_name+"/0.json", function(j) { + var new_threads = 0; + + j.threads.forEach(function(t) { + var s_thread = $("#thread_"+t.posts[0].no); + + if (s_thread.length) { + var my_posts = s_thread.find(".post.reply").length; + + var omitted_posts = s_thread.find(".omitted"); + if (omitted_posts.length) { + omitted_posts = omitted_posts.html().match("^[^0-9]*([0-9]+)")[1]|0; + my_posts += omitted_posts; + } + + my_posts -= t.posts[0].replies|0; + my_posts *= -1; + update_new_posts(my_posts, s_thread); + } + else { + new_threads++; + } + }); + + update_new_threads(new_threads); + }); + }, 1000); }); $(document).on("new_post", function(e, post) { if (!$(post).hasClass("reply")) { - handle_one_thread.bind(post); + handle_one_thread.call(post); } }); var update_new_threads = function(i) { var msg = i ? - fmt(_("There are {0} new threads."), [i]) : + (fmt(_("There are {0} new threads."), [i]) + " "+_("Click to expand")+".") : _("No new threads."); - if ($(".new-threads").html() != msg) + if ($(".new-threads").html() != msg) { $(".new-threads").html(msg); + $(".new-threads a").click(fetch_new_threads); + } }; var update_new_posts = function(i, th) { @@ -53,32 +89,17 @@ if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?| } }; - setInterval(function() { - $.getJSON(configRoot+board_name+"/0.json", function(j, x, r) { - var new_threads = 0; - - j.threads.forEach(function(t) { - var s_thread = $("#thread_"+t.posts[0].no); - - if (s_thread.length) { - var my_posts = s_thread.find(".post.reply").length; - - var omitted_posts = s_thread.find(".omitted"); - if (omitted_posts.length) { - omitted_posts = omitted_posts.html().match("^[^0-9]*([0-9]+)")[1]|0; - my_posts += omitted_posts; - } - - my_posts -= t.posts[0].replies|0; - my_posts *= -1; - update_new_posts(my_posts, s_thread); + var fetch_new_threads = function() { + $.get(""+document.location, function(data) { + $(data).find('div[id^="thread_"]').reverse().each(function() { + if ($("#"+$(this).attr("id")).length) { + // okay, the thread is there } else { - new_threads++; + var thread = $(this).insertBefore('div[id^="thread_"]:first'); + $(document).trigger("new_post", this); } }); - - update_new_threads(new_threads); }); - }, 2000); + }; }(); From 1a1d44aadfdab2cc0ee3f74bae96090b9fd09e5f Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 10 Aug 2014 22:49:23 +0200 Subject: [PATCH 08/11] live-index: fix for boards with more than one letter in name --- js/live-index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/live-index.js b/js/live-index.js index 8bce94f0..463f7596 100644 --- a/js/live-index.js +++ b/js/live-index.js @@ -18,7 +18,7 @@ if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?| // Make jQuery respond to reverse() $.fn.reverse = [].reverse; - var board_name = (""+document.location).match(/\/([^\/])\/[^/]*$/)[1]; + var board_name = (""+document.location).match(/\/([^\/]+)\/[^/]*$/)[1]; var handle_one_thread = function() { if ($(this).find(".new-posts").length <= 0) { From 4d7933deb8516a96690cd42f0780dbaca2ab7bb7 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 10 Aug 2014 22:54:47 +0200 Subject: [PATCH 09/11] fix hide-threads.js & no-animated-gif.js interaction --- js/hide-threads.js | 2 +- js/no-animated-gif.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/hide-threads.js b/js/hide-threads.js index c8aa2a03..f83b479b 100644 --- a/js/hide-threads.js +++ b/js/hide-threads.js @@ -36,7 +36,7 @@ $(document).ready(function(){ } } - var fields_to_hide = 'div.post,div.video-container,video,img,p.fileinfo,a.hide-thread-link,div.new-posts,br'; + var fields_to_hide = 'div.post,div.video-container,video,img:not(.unanimated),canvas,p.fileinfo,a.hide-thread-link,div.new-posts,br'; var do_hide_threads = function() { var id = $(this).children('p.intro').children('a.post_no:eq(1)').text(); diff --git a/js/no-animated-gif.js b/js/no-animated-gif.js index 36d48954..5d21704f 100644 --- a/js/no-animated-gif.js +++ b/js/no-animated-gif.js @@ -24,7 +24,7 @@ function unanimate_gif(e) { draw_image(); } - $(e).hide(); + $(e).addClass("unanimated").hide(); } function no_animated_gif() { @@ -37,7 +37,7 @@ function no_animated_gif() { function animated_gif() { $('canvas.post-image').remove(); - $('img.post-image').show(); + $('img.post-image').removeClass("unanimated").show(); localStorage.no_animated_gif = false; $('#no-animated-gif>a').text(_('Unanimate GIFs')); From d78dcd6ed6efefba9b67529663610b62e8b38228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=81abanowski?= Date: Thu, 21 Aug 2014 04:27:25 +0200 Subject: [PATCH 10/11] fix a bug reported by Dudeman on #v-d --- inc/display.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/display.php b/inc/display.php index 9397b4a9..1a78e19b 100644 --- a/inc/display.php +++ b/inc/display.php @@ -353,7 +353,7 @@ class Post { $this->{$key} = $value; } - if (isset($this->files)) + if (isset($this->files) && $this->files) $this->files = json_decode($this->files); $this->subject = utf8tohtml($this->subject); From 1b62fbea6f19bae1fd09e76de533e507aa50fc46 Mon Sep 17 00:00:00 2001 From: Tomasz Konojacki Date: Sun, 24 Aug 2014 23:33:53 +0200 Subject: [PATCH 11/11] added support for statcounter.com tracking code --- inc/config.php | 5 +++++ templates/main.js | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/inc/config.php b/inc/config.php index 802a1471..41cbbd12 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1526,6 +1526,11 @@ // Keep the Google Analytics cookies to one domain -- ga._setDomainName() // $config['google_analytics_domain'] = 'www.example.org'; + // Link imageboard to your Statcounter.com account to track users and provide traffic insights without the Google botnet. + // Extract these values from Statcounter's JS tracking code: + // $config['statcounter_project'] = '1234567'; + // $config['statcounter_security'] = 'acbd1234'; + // If you use Varnish, Squid, or any similar caching reverse-proxy in front of Tinyboard, you can // configure Tinyboard to PURGE files when they're written to. // $config['purge'] = array( diff --git a/templates/main.js b/templates/main.js index f7b99a42..97f1135f 100644 --- a/templates/main.js +++ b/templates/main.js @@ -305,3 +305,11 @@ onready(init); var _gaq = _gaq || [];_gaq.push(['_setAccount', '{% endraw %}{{ config.google_analytics }}{% raw %}']);{% endraw %}{% if config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', '{% endraw %}{{ config.google_analytics_domain }}{% raw %}']){% endraw %}{% endif %}{% if not config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', 'none']){% endraw %}{% endif %}{% raw %};_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();{% endraw %}{% endif %} +{% if config.statcounter_project and config.statcounter_security %} +var sc = document.createElement('script'); +sc.type = 'text/javascript'; +sc.innerHTML = 'var sc_project={{ config.statcounter_project }};var sc_invisible=1;var sc_security="{{ config.statcounter_security }}";var scJsHost=(("https:" == document.location.protocol) ? "https://secure." : "http://www.");document.write("");'; +var s = document.getElementsByTagName('script')[0]; +s.parentNode.insertBefore(sc, s); +{% endif %} +