From 5d8d20fcc5c8a2364d51158813f439eff4de3cc8 Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 24 Sep 2014 21:29:12 +0000 Subject: Add timer to auto reload js Conflicts: js/auto-reload.js --- js/auto-reload.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 4a872024..886f32e6 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -8,6 +8,7 @@ * Copyright (c) 2012 Michael Save * Copyright (c) 2013-2014 Marcin Ɓabanowski * Copyright (c) 2013 undido + * Copyright (c) 2014 Fredrick Brennan * * Usage: * $config['additional_javascript'][] = 'js/jquery.min.js'; @@ -27,6 +28,8 @@ $(document).ready(function(){ var poll_interval; + // Add an update link + $('.boardlist.bottom').prev().after("["+_("Update thread")+"] ()"); // Grab the settings var settings = new script_settings('auto-reload'); @@ -37,6 +40,7 @@ $(document).ready(function(){ // number of ms to wait before reloading var poll_interval_delay = poll_interval_mindelay_bottom; + var poll_current_time = poll_interval_delay; var end_of_page = false; @@ -68,6 +72,14 @@ $(document).ready(function(){ window_active = false; }); + var timer_update = function() { + $('#update_secs').text(poll_current_time/1000); + } + + var decrement_timer = function() { + poll_current_time = poll_current_time - 1000; + } + var recheck_activated = function() { if (new_posts && window_active && $(window).scrollTop() + $(window).height() >= @@ -115,6 +127,7 @@ $(document).ready(function(){ } poll_interval = setTimeout(poll, poll_interval_delay); + poll_current_time = poll_interval_delay; }; $(window).scroll(function() { @@ -128,9 +141,15 @@ $(document).ready(function(){ clearTimeout(poll_interval); poll_interval = setTimeout(poll, poll_interval_shortdelay); + poll_current_time = poll_interval_shortdelay; end_of_page = true; }).trigger('scroll'); - poll_interval = setTimeout(poll, poll_interval_delay); + $('#update_thread').on('click', poll); + setInterval(timer_update, 1000); + setInterval(decrement_timer, 1000); + + poll_interval = setInterval(poll, poll_interval_delay); + timer_update(); }); -- cgit v1.3 From ed5272f17d22be01770361c3950fe5fbc32cfb7f Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 25 Sep 2014 06:31:40 +0200 Subject: auto-reload.js: don`t scroll up --- js/auto-reload.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 886f32e6..1f4d11fe 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -128,6 +128,8 @@ $(document).ready(function(){ poll_interval = setTimeout(poll, poll_interval_delay); poll_current_time = poll_interval_delay; + + return false; }; $(window).scroll(function() { -- cgit v1.3 From dbaeb395acf6ad1e95f7623c2853d9d702920bb5 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 25 Sep 2014 06:32:53 +0200 Subject: auto-reload.js: it`s actually setTimeout, not setInterval, right? --- js/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 1f4d11fe..87e332df 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -151,7 +151,7 @@ $(document).ready(function(){ setInterval(timer_update, 1000); setInterval(decrement_timer, 1000); - poll_interval = setInterval(poll, poll_interval_delay); + poll_interval = setTimeout(poll, poll_interval_delay); timer_update(); }); -- cgit v1.3 From 9a096f58886725f420a9ec6ce1ec8efb4c0b7c72 Mon Sep 17 00:00:00 2001 From: topkek Date: Sun, 28 Sep 2014 00:16:16 +0100 Subject: Update auto-reload.js --- js/auto-reload.js | 136 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 46 deletions(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 87e332df..0e4b730a 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -24,31 +24,37 @@ $(document).ready(function(){ return; // not index if($(".post.op").size() != 1) - return; //not thread page + return; //not thread page - var poll_interval; + var countdown_interval; // Add an update link - $('.boardlist.bottom').prev().after("["+_("Update thread")+"] ()"); + $('.boardlist.bottom').prev().after("["+_("Update")+"] ( Auto) "); // Grab the settings var settings = new script_settings('auto-reload'); - var poll_interval_mindelay_bottom = settings.get('min_delay_bottom', 3000); - var poll_interval_mindelay_top = settings.get('min_delay_top', 10000); + var poll_interval_mindelay_bottom = settings.get('min_delay_bottom', 5000); var poll_interval_maxdelay = settings.get('max_delay', 600000); - var poll_interval_shortdelay = settings.get('quick_delay', 100); // number of ms to wait before reloading - var poll_interval_delay = poll_interval_mindelay_bottom; + var poll_interval_delay = poll_interval_mindelay; var poll_current_time = poll_interval_delay; var end_of_page = false; var new_posts = 0; var first_new_post = null; + + var title = document.title; if (typeof update_title == "undefined") { - var update_title = function() { }; + var update_title = function() { + if (new_posts) { + document.title = "("+new_posts+") "+title; + } else { + document.title = title; + } + }; } if (typeof add_title_collector != "undefined") @@ -63,37 +69,67 @@ $(document).ready(function(){ // Reset the delay if needed if(settings.get('reset_focus', true)) { - poll_interval_delay = end_of_page - ? poll_interval_mindelay_bottom - : poll_interval_mindelay_top; + poll_interval_delay = poll_interval_mindelay; } }); $(window).blur(function() { window_active = false; }); - var timer_update = function() { - $('#update_secs').text(poll_current_time/1000); - } + + $('#auto_update_status').click(function() { + if($("#auto_update_status").is(':checked')) { + auto_update(poll_interval_mindelay); + } else { + stop_auto_update(); + $('#update_secs').text(""); + } + + }); + var decrement_timer = function() { poll_current_time = poll_current_time - 1000; + $('#update_secs').text(poll_current_time/1000); + + if (poll_current_time <= 0) { + poll(manualUpdate = false); + } } var recheck_activated = function() { if (new_posts && window_active && $(window).scrollTop() + $(window).height() >= - $(first_new_post).position().top) { + $('div.boardlist.bottom').position().top) { new_posts = 0; } update_title(); + first_new_post = null; }; + + // automatically updates the thread after a specified delay + var auto_update = function(delay) { + clearInterval(countdown_interval); - var poll = function() { + poll_current_time = delay; + countdown_interval = setInterval(decrement_timer, 1000); + $('#update_secs').text(poll_current_time/1000); + } + + var stop_auto_update = function() { + clearInterval(countdown_interval); + } + + + var poll = function(manualUpdate) { + stop_auto_update(); + $('#update_secs').text("Updating..."); + $.ajax({ url: document.location, success: function(data) { + var loaded_posts = 0; // the number of new posts loaded in this update $(data).find('div.post.reply').each(function() { var id = $(this).attr('id'); if($('#' + id).length == 0) { @@ -102,56 +138,64 @@ $(document).ready(function(){ } $(this).insertAfter($('div.post:last').next()).after('
'); new_posts++; + loaded_posts++; $(document).trigger('new_post', this); recheck_activated(); } }); time_loaded = Date.now(); // interop with watch.js + + + if ($('#auto_update_status').is(':checked')) { + // If there are no new posts, double the delay. Otherwise set it to the min. + if(loaded_posts == 0) { + // if the update was manual, don't increase the delay + if (manualUpdate == false) { + poll_interval_delay *= 2; + + // Don't increase the delay beyond the maximum + if(poll_interval_delay > poll_interval_maxdelay) { + poll_interval_delay = poll_interval_maxdelay; + } + } + } else { + poll_interval_delay = poll_interval_mindelay; + } + + auto_update(poll_interval_delay); + } else { + // Decide the message to show if auto update is disabled + if (loaded_posts > 0) + $('#update_secs').text("Thread updated with "+loaded_posts+" new post(s)"); + else + $('#update_secs').text("No new posts found"); + } } }); - clearTimeout(poll_interval); - - // If there are no new posts, double the delay. Otherwise set it to the min. - if(new_posts == 0) { - poll_interval_delay *= 2; - - // Don't increase the delay beyond the maximum - if(poll_interval_delay > poll_interval_maxdelay) { - poll_interval_delay = poll_interval_maxdelay; - } - } else { - poll_interval_delay = end_of_page - ? poll_interval_mindelay_bottom - : poll_interval_mindelay_top; - } - - poll_interval = setTimeout(poll, poll_interval_delay); - poll_current_time = poll_interval_delay; - return false; }; $(window).scroll(function() { recheck_activated(); - + + // if the newest post is not visible if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) { end_of_page = false; return; + } else { + if($("#auto_update_status").is(':checked')) { + poll(manualUpdate = true); + } + end_of_page = true; } - - clearTimeout(poll_interval); - poll_interval = setTimeout(poll, poll_interval_shortdelay); - poll_current_time = poll_interval_shortdelay; - end_of_page = true; }).trigger('scroll'); - $('#update_thread').on('click', poll); - setInterval(timer_update, 1000); - setInterval(decrement_timer, 1000); + $('#update_thread').on('click', function() { poll(manualUpdate = true); return false; }); - poll_interval = setTimeout(poll, poll_interval_delay); - timer_update(); + if($("#auto_update_status").is(':checked')) { + auto_update(poll_interval_delay); + } }); -- cgit v1.3 From 71491bc9e96c9ef421d9b91f7f5678d7fe737771 Mon Sep 17 00:00:00 2001 From: topkek Date: Sun, 28 Sep 2014 00:40:00 +0100 Subject: Update auto-reload.js --- js/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 0e4b730a..cc7f650f 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -33,7 +33,7 @@ $(document).ready(function(){ // Grab the settings var settings = new script_settings('auto-reload'); - var poll_interval_mindelay_bottom = settings.get('min_delay_bottom', 5000); + var poll_interval_mindelay = settings.get('min_delay_bottom', 5000); var poll_interval_maxdelay = settings.get('max_delay', 600000); // number of ms to wait before reloading -- cgit v1.3 From 7aa2976524b0411795929203804ee3c27176ac19 Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 29 Sep 2014 05:18:00 +0900 Subject: wrap updater in ID span --- js/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index cc7f650f..19581b5e 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -29,7 +29,7 @@ $(document).ready(function(){ var countdown_interval; // Add an update link - $('.boardlist.bottom').prev().after("["+_("Update")+"] ( Auto) "); + $('.boardlist.bottom').prev().after("["+_("Update")+"] ( Auto) "); // Grab the settings var settings = new script_settings('auto-reload'); -- cgit v1.3 From 2ece97d6858b98b3836840bca0da8f4f08fdc2f8 Mon Sep 17 00:00:00 2001 From: ScriptKi77y Date: Mon, 29 Sep 2014 22:02:57 -0500 Subject: Scroll hook thread polling adjusttment. Fixed an issue with the scroll hook thread polling. Users scrolling near the bottom of the page are making upwards of 7-10 requests a second to the site. Added a small timer using the "poll_interval_mindelay" value to prevent unnecessary polling, one is enough during this minimum time delay. --- js/auto-reload.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 19581b5e..8a4ab949 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -121,6 +121,18 @@ $(document).ready(function(){ clearInterval(countdown_interval); } + var epoch = (new Date).getTime(); + var epochold = epoch; + + var timeDiff = function (delay) { + if((epoch-epochold) > delay) { + epochold = epoch = (new Date).getTime(); + return true; + }else{ + epoch = (new Date).getTime(); + return; + } + } var poll = function(manualUpdate) { stop_auto_update(); @@ -185,7 +197,7 @@ $(document).ready(function(){ end_of_page = false; return; } else { - if($("#auto_update_status").is(':checked')) { + if($("#auto_update_status").is(':checked') && timeDiff(poll_interval_mindelay)) { poll(manualUpdate = true); } end_of_page = true; -- cgit v1.3 From 7d5899d3a7ba6ab10ad75c6710cdfd661ed59383 Mon Sep 17 00:00:00 2001 From: ScriptKi77y Date: Tue, 30 Sep 2014 01:58:23 -0500 Subject: Quick fix to remove lag.. Executing a function to make a get request while simultaneously triggering a scroll event within the executed scroll event is probably not the best idea. This still needs work, there should probably be something else used to check for updates, such as an event where page has focus or something else that doesn't get called so many times, preferably something that reduces the timer instead. This is just a quick fix to stop all the lag on threads when scrolling near the bottom. --- js/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 8a4ab949..8a35335e 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -202,7 +202,7 @@ $(document).ready(function(){ } end_of_page = true; } - }).trigger('scroll'); + }); $('#update_thread').on('click', function() { poll(manualUpdate = true); return false; }); -- cgit v1.3 From 606b39450d29194fd7241898cfd4d1b9746a3c8b Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Oct 2014 18:30:47 +0200 Subject: better synchronize the javascripts with 8chan --- js/auto-reload.js | 24 ++++++++++++++++++++++++ js/id_colors.js | 52 +++++++++++++++++++++++++++++++++------------------- js/id_highlighter.js | 8 +++++++- 3 files changed, 64 insertions(+), 20 deletions(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 8a35335e..081314d8 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -17,6 +17,7 @@ * */ + auto_reload_enabled = true; // for watch.js to interop $(document).ready(function(){ @@ -35,6 +36,7 @@ $(document).ready(function(){ var settings = new script_settings('auto-reload'); var poll_interval_mindelay = settings.get('min_delay_bottom', 5000); var poll_interval_maxdelay = settings.get('max_delay', 600000); + var poll_interval_errordelay = settings.get('error_delay', 30000); // number of ms to wait before reloading var poll_interval_delay = poll_interval_mindelay; @@ -182,6 +184,28 @@ $(document).ready(function(){ else $('#update_secs').text("No new posts found"); } + }, + error: function(xhr, status_text, error_text) { + if (status_text == "error") { + if (error_text == "Not Found") { + $('#update_secs').text("Thread deleted or pruned"); + $('#auto_update_status').prop('checked', false); + $('#auto_update_status').prop('disabled', true); // disable updates if thread is deleted + return; + } else { + $('#update_secs').text("Error: "+error_text); + } + } else if (status_text) { + $('#update_secs').text("Error: "+status_text); + } else { + $('#update_secs').text("Unknown error"); + } + + // Keep trying to update + if ($('#auto_update_status').is(':checked')) { + poll_interval_delay = poll_interval_errordelay; + auto_update(poll_interval_delay); + } } }); diff --git a/js/id_colors.js b/js/id_colors.js index f92113d8..17f8b4d9 100644 --- a/js/id_colors.js +++ b/js/id_colors.js @@ -1,25 +1,39 @@ if (active_page == 'thread' || active_page == 'index') { $(document).ready(function(){ - $.hash = function(str) { - var i, j, msg = 0; - - for (i = 0, j = str.length; i < j; ++i) { - msg = ((msg << 5) - msg) + str.charCodeAt(i); + if (window.Options && Options.get_tab('general')) { + selector = '#color-ids>input'; + event = 'change'; + Options.extend_tab("general", ""); + } + + else { + selector = '#color-ids'; + event = 'click'; + $('hr:first').before('') + } + + $(selector).on(event, function() { + if (localStorage.color_ids === 'true') { + localStorage.color_ids = 'false'; + } else { + localStorage.color_ids = 'true'; } - - return msg; - }; - - function stringToRGB(str){ - var rgb, hash; - - rgb = []; - hash = $.hash(str); - - rgb[0] = (hash >> 24) & 0xFF; - rgb[1] = (hash >> 16) & 0xFF; - rgb[2] = (hash >> 8) & 0xFF; - + }); + + if (!localStorage.color_ids || localStorage.color_ids === 'false') { + return; + } else { + $('#color-ids>input').attr('checked','checked'); + } + + function IDToRGB(id_str){ + var id = id_str.match(/.{1,2}/g); + var rgb = new Array(); + + for (i = 0; i < id.length; i++) { + rgb[i] = parseInt(id[i], 16); + } + return rgb; } diff --git a/js/id_highlighter.js b/js/id_highlighter.js index 82e2c79d..d0a5fabf 100644 --- a/js/id_highlighter.js +++ b/js/id_highlighter.js @@ -23,7 +23,7 @@ if (active_page == 'thread' || active_page == 'index') { return toRet; } - $(".poster_id").click(function(){ + var id_highlighter = function(){ var id = $(this).text(); if($.inArray(id, idshighlighted) !== -1){ @@ -39,6 +39,12 @@ if (active_page == 'thread' || active_page == 'index') { $(this).addClass("highlighted"); }); } + } + + $(".poster_id").on('click', id_highlighter); + + $(document).on('new_post', function(e, post) { + $(post).find('.poster_id').on('click', id_highlighter); }); }); } -- cgit v1.3 From ca42984ddc892cddccd8539a416911a193ea43d2 Mon Sep 17 00:00:00 2001 From: czaks Date: Tue, 7 Oct 2014 05:40:37 +0200 Subject: i18n auto-reload.js --- js/auto-reload.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'js/auto-reload.js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 081314d8..d015dfc1 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -30,7 +30,7 @@ $(document).ready(function(){ var countdown_interval; // Add an update link - $('.boardlist.bottom').prev().after("["+_("Update")+"] ( Auto) "); + $('.boardlist.bottom').prev().after("["+_("Update")+"] ( "+_("Auto")+") "); // Grab the settings var settings = new script_settings('auto-reload'); @@ -138,7 +138,7 @@ $(document).ready(function(){ var poll = function(manualUpdate) { stop_auto_update(); - $('#update_secs').text("Updating..."); + $('#update_secs').text(_("Updating...")); $.ajax({ url: document.location, @@ -180,15 +180,15 @@ $(document).ready(function(){ } else { // Decide the message to show if auto update is disabled if (loaded_posts > 0) - $('#update_secs').text("Thread updated with "+loaded_posts+" new post(s)"); + $('#update_secs').text(fmt(_("Thread updated with {0} new post(s)"), [loaded_posts])); else - $('#update_secs').text("No new posts found"); + $('#update_secs').text(_("No new posts found")); } }, error: function(xhr, status_text, error_text) { if (status_text == "error") { if (error_text == "Not Found") { - $('#update_secs').text("Thread deleted or pruned"); + $('#update_secs').text(_("Thread deleted or pruned")); $('#auto_update_status').prop('checked', false); $('#auto_update_status').prop('disabled', true); // disable updates if thread is deleted return; @@ -196,9 +196,9 @@ $(document).ready(function(){ $('#update_secs').text("Error: "+error_text); } } else if (status_text) { - $('#update_secs').text("Error: "+status_text); + $('#update_secs').text(_("Error: ")+status_text); } else { - $('#update_secs').text("Unknown error"); + $('#update_secs').text(_("Unknown error")); } // Keep trying to update -- cgit v1.3