|
|
@ -24,6 +24,58 @@ $(document).ready(function(){ |
|
|
|
if(active_page != 'thread') |
|
|
|
return; |
|
|
|
|
|
|
|
// Adds Options panel item
|
|
|
|
if (typeof localStorage.auto_thread_update === 'undefined') { |
|
|
|
localStorage.auto_thread_update = 'true'; //default value
|
|
|
|
} |
|
|
|
if (window.Options && Options.get_tab('general')) { |
|
|
|
Options.extend_tab("general", "<fieldset id='auto-update-fs'><legend>"+_("Auto update")+"</legend>" |
|
|
|
+ ('<label id="auto-thread-update"><input type="checkbox">' + _('Auto update thread') + '</label>') |
|
|
|
+ ('<label id="auto_thread_desktop_notifications"><input type="checkbox">' + _('Show desktop notifications when users quote me') + '</label>') |
|
|
|
+ ('<label id="auto_thread_desktop_notifications_all"><input type="checkbox">' + _('Show desktop notifications on all replies') + '</label>') |
|
|
|
+ '</fieldset>'); |
|
|
|
|
|
|
|
$('#auto-thread-update>input').on('click', function() { |
|
|
|
if ($('#auto-thread-update>input').is(':checked')) { |
|
|
|
localStorage.auto_thread_update = 'true'; |
|
|
|
} else { |
|
|
|
localStorage.auto_thread_update = 'false'; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
$('#auto_thread_desktop_notifications>input,#auto_thread_desktop_notifications_all>input').on('click', function() { |
|
|
|
if (!("Notification" in window)) return; |
|
|
|
|
|
|
|
var setting = $(this).parent().attr('id'); |
|
|
|
if ($(this).is(':checked')) { |
|
|
|
Notification.requestPermission(function(permission){ |
|
|
|
if (permission === "granted") { |
|
|
|
localStorage[setting] = 'true'; |
|
|
|
} |
|
|
|
}); |
|
|
|
if (Notification.permission === "granted") { |
|
|
|
localStorage[setting] = 'true'; |
|
|
|
} |
|
|
|
} else { |
|
|
|
localStorage[setting] = 'false'; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
if (localStorage.auto_thread_update === 'true') { |
|
|
|
$('#auto-thread-update>input').prop('checked', true); |
|
|
|
} |
|
|
|
|
|
|
|
if (localStorage.auto_thread_desktop_notifications === 'true') { |
|
|
|
$('#auto_thread_desktop_notifications>input').prop('checked', true); |
|
|
|
notify = "mention"; |
|
|
|
} |
|
|
|
|
|
|
|
if (localStorage.auto_thread_desktop_notifications_all === 'true') { |
|
|
|
$('#auto_thread_desktop_notifications_all>input').prop('checked', true); |
|
|
|
notify = "all"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var countdown_interval; |
|
|
|
|
|
|
|
// Add an update link
|
|
|
@ -36,9 +88,9 @@ $(document).ready(function(){ |
|
|
|
|
|
|
|
// Grab the settings
|
|
|
|
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); |
|
|
|
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; |
|
|
@ -123,9 +175,9 @@ $(document).ready(function(){ |
|
|
|
clearInterval(countdown_interval); |
|
|
|
} |
|
|
|
|
|
|
|
var epoch = (new Date).getTime(); |
|
|
|
var epochold = epoch; |
|
|
|
|
|
|
|
var epoch = (new Date).getTime(); |
|
|
|
var epochold = epoch; |
|
|
|
|
|
|
|
var timeDiff = function (delay) { |
|
|
|
if((epoch-epochold) > delay) { |
|
|
|
epochold = epoch = (new Date).getTime(); |
|
|
@ -147,13 +199,10 @@ $(document).ready(function(){ |
|
|
|
$(data).find('div.post.reply').each(function() { |
|
|
|
var id = $(this).attr('id'); |
|
|
|
if($('#' + id).length == 0) { |
|
|
|
if (!new_posts) { |
|
|
|
makeIcon('reply'); |
|
|
|
if (notify === "all" || (notify === "mention" && $(this).find('.own_post').length)) { |
|
|
|
var body = $(this).children('.body').html().replace(/<br\s*[\/]?>/gi, "\n"); |
|
|
|
var n = new Notification("New reply to "+ title, {body: $('<div/>').html(body).text()}); |
|
|
|
} |
|
|
|
if (notify === "all" || (notify === "mention" && $(this).find('.own_post').length)) { |
|
|
|
var body = $(this).children('.body').html().replace(/<br\s*[\/]?>/gi, "\n"); |
|
|
|
var n = new Notification("New reply to "+ title, {body: $('<div/>').html(body).text()}); |
|
|
|
} |
|
|
|
|
|
|
|
$(this).insertAfter($('div.post:not(.post-hover,.inline)').last().next()).after('<br class="clear">'); |
|
|
|
new_posts++; |
|
|
|