summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2014-10-05 18:30:47 +0200
committerczaks <marcin@6irc.net>2014-10-05 18:30:47 +0200
commit606b39450d29194fd7241898cfd4d1b9746a3c8b (patch)
tree663094e1487f56b287e6065525472cea61399cca
parent1964279436f61e56e6b138b64d9d4f6e476fdc02 (diff)
better synchronize the javascripts with 8chan
-rw-r--r--js/auto-reload.js24
-rw-r--r--js/id_colors.js50
-rw-r--r--js/id_highlighter.js8
3 files changed, 63 insertions, 19 deletions
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", "<label id='color-ids'><input type='checkbox' /> "+_('Color IDs')+"</label>");
+ }
+
+ else {
+ 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';
+ }
+ });
+
+ 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 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;
-
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);
});
});
}