From 01ce31a5168735fb6ef899de359f5431e2dd7baa Mon Sep 17 00:00:00 2001 From: anonfagola Date: Sat, 27 Sep 2014 11:56:05 -0700 Subject: Added id_colors.js --- js/id_colors.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 js/id_colors.js (limited to 'js/id_colors.js') diff --git a/js/id_colors.js b/js/id_colors.js new file mode 100644 index 00000000..6923dbec --- /dev/null +++ b/js/id_colors.js @@ -0,0 +1,34 @@ +$.hash = function(str) { + var i, j, msg = 0; + + for (i = 0, j = str.length; i < j; ++i) { + msg = ((msg << 5) - msg) + str.charCodeAt(i); + } + + 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; +} + +$(".poster_id").each(function(){ + var rgb = stringToRGB($(this).text()); + + $(this).css({ + "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")", + "padding": "3px 5px", + "border-radius": "8px", + "color": "white" + }); +}); + -- cgit v1.3 From 035f8437abe8713678b7cb3e301446419028593b Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 27 Sep 2014 20:04:57 +0000 Subject: Call on ready, dont pollute window namespace with vars --- js/id_colors.js | 65 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) (limited to 'js/id_colors.js') diff --git a/js/id_colors.js b/js/id_colors.js index 6923dbec..7d531fde 100644 --- a/js/id_colors.js +++ b/js/id_colors.js @@ -1,34 +1,37 @@ -$.hash = function(str) { - var i, j, msg = 0; - - for (i = 0, j = str.length; i < j; ++i) { - msg = ((msg << 5) - msg) + str.charCodeAt(i); - } - - return msg; -}; +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); + } + + 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; -} + 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; + } -$(".poster_id").each(function(){ - var rgb = stringToRGB($(this).text()); - - $(this).css({ - "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")", - "padding": "3px 5px", - "border-radius": "8px", - "color": "white" + $(".poster_id").each(function(){ + var rgb = stringToRGB($(this).text()); + + $(this).css({ + "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")", + "padding": "3px 5px", + "border-radius": "8px", + "color": "white" + }); + }); }); -}); - +} -- cgit v1.3 From f8178dcbe4c23c930b865c993c8f5ab8c831e59c Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 27 Sep 2014 20:17:31 +0000 Subject: Color IDs on new posts received via AJAX --- js/id_colors.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'js/id_colors.js') diff --git a/js/id_colors.js b/js/id_colors.js index 7d531fde..e0795b75 100644 --- a/js/id_colors.js +++ b/js/id_colors.js @@ -23,7 +23,7 @@ if (active_page == 'thread' || active_page == 'index') { return rgb; } - $(".poster_id").each(function(){ + function colorPostId(el) { var rgb = stringToRGB($(this).text()); $(this).css({ @@ -32,6 +32,16 @@ if (active_page == 'thread' || active_page == 'index') { "border-radius": "8px", "color": "white" }); + } + + $(".poster_id").each(function(k, v){ + colorPostId(v); + }); + + $(document).on('new_post', function(e, post) { + $(post).find('.poster_id').each(function(k, v) { + colorPostId(v); + }); }); }); } -- cgit v1.3 From 8bfd5e1bcda4ff68a527fb370da0ccaa7a5ff6e7 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 27 Sep 2014 20:19:58 +0000 Subject: this>el --- js/id_colors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/id_colors.js') diff --git a/js/id_colors.js b/js/id_colors.js index e0795b75..9cde1b00 100644 --- a/js/id_colors.js +++ b/js/id_colors.js @@ -24,9 +24,9 @@ if (active_page == 'thread' || active_page == 'index') { } function colorPostId(el) { - var rgb = stringToRGB($(this).text()); + var rgb = stringToRGB($(el).text()); - $(this).css({ + $(el).css({ "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")", "padding": "3px 5px", "border-radius": "8px", -- cgit v1.3 From 22f4543e6fb40f4f76143fdf8ef6cf5e0487c38a Mon Sep 17 00:00:00 2001 From: Bui Date: Sun, 28 Sep 2014 08:58:39 +0900 Subject: remove vertical padding on coloured IDs --- js/id_colors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/id_colors.js') diff --git a/js/id_colors.js b/js/id_colors.js index 9cde1b00..512bb591 100644 --- a/js/id_colors.js +++ b/js/id_colors.js @@ -28,7 +28,7 @@ if (active_page == 'thread' || active_page == 'index') { $(el).css({ "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")", - "padding": "3px 5px", + "padding": "0px 5px", "border-radius": "8px", "color": "white" }); -- cgit v1.3 From 6133386b826758d03caf938b15266efa88ecb200 Mon Sep 17 00:00:00 2001 From: Bui Date: Sun, 28 Sep 2014 09:17:30 +0900 Subject: change ID text colour on hover --- js/id_colors.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'js/id_colors.js') diff --git a/js/id_colors.js b/js/id_colors.js index 512bb591..bde2a969 100644 --- a/js/id_colors.js +++ b/js/id_colors.js @@ -32,6 +32,12 @@ if (active_page == 'thread' || active_page == 'index') { "border-radius": "8px", "color": "white" }); + + $(el).mouseover(function() { + $(this).css('color', '#800000'); + }).mouseout(function() { + $(this).css('color', '#FFF'); + }); } $(".poster_id").each(function(k, v){ -- cgit v1.3 From b34f9c31f9d950bd25045110fe78461bfa1304b5 Mon Sep 17 00:00:00 2001 From: 7185 <7185@users.noreply.github.com> Date: Sun, 28 Sep 2014 05:55:10 +0200 Subject: Poster ID readability Conflicts: js/id_colors.js --- js/id_colors.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'js/id_colors.js') diff --git a/js/id_colors.js b/js/id_colors.js index bde2a969..f92113d8 100644 --- a/js/id_colors.js +++ b/js/id_colors.js @@ -24,19 +24,23 @@ if (active_page == 'thread' || active_page == 'index') { } function colorPostId(el) { - var rgb = stringToRGB($(el).text()); - + var rgb = IDToRGB($(el).text()); + var ft = "#fff"; + + if ((rgb[0]*0.299 + rgb[1]*0.587 + rgb[2]*0.114) > 125) + ft = "#000"; + $(el).css({ "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")", "padding": "0px 5px", "border-radius": "8px", - "color": "white" + "color": ft }); $(el).mouseover(function() { - $(this).css('color', '#800000'); + $(this).css('color', '#800000'); // how about a CSS :hover rule instead? }).mouseout(function() { - $(this).css('color', '#FFF'); + $(this).css('color', ft); }); } -- 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/id_colors.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