1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-02-02 21:07:20 +01:00

auto-reload.js: format

This commit is contained in:
Zankaria 2025-01-04 21:42:01 +01:00
parent 8d56da9108
commit 209c334667

View File

@ -17,62 +17,65 @@
* *
* You must have boardlinks or else this script will not load. * You must have boardlinks or else this script will not load.
* Search for "$config['boards'] = array(" within your inc/config.php and add something similar to your instance-config.php. * Search for "$config['boards'] = array(" within your inc/config.php and add something similar to your instance-config.php.
*
*/ */
auto_reload_enabled = true; // For watch.js to interop.
auto_reload_enabled = true; // for watch.js to interop
$(document).ready(function(){ $(document).ready(function(){
if($('div.banner').length == 0) if($('div.banner').length == 0) {
return; // not index // Not index.
return;
}
if($(".post.op").size() != 1) if($(".post.op").size() != 1) {
return; //not thread page // Not thread page.
return;
}
var countdown_interval; var countdown_interval;
// Add an update link // Add an update link.
$('.boardlist.bottom').prev().after("<span id='updater'><a href='#' id='update_thread' style='padding-left:10px'>["+_("Update")+"]</a> (<input type='checkbox' id='auto_update_status' checked> "+_("Auto")+") <span id='update_secs'></span></span>"); $('.boardlist.bottom').prev().after("<span id='updater'><a href='#' id='update_thread' style='padding-left:10px'>["+_("Update")+"]</a> (<input type='checkbox' id='auto_update_status' checked> "+_("Auto")+") <span id='update_secs'></span></span>");
// Grab the settings // Grab the settings.
var settings = new script_settings('auto-reload'); var settings = new script_settings('auto-reload');
var poll_interval_mindelay = 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); var poll_interval_maxdelay = settings.get('max_delay', 600000);
var poll_interval_errordelay = settings.get('error_delay', 30000); var poll_interval_errordelay = settings.get('error_delay', 30000);
// number of ms to wait before reloading // number of ms to wait before reloading.
var poll_interval_delay = poll_interval_mindelay; var poll_interval_delay = poll_interval_mindelay;
var poll_current_time = poll_interval_delay; var poll_current_time = poll_interval_delay;
var end_of_page = false; var end_of_page = false;
var new_posts = 0; var new_posts = 0;
var first_new_post = null; var first_new_post = null;
var title = document.title; var title = document.title;
if (typeof update_title == "undefined") { if (typeof update_title == "undefined") {
var update_title = function() { var update_title = function() {
if (new_posts) { if (new_posts) {
document.title = "("+new_posts+") "+title; document.title = "("+new_posts+") "+title;
} else { } else {
document.title = title; document.title = title;
} }
}; };
} }
if (typeof add_title_collector != "undefined") if (typeof add_title_collector != "undefined") {
add_title_collector(function(){ add_title_collector(function() {
return new_posts; return new_posts;
}); });
}
var window_active = true; var window_active = true;
$(window).focus(function() { $(window).focus(function() {
window_active = true; window_active = true;
recheck_activated(); recheck_activated();
// Reset the delay if needed // Reset the delay if needed.
if(settings.get('reset_focus', true)) { if(settings.get('reset_focus', true)) {
poll_interval_delay = poll_interval_mindelay; poll_interval_delay = poll_interval_mindelay;
} }
@ -89,7 +92,6 @@ $(document).ready(function(){
stop_auto_update(); stop_auto_update();
$('#update_secs').text(""); $('#update_secs').text("");
} }
}); });
@ -126,14 +128,14 @@ $(document).ready(function(){
clearInterval(countdown_interval); clearInterval(countdown_interval);
} }
var epoch = (new Date).getTime(); var epoch = (new Date).getTime();
var epochold = epoch; var epochold = epoch;
var timeDiff = function (delay) { var timeDiff = function (delay) {
if((epoch-epochold) > delay) { if ((epoch-epochold) > delay) {
epochold = epoch = (new Date).getTime(); epochold = epoch = (new Date).getTime();
return true; return true;
}else{ } else {
epoch = (new Date).getTime(); epoch = (new Date).getTime();
return; return;
} }
@ -225,7 +227,7 @@ $(document).ready(function(){
$(window).scroll(function() { $(window).scroll(function() {
recheck_activated(); recheck_activated();
// if the newest post is not visible // If the newest post is not visible.
if($(this).scrollTop() + $(this).height() < if($(this).scrollTop() + $(this).height() <
$('div.post:last').position().top + $('div.post:last').height()) { $('div.post:last').position().top + $('div.post:last').height()) {
end_of_page = false; end_of_page = false;