1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-23 23:20:57 +01:00

better synchronize the javascripts with 8chan

This commit is contained in:
czaks 2014-10-05 18:30:47 +02:00
parent 1964279436
commit 606b39450d
3 changed files with 64 additions and 20 deletions

View File

@ -17,6 +17,7 @@
* *
*/ */
auto_reload_enabled = true; // for watch.js to interop auto_reload_enabled = true; // for watch.js to interop
$(document).ready(function(){ $(document).ready(function(){
@ -35,6 +36,7 @@ $(document).ready(function(){
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);
// 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;
@ -182,6 +184,28 @@ $(document).ready(function(){
else 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");
$('#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);
}
} }
}); });

View File

@ -1,24 +1,38 @@
if (active_page == 'thread' || active_page == 'index') { if (active_page == 'thread' || active_page == 'index') {
$(document).ready(function(){ $(document).ready(function(){
$.hash = function(str) { if (window.Options && Options.get_tab('general')) {
var i, j, msg = 0; selector = '#color-ids>input';
event = 'change';
Options.extend_tab("general", "<label id='color-ids'><input type='checkbox' /> "+_('Color IDs')+"</label>");
}
for (i = 0, j = str.length; i < j; ++i) { else {
msg = ((msg << 5) - msg) + str.charCodeAt(i); selector = '#color-ids';
event = 'click';
$('hr:first').before('<div id="color-ids" style="text-align:right"><a class="unimportant" href="javascript:void(0)">'+_('Color IDs')+'</a></div>')
}
$(selector).on(event, function() {
if (localStorage.color_ids === 'true') {
localStorage.color_ids = 'false';
} else {
localStorage.color_ids = 'true';
} }
});
return msg; if (!localStorage.color_ids || localStorage.color_ids === 'false') {
}; return;
} else {
$('#color-ids>input').attr('checked','checked');
}
function stringToRGB(str){ function IDToRGB(id_str){
var rgb, hash; var id = id_str.match(/.{1,2}/g);
var rgb = new Array();
rgb = []; for (i = 0; i < id.length; i++) {
hash = $.hash(str); rgb[i] = parseInt(id[i], 16);
}
rgb[0] = (hash >> 24) & 0xFF;
rgb[1] = (hash >> 16) & 0xFF;
rgb[2] = (hash >> 8) & 0xFF;
return rgb; return rgb;
} }

View File

@ -23,7 +23,7 @@ if (active_page == 'thread' || active_page == 'index') {
return toRet; return toRet;
} }
$(".poster_id").click(function(){ var id_highlighter = function(){
var id = $(this).text(); var id = $(this).text();
if($.inArray(id, idshighlighted) !== -1){ if($.inArray(id, idshighlighted) !== -1){
@ -39,6 +39,12 @@ if (active_page == 'thread' || active_page == 'index') {
$(this).addClass("highlighted"); $(this).addClass("highlighted");
}); });
} }
}
$(".poster_id").on('click', id_highlighter);
$(document).on('new_post', function(e, post) {
$(post).find('.poster_id').on('click', id_highlighter);
}); });
}); });
} }