From 2a823ae786f279eaec154faf50cca1fd40085af6 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Tue, 23 Sep 2014 16:50:32 -0700 Subject: Create threadscroll.js --- js/threadscroll.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 js/threadscroll.js (limited to 'js') diff --git a/js/threadscroll.js b/js/threadscroll.js new file mode 100644 index 00000000..9b97074a --- /dev/null +++ b/js/threadscroll.js @@ -0,0 +1,46 @@ +var hoverElem = null; + +$(document).mouseover(function(e){ + var x = e.clientX, y = e.clientY, + elementOnMouseOver = document.elementFromPoint(x, y); + hoverElem = $(elementOnMouseOver); +}); + +$(document).keydown(function(e){ + console.log(e); + if(e.which == 38){ + var ele = hoverElem; + + if(ele.parent().attr("class") == "post op" || ele.attr("class") == "body" || ele.attr("class") == "post-image" || ele.parent().attr("class") == "body" || ele.parent().attr("class") == "body" || (ele.parent().attr("id")!= null && ele.parent().attr("id").match("^thread") != null) || (ele.parent().attr("for")!= null && ele.parent().attr("id").match("delete") != null)){ + var thread = (ele.parent().attr("class") == "post op") ? ele.parent().parent() : ele.parent(); + thread = (thread.attr("class") == "post reply") ? thread.parent() : thread; + thread = (thread.attr("class") == "body") ? thread.parent().parent() : thread; + thread = (ele.attr("class") == "post-image") ? thread.parent().parent().parent().parent() : thread; + + if(thread.attr("id") == null) thread = ele.parent().parent().parent().parent(); //op image + + if(thread.prev().attr("id") != null){ + if(thread.prev().attr("id").match("^thread")){ + window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+thread.prev().attr("id"); + } + } + } + }else if(e.which == 40){ + var ele = hoverElem; + + if(ele.parent().attr("class") == "post op" || ele.attr("class") == "body" || ele.attr("class") == "post-image" || ele.parent().attr("class") == "body" || ele.parent().attr("class") == "body" || (ele.parent().attr("id")!= null && ele.parent().attr("id").match("^thread") != null) || (ele.parent().attr("for")!= null && ele.parent().attr("id").match("delete") != null)){ + var thread = (ele.parent().attr("class") == "post op") ? ele.parent().parent() : ele.parent(); + thread = (thread.attr("class") == "post reply") ? thread.parent() : thread; + thread = (thread.attr("class") == "body") ? thread.parent().parent() : thread; + thread = (ele.attr("class") == "post-image") ? thread.parent().parent().parent().parent() : thread; + + if(thread.attr("id") == null) thread = ele.parent().parent().parent().parent(); //op image + + if(thread.next().attr("id") != null){ + if(thread.next().attr("id").match("^thread")){ + window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+thread.next().attr("id"); + } + } + } + } +}); -- cgit v1.3 From f5d121af105c76217ef0026cdf008f5aeac913e3 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Tue, 23 Sep 2014 18:55:50 -0700 Subject: Update threadscroll.js Fixed a line left from debug, and added comments. --- js/threadscroll.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/threadscroll.js b/js/threadscroll.js index 9b97074a..4f623ed2 100644 --- a/js/threadscroll.js +++ b/js/threadscroll.js @@ -7,7 +7,7 @@ $(document).mouseover(function(e){ }); $(document).keydown(function(e){ - console.log(e); + //Up arrow if(e.which == 38){ var ele = hoverElem; @@ -25,6 +25,7 @@ $(document).keydown(function(e){ } } } + //Down arrow }else if(e.which == 40){ var ele = hoverElem; -- cgit v1.3 From 712e7f6c575f028511bf1ecfdf81e0a02df913fc Mon Sep 17 00:00:00 2001 From: anonfagola Date: Tue, 23 Sep 2014 19:27:41 -0700 Subject: Update threadscroll.js Made cleaner. --- js/threadscroll.js | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'js') diff --git a/js/threadscroll.js b/js/threadscroll.js index 4f623ed2..5cbcbbe8 100644 --- a/js/threadscroll.js +++ b/js/threadscroll.js @@ -10,36 +10,24 @@ $(document).keydown(function(e){ //Up arrow if(e.which == 38){ var ele = hoverElem; + var par = $(ele).parents('div[id^="thread_"]'); - if(ele.parent().attr("class") == "post op" || ele.attr("class") == "body" || ele.attr("class") == "post-image" || ele.parent().attr("class") == "body" || ele.parent().attr("class") == "body" || (ele.parent().attr("id")!= null && ele.parent().attr("id").match("^thread") != null) || (ele.parent().attr("for")!= null && ele.parent().attr("id").match("delete") != null)){ - var thread = (ele.parent().attr("class") == "post op") ? ele.parent().parent() : ele.parent(); - thread = (thread.attr("class") == "post reply") ? thread.parent() : thread; - thread = (thread.attr("class") == "body") ? thread.parent().parent() : thread; - thread = (ele.attr("class") == "post-image") ? thread.parent().parent().parent().parent() : thread; - - if(thread.attr("id") == null) thread = ele.parent().parent().parent().parent(); //op image - - if(thread.prev().attr("id") != null){ - if(thread.prev().attr("id").match("^thread")){ - window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+thread.prev().attr("id"); + if(par.length == 1){ + if(par.prev().attr("id") != null){ + if(par.prev().attr("id").match("^thread")){ + window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.prev().attr("id"); } } } //Down arrow }else if(e.which == 40){ var ele = hoverElem; + var par = $(ele).parents('div[id^="thread_"]'); - if(ele.parent().attr("class") == "post op" || ele.attr("class") == "body" || ele.attr("class") == "post-image" || ele.parent().attr("class") == "body" || ele.parent().attr("class") == "body" || (ele.parent().attr("id")!= null && ele.parent().attr("id").match("^thread") != null) || (ele.parent().attr("for")!= null && ele.parent().attr("id").match("delete") != null)){ - var thread = (ele.parent().attr("class") == "post op") ? ele.parent().parent() : ele.parent(); - thread = (thread.attr("class") == "post reply") ? thread.parent() : thread; - thread = (thread.attr("class") == "body") ? thread.parent().parent() : thread; - thread = (ele.attr("class") == "post-image") ? thread.parent().parent().parent().parent() : thread; - - if(thread.attr("id") == null) thread = ele.parent().parent().parent().parent(); //op image - - if(thread.next().attr("id") != null){ - if(thread.next().attr("id").match("^thread")){ - window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+thread.next().attr("id"); + if(par.length == 1){ + if(par.next().attr("id") != null){ + if(par.next().attr("id").match("^thread")){ + window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.next().attr("id"); } } } -- cgit v1.3 From b9886dc474e5d3fcbf879bd6237bae739c63a9f1 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Tue, 23 Sep 2014 19:31:06 -0700 Subject: Update threadscroll.js Made compatible for use with additional_javascripts. --- js/threadscroll.js | 62 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'js') diff --git a/js/threadscroll.js b/js/threadscroll.js index 5cbcbbe8..c3c6deef 100644 --- a/js/threadscroll.js +++ b/js/threadscroll.js @@ -1,35 +1,37 @@ -var hoverElem = null; - -$(document).mouseover(function(e){ - var x = e.clientX, y = e.clientY, - elementOnMouseOver = document.elementFromPoint(x, y); - hoverElem = $(elementOnMouseOver); -}); - -$(document).keydown(function(e){ - //Up arrow - if(e.which == 38){ - var ele = hoverElem; - var par = $(ele).parents('div[id^="thread_"]'); - - if(par.length == 1){ - if(par.prev().attr("id") != null){ - if(par.prev().attr("id").match("^thread")){ - window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.prev().attr("id"); +if(active_page == "index" || active_page == "ukko"){ + var hoverElem = null; + + $(document).mouseover(function(e){ + var x = e.clientX, y = e.clientY, + elementOnMouseOver = document.elementFromPoint(x, y); + hoverElem = $(elementOnMouseOver); + }); + + $(document).keydown(function(e){ + //Up arrow + if(e.which == 38){ + var ele = hoverElem; + var par = $(ele).parents('div[id^="thread_"]'); + + if(par.length == 1){ + if(par.prev().attr("id") != null){ + if(par.prev().attr("id").match("^thread")){ + window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.prev().attr("id"); + } } } - } - //Down arrow - }else if(e.which == 40){ - var ele = hoverElem; - var par = $(ele).parents('div[id^="thread_"]'); - - if(par.length == 1){ - if(par.next().attr("id") != null){ - if(par.next().attr("id").match("^thread")){ - window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.next().attr("id"); + //Down arrow + }else if(e.which == 40){ + var ele = hoverElem; + var par = $(ele).parents('div[id^="thread_"]'); + + if(par.length == 1){ + if(par.next().attr("id") != null){ + if(par.next().attr("id").match("^thread")){ + window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.next().attr("id"); + } } } } - } -}); + }); +} -- cgit v1.3 From 5d8d20fcc5c8a2364d51158813f439eff4de3cc8 Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 24 Sep 2014 21:29:12 +0000 Subject: Add timer to auto reload js Conflicts: js/auto-reload.js --- js/auto-reload.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 4a872024..886f32e6 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -8,6 +8,7 @@ * Copyright (c) 2012 Michael Save * Copyright (c) 2013-2014 Marcin Łabanowski * Copyright (c) 2013 undido + * Copyright (c) 2014 Fredrick Brennan * * Usage: * $config['additional_javascript'][] = 'js/jquery.min.js'; @@ -27,6 +28,8 @@ $(document).ready(function(){ var poll_interval; + // Add an update link + $('.boardlist.bottom').prev().after("["+_("Update thread")+"] ()"); // Grab the settings var settings = new script_settings('auto-reload'); @@ -37,6 +40,7 @@ $(document).ready(function(){ // number of ms to wait before reloading var poll_interval_delay = poll_interval_mindelay_bottom; + var poll_current_time = poll_interval_delay; var end_of_page = false; @@ -68,6 +72,14 @@ $(document).ready(function(){ window_active = false; }); + var timer_update = function() { + $('#update_secs').text(poll_current_time/1000); + } + + var decrement_timer = function() { + poll_current_time = poll_current_time - 1000; + } + var recheck_activated = function() { if (new_posts && window_active && $(window).scrollTop() + $(window).height() >= @@ -115,6 +127,7 @@ $(document).ready(function(){ } poll_interval = setTimeout(poll, poll_interval_delay); + poll_current_time = poll_interval_delay; }; $(window).scroll(function() { @@ -128,9 +141,15 @@ $(document).ready(function(){ clearTimeout(poll_interval); poll_interval = setTimeout(poll, poll_interval_shortdelay); + poll_current_time = poll_interval_shortdelay; end_of_page = true; }).trigger('scroll'); - poll_interval = setTimeout(poll, poll_interval_delay); + $('#update_thread').on('click', poll); + setInterval(timer_update, 1000); + setInterval(decrement_timer, 1000); + + poll_interval = setInterval(poll, poll_interval_delay); + timer_update(); }); -- cgit v1.3 From ed5272f17d22be01770361c3950fe5fbc32cfb7f Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 25 Sep 2014 06:31:40 +0200 Subject: auto-reload.js: don`t scroll up --- js/auto-reload.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 886f32e6..1f4d11fe 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -128,6 +128,8 @@ $(document).ready(function(){ poll_interval = setTimeout(poll, poll_interval_delay); poll_current_time = poll_interval_delay; + + return false; }; $(window).scroll(function() { -- cgit v1.3 From dbaeb395acf6ad1e95f7623c2853d9d702920bb5 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 25 Sep 2014 06:32:53 +0200 Subject: auto-reload.js: it`s actually setTimeout, not setInterval, right? --- js/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 1f4d11fe..87e332df 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -151,7 +151,7 @@ $(document).ready(function(){ setInterval(timer_update, 1000); setInterval(decrement_timer, 1000); - poll_interval = setInterval(poll, poll_interval_delay); + poll_interval = setTimeout(poll, poll_interval_delay); timer_update(); }); -- cgit v1.3 From ba515c5f0519ae89b0876e4291061ecf2ffa6967 Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 26 Sep 2014 12:56:05 +0200 Subject: post-hover.js: show a popup preview if a reply is only partially on screen; fixes ctrlcctrlv#84 --- js/post-hover.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/post-hover.js b/js/post-hover.js index 2808b8e7..0becfb70 100644 --- a/js/post-hover.js +++ b/js/post-hover.js @@ -58,8 +58,8 @@ onready(function(){ // link links to itself or to op; ignore } else if($post.is(':visible') && - $post.offset().top + $post.height() >= $(window).scrollTop() && - $post.offset().top <= $(window).scrollTop() + $(window).height()) { + $post.offset().top >= $(window).scrollTop() && + $post.offset().top + $post.height() <= $(window).scrollTop() + $(window).height()) { // post is in view $post.addClass('highlighted'); } else { -- cgit v1.3 From b7592c3eecd5346851cfc0b1450e4a3c3b6bb543 Mon Sep 17 00:00:00 2001 From: Nebs Date: Fri, 26 Sep 2014 00:30:23 -0500 Subject: Fixed unanimating gifs in the catalog --- js/no-animated-gif.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/no-animated-gif.js b/js/no-animated-gif.js index 7e777d87..45a55f97 100644 --- a/js/no-animated-gif.js +++ b/js/no-animated-gif.js @@ -13,7 +13,10 @@ */ function unanimate_gif(e) { - var c = $(''); + if (active_page === "catalog") + var c = $(''); + else + var c = $(''); $(e).parent().prepend(c); c.attr('width', $(e).width()); c.attr('height',$(e).height()); @@ -32,7 +35,7 @@ function unanimate_gif(e) { } function no_animated_gif() { - var anim_gifs = $('img.post-image[src$=".gif"]'); + var anim_gifs = $('img.post-image[src$=".gif"], img.thread-image[src$=".gif"]'); localStorage.no_animated_gif = true; $('#no-animated-gif>a').text(_('Animate GIFs')); $('#no-animated-gif>input').prop('checked', true); @@ -48,7 +51,7 @@ function animated_gif() { $('#no-animated-gif>input').prop('checked', false); } -if (active_page == 'thread' || active_page == 'index' || active_page == 'ukko') { +if (active_page == 'thread' || active_page == 'index' || active_page == 'ukko' || active_page == 'catalog') { $(function(){ var selector, event; if (window.Options && Options.get_tab('general')) { -- cgit v1.3 From ab2a83d194eb7bfd2fe82942333fe55cb4cb4c16 Mon Sep 17 00:00:00 2001 From: Nebs Date: Thu, 25 Sep 2014 18:27:39 -0500 Subject: Fixes catalog href on a potential /res/ board --- js/catalog-link.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/catalog-link.js b/js/catalog-link.js index 899e6859..5c5d9b13 100644 --- a/js/catalog-link.js +++ b/js/catalog-link.js @@ -16,11 +16,11 @@ function catalog() { var board = $("input[name='board']"); if (board.length>0) { -if (window.location.href.indexOf("/res/")==-1){ //if we are inside a thread -var catalog_url = 'catalog.html'; +if (window.location.pathname.indexOf("/res/")>0){ //if we are inside a thread +var catalog_url = '../catalog.html'; } else { -var catalog_url = '../catalog.html'; +var catalog_url = 'catalog.html'; } var pages = document.getElementsByClassName('pages')[0]; var bottom = document.getElementsByClassName('boardlist bottom')[0] -- cgit v1.3 From d9f20c290db89b17640228df6c405925e9ead587 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Fri, 26 Sep 2014 16:55:16 -0700 Subject: Updated threadscroll.js with bettter compatibility --- js/threadscroll.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/threadscroll.js b/js/threadscroll.js index c3c6deef..0a233f58 100644 --- a/js/threadscroll.js +++ b/js/threadscroll.js @@ -16,7 +16,7 @@ if(active_page == "index" || active_page == "ukko"){ if(par.length == 1){ if(par.prev().attr("id") != null){ if(par.prev().attr("id").match("^thread")){ - window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.prev().attr("id"); + par.prev()[0].scrollIntoView(true); } } } @@ -28,7 +28,7 @@ if(active_page == "index" || active_page == "ukko"){ if(par.length == 1){ if(par.next().attr("id") != null){ if(par.next().attr("id").match("^thread")){ - window.location.href = window.location.protocol+"//"+window.location.host+window.location.pathname+"#"+par.next().attr("id"); + par.next()[0].scrollIntoView(true); } } } -- cgit v1.3 From 56f3d89774654f2cfa747e9fd9881fb9efb92223 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 27 Sep 2014 00:44:41 +0000 Subject: Fix multi image from quick reply Conflicts: js/multi-image.js --- js/multi-image.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/multi-image.js b/js/multi-image.js index 32d1f256..77c3f766 100644 --- a/js/multi-image.js +++ b/js/multi-image.js @@ -18,7 +18,10 @@ function multi_image() { var images_len = $('form:not([id="quick-reply"]) [type=file]').length; if (!(images_len >= max_images)) { - $('.add_image').after('
'); + var new_file = '
'; + + $('[type=file]:last').after(new_file); + $('form:not([id="quick-reply"]) [type=file]:last').after(new_file); if (typeof setup_form !== 'undefined') setup_form($('form[name="post"]')); } }) -- cgit v1.3 From 6fd3b64c679d0640796b3fb3d5972fc465bfa954 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 27 Sep 2014 00:44:55 +0000 Subject: Disallow multiple Shrink all images appearing fixes vichan-devel#91 --- js/expand-all-images.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/expand-all-images.js b/js/expand-all-images.js index fc273e5e..5545045c 100644 --- a/js/expand-all-images.js +++ b/js/expand-all-images.js @@ -27,7 +27,10 @@ onready(function(){ $(this).parent().click(); }); - $('hr:first').before('
'); + if (!$('#shrink-all-images').length) { + $('hr:first').before('
'); + } + $('div#shrink-all-images a') .text(_('Shrink all images')) .click(function(){ -- cgit v1.3 From dda746201396977321b5c639a2fc8cf0575588a0 Mon Sep 17 00:00:00 2001 From: czaks Date: Sat, 27 Sep 2014 11:13:04 +0200 Subject: catalog link not always working; fix ctrlcctrlv#88 --- js/catalog-link.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/catalog-link.js b/js/catalog-link.js index 5c5d9b13..05ee9efb 100644 --- a/js/catalog-link.js +++ b/js/catalog-link.js @@ -15,13 +15,8 @@ function catalog() { var board = $("input[name='board']"); -if (board.length>0) { -if (window.location.pathname.indexOf("/res/")>0){ //if we are inside a thread -var catalog_url = '../catalog.html'; -} -else { -var catalog_url = 'catalog.html'; -} +var catalog_url = configRoot + board.first().val() + "/catalog.html"; + var pages = document.getElementsByClassName('pages')[0]; var bottom = document.getElementsByClassName('boardlist bottom')[0] var subtitle = document.getElementsByClassName('subtitle')[0]; @@ -57,7 +52,6 @@ if (subtitle) { subtitle.appendChild(link2); } } -} if (active_page == 'thread' || active_page == 'index') { $(document).ready(catalog); -- cgit v1.3 From f2e101f30d2abf17c481fb59ff1a9394cc9e43d5 Mon Sep 17 00:00:00 2001 From: czaks Date: Sat, 27 Sep 2014 11:22:28 +0200 Subject: fix multi-image.js when quick-reply isn`t loaded --- js/multi-image.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/multi-image.js b/js/multi-image.js index 77c3f766..db4c6bd2 100644 --- a/js/multi-image.js +++ b/js/multi-image.js @@ -21,7 +21,9 @@ function multi_image() { var new_file = '
'; $('[type=file]:last').after(new_file); - $('form:not([id="quick-reply"]) [type=file]:last').after(new_file); + if ($("#quick-reply").length) { + $('form:not(#quick-reply) [type=file]:last').after(new_file); + } if (typeof setup_form !== 'undefined') setup_form($('form[name="post"]')); } }) -- cgit v1.3 From fda530953bb50b10a132fbf56d10952e7d9d0267 Mon Sep 17 00:00:00 2001 From: anonfagola Date: Sat, 27 Sep 2014 09:47:11 -0700 Subject: Create id_highlighter --- js/id_highlighter | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 js/id_highlighter (limited to 'js') diff --git a/js/id_highlighter b/js/id_highlighter new file mode 100644 index 00000000..60052031 --- /dev/null +++ b/js/id_highlighter @@ -0,0 +1,40 @@ +Array.prototype.remove = function(v) { this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); } + +var idshighlighted = []; + +function getPostsById(id){ + return $(".poster_id").filter(function(i){ + return $(this).text() == id; + }); +} + +function getMasterPosts(parents){ + if(!parents.hasClass("post")) return; + + var toRet = []; + + $(parents).each(function(){ + if($(this).hasClass("post")) + toRet.push($(this)); + }); + + return toRet; +} + +$(".poster_id").click(function(){ + var id = $(this).text(); + + if($.inArray(id, idshighlighted) !== -1){ + idshighlighted.remove(id); + + $(getMasterPosts(getPostsById(id).parents())).each(function(i){ + $(this).removeClass("highlighted"); + }); + }else{ + idshighlighted.push(id); + + $(getMasterPosts(getPostsById(id).parents())).each(function(i){ + $(this).addClass("highlighted"); + }); + } +}); -- cgit v1.3 From b419c85f8c9c79e6bb0425db93967b36240ebbed Mon Sep 17 00:00:00 2001 From: anonfagola Date: Sat, 27 Sep 2014 11:55:39 -0700 Subject: Forgot .js extension --- js/id_highlighter | 40 ---------------------------------------- js/id_highlighter.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 js/id_highlighter create mode 100644 js/id_highlighter.js (limited to 'js') diff --git a/js/id_highlighter b/js/id_highlighter deleted file mode 100644 index 60052031..00000000 --- a/js/id_highlighter +++ /dev/null @@ -1,40 +0,0 @@ -Array.prototype.remove = function(v) { this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); } - -var idshighlighted = []; - -function getPostsById(id){ - return $(".poster_id").filter(function(i){ - return $(this).text() == id; - }); -} - -function getMasterPosts(parents){ - if(!parents.hasClass("post")) return; - - var toRet = []; - - $(parents).each(function(){ - if($(this).hasClass("post")) - toRet.push($(this)); - }); - - return toRet; -} - -$(".poster_id").click(function(){ - var id = $(this).text(); - - if($.inArray(id, idshighlighted) !== -1){ - idshighlighted.remove(id); - - $(getMasterPosts(getPostsById(id).parents())).each(function(i){ - $(this).removeClass("highlighted"); - }); - }else{ - idshighlighted.push(id); - - $(getMasterPosts(getPostsById(id).parents())).each(function(i){ - $(this).addClass("highlighted"); - }); - } -}); diff --git a/js/id_highlighter.js b/js/id_highlighter.js new file mode 100644 index 00000000..60052031 --- /dev/null +++ b/js/id_highlighter.js @@ -0,0 +1,40 @@ +Array.prototype.remove = function(v) { this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); } + +var idshighlighted = []; + +function getPostsById(id){ + return $(".poster_id").filter(function(i){ + return $(this).text() == id; + }); +} + +function getMasterPosts(parents){ + if(!parents.hasClass("post")) return; + + var toRet = []; + + $(parents).each(function(){ + if($(this).hasClass("post")) + toRet.push($(this)); + }); + + return toRet; +} + +$(".poster_id").click(function(){ + var id = $(this).text(); + + if($.inArray(id, idshighlighted) !== -1){ + idshighlighted.remove(id); + + $(getMasterPosts(getPostsById(id).parents())).each(function(i){ + $(this).removeClass("highlighted"); + }); + }else{ + idshighlighted.push(id); + + $(getMasterPosts(getPostsById(id).parents())).each(function(i){ + $(this).addClass("highlighted"); + }); + } +}); -- cgit v1.3 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') 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 c3ba4cc7efc3ec345634fa1a8f409008e2c535e8 Mon Sep 17 00:00:00 2001 From: 8chan Date: Sat, 27 Sep 2014 20:04:27 +0000 Subject: Remove prototype pollution, call on ready --- js/id_highlighter.js | 74 +++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 35 deletions(-) (limited to 'js') diff --git a/js/id_highlighter.js b/js/id_highlighter.js index 60052031..82e2c79d 100644 --- a/js/id_highlighter.js +++ b/js/id_highlighter.js @@ -1,40 +1,44 @@ -Array.prototype.remove = function(v) { this.splice(this.indexOf(v) == -1 ? this.length : this.indexOf(v), 1); } +if (active_page == 'thread' || active_page == 'index') { + $(document).ready(function(){ + function arrayRemove(a, v) { a.splice(a.indexOf(v) == -1 ? a.length : a.indexOf(v), 1); } -var idshighlighted = []; + var idshighlighted = []; -function getPostsById(id){ - return $(".poster_id").filter(function(i){ - return $(this).text() == id; - }); -} + function getPostsById(id){ + return $(".poster_id").filter(function(i){ + return $(this).text() == id; + }); + } -function getMasterPosts(parents){ - if(!parents.hasClass("post")) return; - - var toRet = []; - - $(parents).each(function(){ - if($(this).hasClass("post")) - toRet.push($(this)); - }); - - return toRet; -} + function getMasterPosts(parents){ + if(!parents.hasClass("post")) return; + + var toRet = []; + + $(parents).each(function(){ + if($(this).hasClass("post")) + toRet.push($(this)); + }); + + return toRet; + } -$(".poster_id").click(function(){ - var id = $(this).text(); - - if($.inArray(id, idshighlighted) !== -1){ - idshighlighted.remove(id); - - $(getMasterPosts(getPostsById(id).parents())).each(function(i){ - $(this).removeClass("highlighted"); + $(".poster_id").click(function(){ + var id = $(this).text(); + + if($.inArray(id, idshighlighted) !== -1){ + arrayRemove(idshighlighted, id); + + $(getMasterPosts(getPostsById(id).parents())).each(function(i){ + $(this).removeClass("highlighted"); + }); + }else{ + idshighlighted.push(id); + + $(getMasterPosts(getPostsById(id).parents())).each(function(i){ + $(this).addClass("highlighted"); + }); + } }); - }else{ - idshighlighted.push(id); - - $(getMasterPosts(getPostsById(id).parents())).each(function(i){ - $(this).addClass("highlighted"); - }); - } -}); + }); +} -- 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') 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') 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') 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 9a096f58886725f420a9ec6ce1ec8efb4c0b7c72 Mon Sep 17 00:00:00 2001 From: topkek Date: Sun, 28 Sep 2014 00:16:16 +0100 Subject: Update auto-reload.js --- js/auto-reload.js | 136 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 46 deletions(-) (limited to 'js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 87e332df..0e4b730a 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -24,31 +24,37 @@ $(document).ready(function(){ return; // not index if($(".post.op").size() != 1) - return; //not thread page + return; //not thread page - var poll_interval; + var countdown_interval; // Add an update link - $('.boardlist.bottom').prev().after("["+_("Update thread")+"] ()"); + $('.boardlist.bottom').prev().after("["+_("Update")+"] ( Auto) "); // Grab the settings var settings = new script_settings('auto-reload'); - var poll_interval_mindelay_bottom = settings.get('min_delay_bottom', 3000); - var poll_interval_mindelay_top = settings.get('min_delay_top', 10000); + var poll_interval_mindelay_bottom = settings.get('min_delay_bottom', 5000); var poll_interval_maxdelay = settings.get('max_delay', 600000); - var poll_interval_shortdelay = settings.get('quick_delay', 100); // number of ms to wait before reloading - var poll_interval_delay = poll_interval_mindelay_bottom; + var poll_interval_delay = poll_interval_mindelay; var poll_current_time = poll_interval_delay; var end_of_page = false; var new_posts = 0; var first_new_post = null; + + var title = document.title; if (typeof update_title == "undefined") { - var update_title = function() { }; + var update_title = function() { + if (new_posts) { + document.title = "("+new_posts+") "+title; + } else { + document.title = title; + } + }; } if (typeof add_title_collector != "undefined") @@ -63,37 +69,67 @@ $(document).ready(function(){ // Reset the delay if needed if(settings.get('reset_focus', true)) { - poll_interval_delay = end_of_page - ? poll_interval_mindelay_bottom - : poll_interval_mindelay_top; + poll_interval_delay = poll_interval_mindelay; } }); $(window).blur(function() { window_active = false; }); - var timer_update = function() { - $('#update_secs').text(poll_current_time/1000); - } + + $('#auto_update_status').click(function() { + if($("#auto_update_status").is(':checked')) { + auto_update(poll_interval_mindelay); + } else { + stop_auto_update(); + $('#update_secs').text(""); + } + + }); + var decrement_timer = function() { poll_current_time = poll_current_time - 1000; + $('#update_secs').text(poll_current_time/1000); + + if (poll_current_time <= 0) { + poll(manualUpdate = false); + } } var recheck_activated = function() { if (new_posts && window_active && $(window).scrollTop() + $(window).height() >= - $(first_new_post).position().top) { + $('div.boardlist.bottom').position().top) { new_posts = 0; } update_title(); + first_new_post = null; }; + + // automatically updates the thread after a specified delay + var auto_update = function(delay) { + clearInterval(countdown_interval); - var poll = function() { + poll_current_time = delay; + countdown_interval = setInterval(decrement_timer, 1000); + $('#update_secs').text(poll_current_time/1000); + } + + var stop_auto_update = function() { + clearInterval(countdown_interval); + } + + + var poll = function(manualUpdate) { + stop_auto_update(); + $('#update_secs').text("Updating..."); + $.ajax({ url: document.location, success: function(data) { + var loaded_posts = 0; // the number of new posts loaded in this update $(data).find('div.post.reply').each(function() { var id = $(this).attr('id'); if($('#' + id).length == 0) { @@ -102,56 +138,64 @@ $(document).ready(function(){ } $(this).insertAfter($('div.post:last').next()).after('
'); new_posts++; + loaded_posts++; $(document).trigger('new_post', this); recheck_activated(); } }); time_loaded = Date.now(); // interop with watch.js + + + if ($('#auto_update_status').is(':checked')) { + // If there are no new posts, double the delay. Otherwise set it to the min. + if(loaded_posts == 0) { + // if the update was manual, don't increase the delay + if (manualUpdate == false) { + poll_interval_delay *= 2; + + // Don't increase the delay beyond the maximum + if(poll_interval_delay > poll_interval_maxdelay) { + poll_interval_delay = poll_interval_maxdelay; + } + } + } else { + poll_interval_delay = poll_interval_mindelay; + } + + auto_update(poll_interval_delay); + } else { + // Decide the message to show if auto update is disabled + if (loaded_posts > 0) + $('#update_secs').text("Thread updated with "+loaded_posts+" new post(s)"); + else + $('#update_secs').text("No new posts found"); + } } }); - clearTimeout(poll_interval); - - // If there are no new posts, double the delay. Otherwise set it to the min. - if(new_posts == 0) { - poll_interval_delay *= 2; - - // Don't increase the delay beyond the maximum - if(poll_interval_delay > poll_interval_maxdelay) { - poll_interval_delay = poll_interval_maxdelay; - } - } else { - poll_interval_delay = end_of_page - ? poll_interval_mindelay_bottom - : poll_interval_mindelay_top; - } - - poll_interval = setTimeout(poll, poll_interval_delay); - poll_current_time = poll_interval_delay; - return false; }; $(window).scroll(function() { recheck_activated(); - + + // if the newest post is not visible if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) { end_of_page = false; return; + } else { + if($("#auto_update_status").is(':checked')) { + poll(manualUpdate = true); + } + end_of_page = true; } - - clearTimeout(poll_interval); - poll_interval = setTimeout(poll, poll_interval_shortdelay); - poll_current_time = poll_interval_shortdelay; - end_of_page = true; }).trigger('scroll'); - $('#update_thread').on('click', poll); - setInterval(timer_update, 1000); - setInterval(decrement_timer, 1000); + $('#update_thread').on('click', function() { poll(manualUpdate = true); return false; }); - poll_interval = setTimeout(poll, poll_interval_delay); - timer_update(); + if($("#auto_update_status").is(':checked')) { + auto_update(poll_interval_delay); + } }); -- cgit v1.3 From 3918386aaba9e885183aa3a09ca50e3c157cbbbe Mon Sep 17 00:00:00 2001 From: topkek Date: Sun, 28 Sep 2014 00:17:16 +0100 Subject: Update settings.js --- js/settings.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'js') diff --git a/js/settings.js b/js/settings.js index 02d5658d..64de9624 100644 --- a/js/settings.js +++ b/js/settings.js @@ -56,12 +56,8 @@ tb_settings['wpaint'] = { tb_settings['auto-reload'] = { // Minimum delay before reloading the page when at the bottom min_delay_bottom: 3000, - // Minimum delay before reloading the page when not at the bottom - min_delay_top: 10000, // Maximum delay before reloading the page max_delay: 600000, - //Delay to wait before reloading when the user scrolls to the bottom - quick_delay: 100, // Reset the delay to the minimum upon focussing the window. reset_focus: true }; -- cgit v1.3 From dd99b22f062825c35c1f2d875c45689364bba348 Mon Sep 17 00:00:00 2001 From: topkek Date: Sun, 28 Sep 2014 00:27:28 +0100 Subject: Update settings.js --- js/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/settings.js b/js/settings.js index 64de9624..fcc8f508 100644 --- a/js/settings.js +++ b/js/settings.js @@ -55,7 +55,7 @@ tb_settings['wpaint'] = { // auto-reload.js tb_settings['auto-reload'] = { // Minimum delay before reloading the page when at the bottom - min_delay_bottom: 3000, + min_delay_bottom: 5000, // Maximum delay before reloading the page max_delay: 600000, // Reset the delay to the minimum upon focussing the window. -- cgit v1.3 From 71491bc9e96c9ef421d9b91f7f5678d7fe737771 Mon Sep 17 00:00:00 2001 From: topkek Date: Sun, 28 Sep 2014 00:40:00 +0100 Subject: Update auto-reload.js --- js/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 0e4b730a..cc7f650f 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -33,7 +33,7 @@ $(document).ready(function(){ // Grab the settings var settings = new script_settings('auto-reload'); - var poll_interval_mindelay_bottom = 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); // number of ms to wait before reloading -- 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') 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') 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') 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 c4fd370d3f3628c90707bf7fb4c5ef86e344cea9 Mon Sep 17 00:00:00 2001 From: topkek Date: Sun, 28 Sep 2014 20:25:07 +0100 Subject: Update settings.js --- js/settings.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js') diff --git a/js/settings.js b/js/settings.js index fcc8f508..81e88f7a 100644 --- a/js/settings.js +++ b/js/settings.js @@ -58,6 +58,8 @@ tb_settings['auto-reload'] = { min_delay_bottom: 5000, // Maximum delay before reloading the page max_delay: 600000, + // Delay if there was an error + error_delay: 30000, // Reset the delay to the minimum upon focussing the window. reset_focus: true }; -- cgit v1.3 From 7aa2976524b0411795929203804ee3c27176ac19 Mon Sep 17 00:00:00 2001 From: Bui Date: Mon, 29 Sep 2014 05:18:00 +0900 Subject: wrap updater in ID span --- js/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/auto-reload.js b/js/auto-reload.js index cc7f650f..19581b5e 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -29,7 +29,7 @@ $(document).ready(function(){ var countdown_interval; // Add an update link - $('.boardlist.bottom').prev().after("["+_("Update")+"] ( Auto) "); + $('.boardlist.bottom').prev().after("["+_("Update")+"] ( Auto) "); // Grab the settings var settings = new script_settings('auto-reload'); -- cgit v1.3 From 2ece97d6858b98b3836840bca0da8f4f08fdc2f8 Mon Sep 17 00:00:00 2001 From: ScriptKi77y Date: Mon, 29 Sep 2014 22:02:57 -0500 Subject: Scroll hook thread polling adjusttment. Fixed an issue with the scroll hook thread polling. Users scrolling near the bottom of the page are making upwards of 7-10 requests a second to the site. Added a small timer using the "poll_interval_mindelay" value to prevent unnecessary polling, one is enough during this minimum time delay. --- js/auto-reload.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 19581b5e..8a4ab949 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -121,6 +121,18 @@ $(document).ready(function(){ clearInterval(countdown_interval); } + var epoch = (new Date).getTime(); + var epochold = epoch; + + var timeDiff = function (delay) { + if((epoch-epochold) > delay) { + epochold = epoch = (new Date).getTime(); + return true; + }else{ + epoch = (new Date).getTime(); + return; + } + } var poll = function(manualUpdate) { stop_auto_update(); @@ -185,7 +197,7 @@ $(document).ready(function(){ end_of_page = false; return; } else { - if($("#auto_update_status").is(':checked')) { + if($("#auto_update_status").is(':checked') && timeDiff(poll_interval_mindelay)) { poll(manualUpdate = true); } end_of_page = true; -- cgit v1.3 From 7d5899d3a7ba6ab10ad75c6710cdfd661ed59383 Mon Sep 17 00:00:00 2001 From: ScriptKi77y Date: Tue, 30 Sep 2014 01:58:23 -0500 Subject: Quick fix to remove lag.. Executing a function to make a get request while simultaneously triggering a scroll event within the executed scroll event is probably not the best idea. This still needs work, there should probably be something else used to check for updates, such as an event where page has focus or something else that doesn't get called so many times, preferably something that reduces the timer instead. This is just a quick fix to stop all the lag on threads when scrolling near the bottom. --- js/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/auto-reload.js b/js/auto-reload.js index 8a4ab949..8a35335e 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -202,7 +202,7 @@ $(document).ready(function(){ } end_of_page = true; } - }).trigger('scroll'); + }); $('#update_thread').on('click', function() { poll(manualUpdate = true); return false; }); -- cgit v1.3 From 5f521adfd55c6d92ed3d62bf9350e7c7044b5093 Mon Sep 17 00:00:00 2001 From: Bui Date: Fri, 3 Oct 2014 00:37:43 +0900 Subject: fix hide link on images fetched with ajax --- js/hide-images.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/hide-images.js b/js/hide-images.js index ad5f401c..023c166c 100644 --- a/js/hide-images.js +++ b/js/hide-images.js @@ -96,6 +96,6 @@ $(document).ready(function(){ $('div.post > a > img.post-image, div > a > img.post-image').each(handle_images); $(document).on('new_post', function(e, post) { - $(post).find('> a > img.post-image').each(handle_images); + $(post).find('a > img.post-image').each(handle_images); }); }); -- 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') 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 From cb92ee048303a6d9065c2e7b9dd4f9532152db34 Mon Sep 17 00:00:00 2001 From: James Campos Date: Tue, 23 Sep 2014 19:52:06 -0700 Subject: inline --- js/inline.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 js/inline.js (limited to 'js') diff --git a/js/inline.js b/js/inline.js new file mode 100644 index 00000000..1130c68b --- /dev/null +++ b/js/inline.js @@ -0,0 +1,34 @@ +;(function() { + $('.body a').click(inline) + + $('head').append( + '') +})() + +function inline(e) { + e.preventDefault() + var postNum = parseInt(this.textContent.slice(2)) + + var cloneID = 'inline_' + postNum + var $clone = $('#' + cloneID) + if ($clone.length) + return $clone.remove() + + var OP = location.pathname.match(/(\d+).html/)[1] + var selector = postNum === OP + ? '.op .body' + : '#reply_' + postNum + ' .body' + + $clone = $(selector).clone(true) + $clone.attr({ + className: 'inline', + id: cloneID + }) + $clone.insertAfter(this) +} -- cgit v1.3 From 3de119e41750c065cebffefc216e56d339bbbc1c Mon Sep 17 00:00:00 2001 From: James Campos Date: Tue, 23 Sep 2014 21:25:34 -0700 Subject: maybe support cross thread inlining --- js/inline.js | 62 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 23 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 1130c68b..6b373dce 100644 --- a/js/inline.js +++ b/js/inline.js @@ -1,5 +1,40 @@ ;(function() { - $('.body a').click(inline) + var inline = function(e) { + e.preventDefault() + + var postNum = this.textContent.slice(2) + + var $clone = $('#inline_' + postNum) + if ($clone.length) + return $clone.remove() + + var OP = location.pathname.match(/(\d+).html/)[1] + var selector = postNum === OP + ? '.op .body' + : '#reply_' + postNum + ' .body' + + var link = { + postNum: postNum, + node: this + } + var $target = $(selector) + if ($target.length) + add(link, $target) + else + $.get(this.pathname, function(data) { + var $target = $(data).find(selector) + add(link, $target) + }) + } + + var add = function(link, $target) { + var $clone = $target.clone(true) + $clone.attr({ + "class": 'inline', + id: 'inline_' + link.postNum + }) + $clone.insertAfter(link.node) + } $('head').append( '') -})() -function inline(e) { - e.preventDefault() - var postNum = parseInt(this.textContent.slice(2)) - - var cloneID = 'inline_' + postNum - var $clone = $('#' + cloneID) - if ($clone.length) - return $clone.remove() - - var OP = location.pathname.match(/(\d+).html/)[1] - var selector = postNum === OP - ? '.op .body' - : '#reply_' + postNum + ' .body' - - $clone = $(selector).clone(true) - $clone.attr({ - className: 'inline', - id: cloneID - }) - $clone.insertAfter(this) -} + $('.body a').click(inline) + +})() -- cgit v1.3 From 274ac0965a6085c009fccbde1e427746d8ff4501 Mon Sep 17 00:00:00 2001 From: James Campos Date: Tue, 23 Sep 2014 21:40:32 -0700 Subject: get op from input value --- js/inline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 6b373dce..863aefbb 100644 --- a/js/inline.js +++ b/js/inline.js @@ -8,7 +8,7 @@ if ($clone.length) return $clone.remove() - var OP = location.pathname.match(/(\d+).html/)[1] + var OP = $('input[name="thread"]').val() var selector = postNum === OP ? '.op .body' : '#reply_' + postNum + ' .body' -- cgit v1.3 From 67d3449998cda1a981a841fce989f59936aaa8d1 Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 24 Sep 2014 12:17:30 -0700 Subject: fix cross-thread inlining --- js/inline.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 863aefbb..6334e60e 100644 --- a/js/inline.js +++ b/js/inline.js @@ -8,8 +8,8 @@ if ($clone.length) return $clone.remove() - var OP = $('input[name="thread"]').val() - var selector = postNum === OP + var postOP = this.pathname.match(/(\d+).html/)[1] + var selector = postNum === postOP ? '.op .body' : '#reply_' + postNum + ' .body' @@ -17,9 +17,12 @@ postNum: postNum, node: this } - var $target = $(selector) - if ($target.length) + + var OP = $('input[name="thread"]').val() + if (OP === postOP) { + var $target = $(selector) add(link, $target) + } else $.get(this.pathname, function(data) { var $target = $(data).find(selector) -- cgit v1.3 From 51a74bbd73f82418370176a9bb6190fb3c1b9da4 Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 24 Sep 2014 12:37:25 -0700 Subject: fix selector --- js/inline.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 6334e60e..e93df2b6 100644 --- a/js/inline.js +++ b/js/inline.js @@ -20,6 +20,8 @@ var OP = $('input[name="thread"]').val() if (OP === postOP) { + // XXX WTF the post hover script adds fetched threads to the DOM + selector = '#thread_' + OP + ' ' + selector var $target = $(selector) add(link, $target) } -- cgit v1.3 From 970ff0d61911b4054cc0214de1db2deabe738cae Mon Sep 17 00:00:00 2001 From: James Campos Date: Wed, 24 Sep 2014 12:49:18 -0700 Subject: this is how you cache --- js/inline.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index e93df2b6..8a2b6614 100644 --- a/js/inline.js +++ b/js/inline.js @@ -1,4 +1,6 @@ ;(function() { + var cache = {} + var inline = function(e) { e.preventDefault() @@ -23,13 +25,21 @@ // XXX WTF the post hover script adds fetched threads to the DOM selector = '#thread_' + OP + ' ' + selector var $target = $(selector) - add(link, $target) + return add(link, $target) + } + + var url = this.pathname + var data = cache[url] + if (data) { + var $target = $(data).find(selector) + return add(link, $target) } - else - $.get(this.pathname, function(data) { - var $target = $(data).find(selector) - add(link, $target) - }) + + $.get(url, function(data) { + cache[url] = data + var $target = $(data).find(selector) + add(link, $target) + }) } var add = function(link, $target) { -- cgit v1.3 From 91ab8eeae663ac5bda1206a95894f2b6d24ab5b2 Mon Sep 17 00:00:00 2001 From: James Campos Date: Thu, 25 Sep 2014 09:58:44 -0700 Subject: disable highlightReply --- js/inline.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 8a2b6614..728a887a 100644 --- a/js/inline.js +++ b/js/inline.js @@ -60,6 +60,8 @@ '}' + '') - $('.body a').click(inline) + $('.body a') + .attr('onclick', null)// disable highlightReply. so hacky + .click(inline) })() -- cgit v1.3 From ee4716b0481cfb2495eab931b3cac115e7f5d912 Mon Sep 17 00:00:00 2001 From: James Campos Date: Thu, 25 Sep 2014 10:11:33 -0700 Subject: work for backlinks --- js/inline.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 728a887a..df91c8a9 100644 --- a/js/inline.js +++ b/js/inline.js @@ -4,9 +4,10 @@ var inline = function(e) { e.preventDefault() + var $root = $(this).closest('.post') var postNum = this.textContent.slice(2) - var $clone = $('#inline_' + postNum) + var $clone = $root.find('#inline_' + postNum) if ($clone.length) return $clone.remove() @@ -15,9 +16,13 @@ ? '.op .body' : '#reply_' + postNum + ' .body' + var node = this.className + ? $root.find('.body').first().children().first() + : this.nextSibling + var link = { - postNum: postNum, - node: this + node: node, + postNum: postNum } var OP = $('input[name="thread"]').val() @@ -48,7 +53,7 @@ "class": 'inline', id: 'inline_' + link.postNum }) - $clone.insertAfter(link.node) + $clone.insertBefore(link.node) } $('head').append( @@ -60,7 +65,7 @@ '}' + '') - $('.body a') + $('.body a, .mentioned a') .attr('onclick', null)// disable highlightReply. so hacky .click(inline) -- cgit v1.3 From 26e343d02affb6291226baec587123f6a61e236a Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 09:17:19 -0700 Subject: fix --- js/inline.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index df91c8a9..ff897ca3 100644 --- a/js/inline.js +++ b/js/inline.js @@ -17,7 +17,8 @@ : '#reply_' + postNum + ' .body' var node = this.className - ? $root.find('.body').first().children().first() + // XXX post hover element is added to the quoting post + ? $root.find('> .body, > .inline').first() : this.nextSibling var link = { @@ -27,7 +28,7 @@ var OP = $('input[name="thread"]').val() if (OP === postOP) { - // XXX WTF the post hover script adds fetched threads to the DOM + // XXX post hover adds fetched threads to the DOM selector = '#thread_' + OP + ' ' + selector var $target = $(selector) return add(link, $target) @@ -66,7 +67,6 @@ '') $('.body a, .mentioned a') - .attr('onclick', null)// disable highlightReply. so hacky + .attr('onclick', null)// XXX disable highlightReply .click(inline) - })() -- cgit v1.3 From 8d91efc560015411fa2545b151607aba4f91cca7 Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 09:53:11 -0700 Subject: grab the whole post --- js/inline.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index ff897ca3..55389f36 100644 --- a/js/inline.js +++ b/js/inline.js @@ -14,7 +14,7 @@ var postOP = this.pathname.match(/(\d+).html/)[1] var selector = postNum === postOP ? '.op .body' - : '#reply_' + postNum + ' .body' + : '#reply_' + postNum var node = this.className // XXX post hover element is added to the quoting post @@ -51,7 +51,7 @@ var add = function(link, $target) { var $clone = $target.clone(true) $clone.attr({ - "class": 'inline', + "class": 'inline post', id: 'inline_' + link.postNum }) $clone.insertBefore(link.node) @@ -59,11 +59,8 @@ $('head').append( '') $('.body a, .mentioned a') -- cgit v1.3 From bb193e93e2925f5ec71756e34f65534a34d67f77 Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 10:00:44 -0700 Subject: fix for image posts --- js/inline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 55389f36..fd445a7a 100644 --- a/js/inline.js +++ b/js/inline.js @@ -18,7 +18,7 @@ var node = this.className // XXX post hover element is added to the quoting post - ? $root.find('> .body, > .inline').first() + ? $root.find('> .files, > .inline').first() : this.nextSibling var link = { -- cgit v1.3 From aea23e99b6b650f152bbddac47c2e18310949565 Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 10:03:31 -0700 Subject: less invasive css fix --- js/inline.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index fd445a7a..3eac588e 100644 --- a/js/inline.js +++ b/js/inline.js @@ -59,8 +59,7 @@ $('head').append( '') $('.body a, .mentioned a') -- cgit v1.3 From b1a59116735f3e82225141da52c99175220d90bd Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 13:05:45 -0700 Subject: fix when quote is last element --- js/inline.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 3eac588e..26b13f91 100644 --- a/js/inline.js +++ b/js/inline.js @@ -17,9 +17,8 @@ : '#reply_' + postNum var node = this.className - // XXX post hover element is added to the quoting post - ? $root.find('> .files, > .inline').first() - : this.nextSibling + ? $root.find('> .intro') + : this var link = { node: node, @@ -54,7 +53,7 @@ "class": 'inline post', id: 'inline_' + link.postNum }) - $clone.insertBefore(link.node) + $clone.insertAfter(link.node) } $('head').append( -- cgit v1.3 From 9ea5ff610e38f3c390cb19bec86ee5b1ab57d187 Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 13:08:50 -0700 Subject: bypass (OP) text --- js/inline.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 26b13f91..0ea7f233 100644 --- a/js/inline.js +++ b/js/inline.js @@ -18,7 +18,7 @@ var node = this.className ? $root.find('> .intro') - : this + : $(this) var link = { node: node, @@ -29,6 +29,8 @@ if (OP === postOP) { // XXX post hover adds fetched threads to the DOM selector = '#thread_' + OP + ' ' + selector + // XXX bypass the `(OP)` text + link.node = link.node.next() var $target = $(selector) return add(link, $target) } -- cgit v1.3 From 3c98319e52bb1b902c726a435a3c77c927492925 Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 13:28:52 -0700 Subject: front page fixes --- js/inline.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 0ea7f233..622d40b3 100644 --- a/js/inline.js +++ b/js/inline.js @@ -25,14 +25,16 @@ postNum: postNum } - var OP = $('input[name="thread"]').val() - if (OP === postOP) { + var srcOP = $root.closest('[id^=thread]').attr('id').match(/\d+/)[0] + if (srcOP === postOP) { // XXX post hover adds fetched threads to the DOM - selector = '#thread_' + OP + ' ' + selector + selector = '#thread_' + srcOP + ' ' + selector // XXX bypass the `(OP)` text link.node = link.node.next() + var $target = $(selector) - return add(link, $target) + if ($target.length) + return add(link, $target) } var url = this.pathname @@ -53,7 +55,8 @@ var $clone = $target.clone(true) $clone.attr({ "class": 'inline post', - id: 'inline_' + link.postNum + id: 'inline_' + link.postNum, + style: null// XXX remove post hover styling }) $clone.insertAfter(link.node) } -- cgit v1.3 From 3ce156a0d0a6e451b6ecb048f4b14f8a7db057b2 Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 13:32:41 -0700 Subject: rename --- js/inline.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 622d40b3..fb50684b 100644 --- a/js/inline.js +++ b/js/inline.js @@ -5,16 +5,16 @@ e.preventDefault() var $root = $(this).closest('.post') - var postNum = this.textContent.slice(2) + var targetNum = this.textContent.slice(2) - var $clone = $root.find('#inline_' + postNum) + var $clone = $root.find('#inline_' + targetNum) if ($clone.length) return $clone.remove() - var postOP = this.pathname.match(/(\d+).html/)[1] - var selector = postNum === postOP + var targetOP = this.pathname.match(/(\d+).html/)[1] + var selector = targetNum === targetOP ? '.op .body' - : '#reply_' + postNum + : '#reply_' + targetNum var node = this.className ? $root.find('> .intro') @@ -22,11 +22,11 @@ var link = { node: node, - postNum: postNum + targetNum: targetNum } var srcOP = $root.closest('[id^=thread]').attr('id').match(/\d+/)[0] - if (srcOP === postOP) { + if (srcOP === targetOP) { // XXX post hover adds fetched threads to the DOM selector = '#thread_' + srcOP + ' ' + selector // XXX bypass the `(OP)` text @@ -55,7 +55,7 @@ var $clone = $target.clone(true) $clone.attr({ "class": 'inline post', - id: 'inline_' + link.postNum, + id: 'inline_' + link.targetNum, style: null// XXX remove post hover styling }) $clone.insertAfter(link.node) -- cgit v1.3 From 2f85073d281bc9cc6d8a09c5607f9a182c81004e Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 13:40:05 -0700 Subject: fix front page backlink --- js/inline.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index fb50684b..2b5200fc 100644 --- a/js/inline.js +++ b/js/inline.js @@ -11,21 +11,26 @@ if ($clone.length) return $clone.remove() - var targetOP = this.pathname.match(/(\d+).html/)[1] - var selector = targetNum === targetOP - ? '.op .body' - : '#reply_' + targetNum + var srcOP = $root.closest('[id^=thread]').attr('id').match(/\d+/)[0] - var node = this.className - ? $root.find('> .intro') - : $(this) + var node, targetOP + if (this.className) {// backlink + node = $root.find('> .intro') + targetOP = srcOP + } else { + node = $(this) + targetOP = this.pathname.match(/(\d+).html/)[1] + } var link = { node: node, targetNum: targetNum } - var srcOP = $root.closest('[id^=thread]').attr('id').match(/\d+/)[0] + var selector = targetNum === targetOP + ? '.op .body' + : '#reply_' + targetNum + if (srcOP === targetOP) { // XXX post hover adds fetched threads to the DOM selector = '#thread_' + srcOP + ' ' + selector -- cgit v1.3 From 9dce04ebc82072978cdcfaae28caa9b6e2f09a5b Mon Sep 17 00:00:00 2001 From: James Campos Date: Fri, 3 Oct 2014 13:41:54 -0700 Subject: remove inlined posts for new inlined posts --- js/inline.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 2b5200fc..a0b80649 100644 --- a/js/inline.js +++ b/js/inline.js @@ -58,6 +58,7 @@ var add = function(link, $target) { var $clone = $target.clone(true) + $clone.find('.inline').remove() $clone.attr({ "class": 'inline post', id: 'inline_' + link.targetNum, -- cgit v1.3 From 702e20753a8cc2f879ae294427ce00ae1763f335 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 4 Oct 2014 06:48:29 -0700 Subject: clearfix --- js/inline.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index a0b80649..0b7a47a0 100644 --- a/js/inline.js +++ b/js/inline.js @@ -69,7 +69,11 @@ $('head').append( '') $('.body a, .mentioned a') -- cgit v1.3 From 262f525e75a74909b41e2fe6b10072b1af1feb72 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 4 Oct 2014 08:16:01 -0700 Subject: fix --- js/inline.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 0b7a47a0..b83a5ae6 100644 --- a/js/inline.js +++ b/js/inline.js @@ -34,8 +34,10 @@ if (srcOP === targetOP) { // XXX post hover adds fetched threads to the DOM selector = '#thread_' + srcOP + ' ' + selector - // XXX bypass the `(OP)` text - link.node = link.node.next() + + // bypass `(OP)` + if (targetNum === targetOP) + link.node = link.node.next() var $target = $(selector) if ($target.length) -- cgit v1.3 From daa30a12de74764d9944e53bf63ce9a7dda5860d Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 5 Oct 2014 07:19:14 -0700 Subject: better op selector, don't attach to links --- js/inline.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index b83a5ae6..9232fa63 100644 --- a/js/inline.js +++ b/js/inline.js @@ -28,16 +28,12 @@ } var selector = targetNum === targetOP - ? '.op .body' + ? '#op_' + srcOP : '#reply_' + targetNum if (srcOP === targetOP) { - // XXX post hover adds fetched threads to the DOM - selector = '#thread_' + srcOP + ' ' + selector - - // bypass `(OP)` if (targetNum === targetOP) - link.node = link.node.next() + link.node = link.node.next()// bypass `(OP)` var $target = $(selector) if ($target.length) @@ -78,7 +74,8 @@ '}' + '') - $('.body a, .mentioned a') + // don't attach to outbound links + $('.body a:not([rel]), .mentioned a') .attr('onclick', null)// XXX disable highlightReply .click(inline) })() -- cgit v1.3 From 1e04f29485583cd1b85276b2fbfeb47f51473e30 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 5 Oct 2014 15:51:22 -0700 Subject: extract caching --- js/inline.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index 9232fa63..bcbf156f 100644 --- a/js/inline.js +++ b/js/inline.js @@ -1,5 +1,18 @@ ;(function() { - var cache = {} + var App = { + cache: {}, + get: function(url, cb) { + var $page = App.cache[url] + if ($page) + return cb($page) + + $.get(url, function(data) { + var $page = $(data) + App.cache[url] = $page + cb($page) + }) + } + } var inline = function(e) { e.preventDefault() @@ -40,16 +53,8 @@ return add(link, $target) } - var url = this.pathname - var data = cache[url] - if (data) { - var $target = $(data).find(selector) - return add(link, $target) - } - - $.get(url, function(data) { - cache[url] = data - var $target = $(data).find(selector) + App.get(this.pathname, function($page) { + var $target = $page.find(selector) add(link, $target) }) } -- cgit v1.3 From f1b89a5302dbb5016b3ac02b68b1111c99e25dd5 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 5 Oct 2014 16:20:25 -0700 Subject: optional --- js/inline.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index bcbf156f..5399e871 100644 --- a/js/inline.js +++ b/js/inline.js @@ -11,6 +11,37 @@ App.cache[url] = $page cb($page) }) + }, + options: { + add: function(key, description, tab) { + tab || (tab = 'general') + + var checked = App.options.get(key) + var $el = $( + '
' + + '' + + '
') + + $el + .find('input') + .prop('checked', checked) + .on('change', App.options.check(key)) + + window.Options.extend_tab(tab, $el) + }, + get: function(key) { + if (localStorage[key]) + return JSON.parse(localStorage[key]) + }, + check: function(key) { + return function(e) { + var val = this.checked + localStorage[key] = JSON.stringify(val) + } + } } } @@ -70,6 +101,11 @@ $clone.insertAfter(link.node) } + App.options.add('inline', 'Inline quoted posts') + + if (!App.options.get('inline')) + return + $('head').append( '') // don't attach to outbound links - $('.body a:not([rel]), .mentioned a') - .attr('onclick', null)// XXX disable highlightReply - .click(inline) + + if (App.options.get('useBacklinks')) { + $('.body a:not([rel]), .mentioned a') + .attr('onclick', null)// XXX disable highlightReply + .click(inline) + } }) -- cgit v1.3 From b7e9007ad445d9da30059bac1ea782fbfdc42d62 Mon Sep 17 00:00:00 2001 From: 8chan Date: Mon, 6 Oct 2014 18:42:07 -0700 Subject: This makes the options appear at the bottom for some reason --- js/inline.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index c1aed4dd..e3dcc988 100644 --- a/js/inline.js +++ b/js/inline.js @@ -1,4 +1,4 @@ -onready(function() { +$(document).ready(function() { var App = { cache: {}, get: function(url, cb) { @@ -142,4 +142,4 @@ onready(function() { .attr('onclick', null)// XXX disable highlightReply .click(inline) } -}) +}); -- cgit v1.3 From 582c77a9350a6a06c4704ee15adaacba57aeea23 Mon Sep 17 00:00:00 2001 From: 8chan Date: Mon, 6 Oct 2014 19:02:39 -0700 Subject: Fix name and order --- js/inline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/inline.js b/js/inline.js index e3dcc988..796c48a1 100644 --- a/js/inline.js +++ b/js/inline.js @@ -123,8 +123,8 @@ $(document).ready(function() { $clone.insertAfter(link.node) } + App.options.add('useInlining', 'Enable inlining') App.options.add('hidePost', 'Hide inlined backlinked posts') - App.options.add('useBacklinks', 'Enable backlinks') $('head').append( ''); + update_thread_stats(true); + $('#update_thread').click(update_thread_stats); + MutationObserver = window.MutationObserver || window.WebKitMutationObserver; + var observer = new MutationObserver(function(mutations, observer){update_thread_stats();}); + observer.observe($('#thread_' + thread_id)[0], {childList: true}); + }); +} \ No newline at end of file -- cgit v1.3 From 8d451280306c4f05ebb966399420ae4f08831965 Mon Sep 17 00:00:00 2001 From: ForklessAnon Date: Sat, 1 Nov 2014 04:29:21 -0500 Subject: Some code cleanup on thread stats. --- js/thread-stats.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index e6fb1142..59fed912 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -7,10 +7,7 @@ * $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/thread-stats.js'; */ -// THREAD STATS if (active_page == 'thread') { - - var thread_stats_timer = 30, thread_stats_timeout; //it has to be on a timer because there I haven't found a way to hook into when the actual page updates the thread... //check if page uses unique ID var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); @@ -27,7 +24,7 @@ if (active_page == 'thread') { el.prepend('0 images | '); el.prepend('0 replies | '); delete el; - function update_thread_stats(force){ + function update_thread_stats(){ var op = $('#thread_'+ thread_id +' > div.post.op:not(.post-hover):not(.inline)').first(); var replies = $('#thread_'+ thread_id +' > div.post.reply:not(.post-hover):not(.inline)'); // post count @@ -102,14 +99,11 @@ if (active_page == 'thread') { $('#thread_stats_page').text(page); if (!found) $('#thread_stats_page').css('color','red'); }); - },30000); $(document).ready(function(){ $('body').append(''); - update_thread_stats(true); + update_thread_stats(); $('#update_thread').click(update_thread_stats); - MutationObserver = window.MutationObserver || window.WebKitMutationObserver; - var observer = new MutationObserver(function(mutations, observer){update_thread_stats();}); - observer.observe($('#thread_' + thread_id)[0], {childList: true}); + $(document).on('new_post',update_thread_stats); }); } \ No newline at end of file -- cgit v1.3 From 1aa8f6251d30545242768bf13bbe9ee89c231ca7 Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 12 Nov 2014 01:19:02 -0800 Subject: Have to load onready --- js/thread-stats.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 59fed912..4050fb67 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -8,8 +8,9 @@ * $config['additional_javascript'][] = 'js/thread-stats.js'; */ if (active_page == 'thread') { +$(document).ready(function(){ //check if page uses unique ID - var IDsupport = ($('.poster_id').length > 0); + var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); thread_id = thread_id[thread_id.length -1].split('+')[0].split('.')[0]; @@ -100,10 +101,9 @@ if (active_page == 'thread') { if (!found) $('#thread_stats_page').css('color','red'); }); },30000); - $(document).ready(function(){ $('body').append(''); update_thread_stats(); $('#update_thread').click(update_thread_stats); $(document).on('new_post',update_thread_stats); - }); -} \ No newline at end of file +}); +} -- cgit v1.3 From fdc14c699c25131ffe25536928e0dfac990c4ae3 Mon Sep 17 00:00:00 2001 From: Forkless Date: Mon, 17 Nov 2014 03:06:56 -0600 Subject: Fix color incase page is missed and then found again. --- js/thread-stats.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 4050fb67..7c13d66c 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -79,6 +79,7 @@ $(document).ready(function(){ } $('#thread_stats_page').text(page); if (!found) $('#thread_stats_page').css('color','red'); + else $('#thread_stats_page').css('color',''); }); } // load the current page the thread is on. @@ -99,6 +100,7 @@ $(document).ready(function(){ } $('#thread_stats_page').text(page); if (!found) $('#thread_stats_page').css('color','red'); + else $('#thread_stats_page').css('color',''); }); },30000); $('body').append(''); -- cgit v1.3 From cf91daee7cfbdbede0e0d01b40dd7879cab88186 Mon Sep 17 00:00:00 2001 From: 8chan Date: Fri, 21 Nov 2014 23:33:42 -0800 Subject: No need to display pruned in two places...especially if server times out / errors --- js/thread-stats.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 7c13d66c..1785b79a 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -65,7 +65,7 @@ $(document).ready(function(){ $('#thread_stats_uids').text(size(ids)); } $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ - var found, page = 'Pruned or Deleted'; + var found, page = '???'; for (var i=0;data[i];i++){ var threads = data[i].threads; for (var j=0; threads[j]; j++){ @@ -86,7 +86,7 @@ $(document).ready(function(){ // uses ajax call so it gets loaded on a delay (depending on network resources available) var thread_stats_page_timer = setInterval(function(){ $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ - var found, page = 'Pruned or Deleted'; + var found, page = '???'; for (var i=0;data[i];i++){ var threads = data[i].threads; for (var j=0; threads[j]; j++){ -- cgit v1.3 From 4b782d6163d061e394e857d6c4f1a94391ddf01b Mon Sep 17 00:00:00 2001 From: Forkless Date: Sat, 22 Nov 2014 19:41:23 -0600 Subject: Fix thread stats so post count hover works on the OP's id. --- js/thread-stats.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 1785b79a..9b9b3cb3 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -50,9 +50,12 @@ $(document).ready(function(){ ids[opID] = 0; } ids[opID]++; + var cur = op.find('>.intro >.poster_id'); + cur.find('+.posts_by_id').remove(); + cur.after(' ('+ ids[cur.text()] +')'); replies.each(function(){ - var cur = $(this).find('> .intro > .poster_id'); - cur.find('+ .posts_by_id').remove(); + cur = $(this).find('>.intro >.poster_id'); + cur.find('+.posts_by_id').remove(); cur.after(' ('+ ids[cur.text()] +')'); }); var size = function(obj) { -- cgit v1.3 From c4fc8273328a7d4955e472e3242837a4e210adaf Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 11 Mar 2015 18:22:22 -0700 Subject: some style fixes Conflicts: templates/8chan/boards-tags.html --- js/thread-stats.js | 2 +- stylesheets/dark.css | 8 ++++++-- stylesheets/photon.css | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 9b9b3cb3..fb520c71 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -16,7 +16,7 @@ $(document).ready(function(){ $('form[name="postcontrols"] > .delete') .first() - .before('
'); + .before('
'); var el = $('#thread_stats'); el.prepend('Page ?'); if (IDsupport){ diff --git a/stylesheets/dark.css b/stylesheets/dark.css index 7fc4e199..beb12364 100644 --- a/stylesheets/dark.css +++ b/stylesheets/dark.css @@ -166,13 +166,13 @@ table.modlog tr th { color: #AAAAAA; } -.desktop-style div.boardlist:nth-child(1) { +.desktop-style div.boardlist:not(.bottom) { text-shadow: black 1px 1px 1px, black -1px -1px 1px, black -1px 1px 1px, black 1px -1px 1px; background-color: #666666; } -.desktop-style div.boardlist:nth-child(1):hover, .desktop-style div.boardlist:nth-child(1).cb-menu { +.desktop-style div.boardlist:not(.bottom):hover, .desktop-style div.boardlist:not(.bottom).cb-menu { background-color: rgba(30%, 30%, 30%, 0.65); } @@ -190,3 +190,7 @@ div.report { .options_tab_icon.active { color: #FFFFFF; } + +#quick-reply table { + background: none repeat scroll 0% 0% #333 !important; +} diff --git a/stylesheets/photon.css b/stylesheets/photon.css index db189d77..a487e4dd 100644 --- a/stylesheets/photon.css +++ b/stylesheets/photon.css @@ -326,6 +326,6 @@ form table tr td div { padding: 0px !important; } -.desktop-style div.boardlist:nth-child(1) { +.desktop-style div.boardlist:not(.bottom) { background-color: #DDDDDD; } -- cgit v1.3 From 0d0b2fcd7e807f50b621c17e153194cf99edef5b Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 10 Apr 2015 23:11:59 +0200 Subject: thread-stats.js: vichan fixes --- js/thread-stats.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index fb520c71..f3b2d375 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -12,9 +12,9 @@ $(document).ready(function(){ //check if page uses unique ID var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); - thread_id = thread_id[thread_id.length -1].split('+')[0].split('.')[0]; + thread_id = thread_id[thread_id.length -1].split(/+-/)[0].split('.')[0]; - $('form[name="postcontrols"] > .delete') + $('.boardlist.bottom, footer') .first() .before('
'); var el = $('#thread_stats'); @@ -67,6 +67,7 @@ $(document).ready(function(){ }; $('#thread_stats_uids').text(size(ids)); } + var board_name = $('input[name="board"]').val(); $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ var found, page = '???'; for (var i=0;data[i];i++){ @@ -88,6 +89,7 @@ $(document).ready(function(){ // load the current page the thread is on. // uses ajax call so it gets loaded on a delay (depending on network resources available) var thread_stats_page_timer = setInterval(function(){ + var board_name = $('input[name="board"]').val(); $.getJSON('//'+ document.location.host +'/'+ board_name +'/threads.json').success(function(data){ var found, page = '???'; for (var i=0;data[i];i++){ -- cgit v1.3 From c4569b2ea55d162716cda443c7f28ceed672e0eb Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 10 Apr 2015 23:13:52 +0200 Subject: thread-stats.js: code typo :^) --- js/thread-stats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index f3b2d375..6035de04 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -12,7 +12,7 @@ $(document).ready(function(){ //check if page uses unique ID var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); - thread_id = thread_id[thread_id.length -1].split(/+-/)[0].split('.')[0]; + thread_id = thread_id[thread_id.length -1].split(/\+-/)[0].split('.')[0]; $('.boardlist.bottom, footer') .first() -- cgit v1.3 From bdda1613a6bc4b88dfe9027dc0f330194654ad9c Mon Sep 17 00:00:00 2001 From: czaks Date: Fri, 10 Apr 2015 23:43:07 +0200 Subject: thread-stats.js: final vichan fix, should work now --- js/thread-stats.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/thread-stats.js b/js/thread-stats.js index 6035de04..8873dbdb 100644 --- a/js/thread-stats.js +++ b/js/thread-stats.js @@ -12,18 +12,18 @@ $(document).ready(function(){ //check if page uses unique ID var IDsupport = ($('.poster_id').length > 0); var thread_id = (document.location.pathname + document.location.search).split('/'); - thread_id = thread_id[thread_id.length -1].split(/\+-/)[0].split('.')[0]; + thread_id = thread_id[thread_id.length -1].split('+')[0].split('-')[0].split('.')[0]; $('.boardlist.bottom, footer') .first() .before('
'); var el = $('#thread_stats'); - el.prepend('Page ?'); + el.prepend(_('Page')+' ?'); if (IDsupport){ el.prepend('0 UIDs | '); } - el.prepend('0 images | '); - el.prepend('0 replies | '); + el.prepend('0 '+_('images')+' | '); + el.prepend('0 '+_('replies')+' | '); delete el; function update_thread_stats(){ var op = $('#thread_'+ thread_id +' > div.post.op:not(.post-hover):not(.inline)').first(); -- cgit v1.3 From cb700e6a72602066404a38403c2f559532de26ca Mon Sep 17 00:00:00 2001 From: czaks Date: Sat, 11 Apr 2015 23:03:45 +0200 Subject: live index should refresh every 20s --- js/live-index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/live-index.js b/js/live-index.js index 463f7596..017d0c1f 100644 --- a/js/live-index.js +++ b/js/live-index.js @@ -58,7 +58,7 @@ if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?| update_new_threads(new_threads); }); - }, 1000); + }, 20000); }); $(document).on("new_post", function(e, post) { -- cgit v1.3 From 4131a6e5636df3afac7b0894994074cda6fa3b6b Mon Sep 17 00:00:00 2001 From: czaks Date: Sat, 11 Apr 2015 23:12:13 +0200 Subject: watch.js: slow down a little bit, let`s see how it works out --- js/watch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/watch.js b/js/watch.js index 8ac026a7..07c6942a 100644 --- a/js/watch.js +++ b/js/watch.js @@ -248,7 +248,7 @@ $(function(){ var st = storage(); var sched = 0; - var sched_diff = 300; + var sched_diff = 2000; for (var i in st) { if (st[i].watched) { -- cgit v1.3 From 3f029853802308ca51cc979bc01074bcbc3e9fc9 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 23 Apr 2015 07:41:36 +0200 Subject: gallery-view.js: initial commit --- js/gallery-view.js | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ stylesheets/style.css | 55 ++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 js/gallery-view.js (limited to 'js') diff --git a/js/gallery-view.js b/js/gallery-view.js new file mode 100644 index 00000000..efe1b3b1 --- /dev/null +++ b/js/gallery-view.js @@ -0,0 +1,124 @@ +if (active_page == 'index' || active_page == 'thread') +$(function(){ + + var gallery_view = false; + + $('hr:first').before(''); + $('#gallery-view a').html(gallery_view ? _("Disable gallery mode") : _("Enable gallery mode")).click(function() { + gallery_view = !gallery_view; + $(this).html(gallery_view ? _("Disable gallery mode") : _("Enable gallery mode")); + toggle_gview(document); + }); + + var toggle_gview = function(elem) { + if (gallery_view) { + $(elem).find('img.post-image').parent().each(function() { + this.oldonclick = this.onclick; + this.onclick = handle_click; + $(this).attr('data-galid', Math.random()); + }); + } + else { + $(elem).find('img.post-image').parent().each(function() { + if (this.onclick == handle_click) this.onclick = this.oldonclick; + }); + } + }; + + $(document).on('new_post', toggle_gview); + + var gallery_opened = false; + + var handle_click = function(e) { + e.stopPropagation(); + e.preventDefault(); + + if (!gallery_opened) open_gallery(); + + gallery_setimage($(this).attr('data-galid')); + }; + + var handler, images, active, toolbar; + + var open_gallery = function() { + $('body').css('overflow', 'hidden'); + + gallery_opened = true; + + handler = $("
").hide().appendTo('body').css('text-align', 'left'); + + $("
").click(close_gallery).appendTo(handler); + + images = $("").appendTo(handler); + toolbar = $("").appendTo(handler); + active = $("").appendTo(handler); + + active.on('click', function() { + close_gallery(); + }); + + $('img.post-image').parent().each(function() { + var thumb = $(this).find('img').attr('src'); + + var i = $('').appendTo(images); + i.attr('src', thumb); + i.attr('data-galid-th', $(this).attr('data-galid')); + + i.on('click', function(e) { + gallery_setimage($(this).attr('data-galid-th')); + }); + }); + + $("") + .click(close_gallery).appendTo(toolbar); + + handler.fadeIn(400); + }; + + var gallery_setimage = function(a) { + if (a == +1 || a == -1) { + var meth = (a == -1) ? 'prev' : 'next'; + a = $('#gallery_images img.active')[meth]().attr('data-galid-th'); + if (!a) return; + } + + $('#gallery_images img.active').removeClass('active'); + + var thumb = $('#gallery_images img[data-galid-th="'+a+'"]'); + var elem = $('a[data-galid="'+a+'"]'); + + thumb.addClass('active'); + + var topscroll = thumb.position().top + images.scrollTop(); + topscroll -= images.height() / 2; + topscroll += thumb.height() / 2; + images.animate({'scrollTop': topscroll}, 300); + + var img = elem.attr('href'); + + active.find('img').fadeOut(200, function() { $(this).remove(); }); + + var i = $(''); + i.attr('src', img); + i.appendTo(active); + i.hide(); + + i.on('load', function() { + i.css('left', 'calc(50% - '+i.width()+'px / 2)'); + i.css('top', 'calc(50% - '+i.height()+'px / 2)'); + i.fadeIn(200); + }).on('click', function(e) { + e.stopPropagation(); + gallery_setimage(+1); + }); + }; + + var close_gallery = function() { + $('body').css('overflow', 'auto'); + + gallery_opened = false; + + handler.fadeOut(400, function() { handler.remove(); }); + }; + +}); diff --git a/stylesheets/style.css b/stylesheets/style.css index 5ae23cd6..4c4c40f5 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -1060,3 +1060,58 @@ table.fileboard th, table.fileboard td { table.fileboard .intro a { margin-left: 0px; } + +/* Gallery view */ +#gallery_images { + position: absolute; + right: 0px; + bottom: 0px; + top: 0px; + width: 15%; + background-color: rgba(0, 0, 0, 0.4); + overflow: auto; +} +#gallery_toolbar { + position: absolute; + right: 15%; + left: 0px; + bottom: 0px; + height: 32px; + background-color: rgba(0, 0, 0, 0.4); + text-align: right; +} +#gallery_images img { + width: 100%; +} +#gallery_toolbar a { + font-size: 28px; + padding-right: 5px; +} +#gallery_main { + position: absolute; + left: 0px; + right: 15%; + bottom: 32px; + top: 0px; + padding: 10px; +} + +#gallery_images img { + opacity: 0.6; + -webkit-transition: all 0.5s; + transition: all 0.5s; +} +#gallery_images img:hover, #gallery_images img.active { + opacity: 1; +} +#gallery_images img.active { + -webkit-box-shadow: 0px 0px 29px 2px rgba(255,255,255,1); + -moz-box-shadow: 0px 0px 29px 2px rgba(255,255,255,1); + box-shadow: 0px 0px 29px 2px rgba(255,255,255,1); + z-index: 1; +} +#gallery_main img { + max-width: 100%; + max-height: 100%; + position: absolute; +} -- cgit v1.3 From 163a4e699c75cfa0b658e7c1e39153c2f603c483 Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 23 Apr 2015 08:45:39 +0200 Subject: gallery-view: support key events (up/down/left/right) --- js/gallery-view.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'js') diff --git a/js/gallery-view.js b/js/gallery-view.js index efe1b3b1..65a1e967 100644 --- a/js/gallery-view.js +++ b/js/gallery-view.js @@ -72,6 +72,17 @@ $(function(){ $("") .click(close_gallery).appendTo(toolbar); + $('body').on('keydown.gview', function(e) { + if (e.which == 39 || e.which == 40) { // right or down arrow + gallery_setimage(+1); + e.preventDefault(); + } + else if (e.which == 37 || e.which == 38) { // left or up arrow + gallery_setimage(-1); + e.preventDefault(); + } + }); + handler.fadeIn(400); }; @@ -103,6 +114,8 @@ $(function(){ i.appendTo(active); i.hide(); + // Let's actually preload the next few images + i.on('load', function() { i.css('left', 'calc(50% - '+i.width()+'px / 2)'); i.css('top', 'calc(50% - '+i.height()+'px / 2)'); @@ -118,6 +131,8 @@ $(function(){ gallery_opened = false; + $('body').off('keydown.gview'); + handler.fadeOut(400, function() { handler.remove(); }); }; -- cgit v1.3 From 099e347e15f87ca757f206c20f77b1fdeb8e887f Mon Sep 17 00:00:00 2001 From: czaks Date: Thu, 23 Apr 2015 09:20:34 +0200 Subject: gallery-view: preloading images, webm support --- js/gallery-view.js | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'js') diff --git a/js/gallery-view.js b/js/gallery-view.js index 65a1e967..2d7d85b4 100644 --- a/js/gallery-view.js +++ b/js/gallery-view.js @@ -95,7 +95,7 @@ $(function(){ $('#gallery_images img.active').removeClass('active'); - var thumb = $('#gallery_images img[data-galid-th="'+a+'"]'); + var thumb = $('#gallery_images [data-galid-th="'+a+'"]'); var elem = $('a[data-galid="'+a+'"]'); thumb.addClass('active'); @@ -107,16 +107,42 @@ $(function(){ var img = elem.attr('href'); - active.find('img').fadeOut(200, function() { $(this).remove(); }); + active.find('img, video').fadeOut(200, function() { $(this).remove(); }); - var i = $(''); - i.attr('src', img); - i.appendTo(active); - i.hide(); + var i; + if (img.match(/player\.php/)) { + img = img.replace(/.*player\.php\?v=|&t=.*/g, ''); + } + if (img.match(/\.webm$|\.mp4$|\.ogv$/i)) { // We are handling video nao + i = $('["+_("Update")+"] ( "+_("Auto")+") "); - - // 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); - - // number of ms to wait before reloading - var poll_interval_delay = poll_interval_mindelay; - var poll_current_time = poll_interval_delay; - - var end_of_page = false; - - var new_posts = 0; - var first_new_post = null; - - var title = document.title; - - if (typeof update_title == "undefined") { - var update_title = function() { - if (new_posts) { - document.title = "("+new_posts+") "+title; - } else { - document.title = title; - } - }; - } + if($('div.banner').length == 0) + return; // not index + + if($(".post.op").size() != 1) + return; //not thread page + + var countdown_interval; + + // Add an update link + $(".threadlinks span:last-child").after(""+_("Update")+" ] ( "+_("Auto")+") "); + + // 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); + + // number of ms to wait before reloading + var poll_interval_delay = poll_interval_mindelay; + var poll_current_time = poll_interval_delay; + + var end_of_page = false; + + var new_posts = 0; + var first_new_post = null; + + var title = document.title; + + if (typeof update_title == "undefined") { + var update_title = function() { + if (new_posts) { + document.title = "("+new_posts+") "+title; + } else { + document.title = title; + } + }; + } - if (typeof add_title_collector != "undefined") + if (typeof add_title_collector != "undefined") add_title_collector(function(){ - return new_posts; + return new_posts; }); - var window_active = true; - $(window).focus(function() { - window_active = true; - recheck_activated(); + var window_active = true; + $(window).focus(function() { + window_active = true; + recheck_activated(); - // Reset the delay if needed - if(settings.get('reset_focus', true)) { - poll_interval_delay = poll_interval_mindelay; - } - }); - $(window).blur(function() { - window_active = false; - }); - + // Reset the delay if needed + if(settings.get('reset_focus', true)) { + poll_interval_delay = poll_interval_mindelay; + } + }); + $(window).blur(function() { + window_active = false; + }); - $('#auto_update_status').click(function() { - if($("#auto_update_status").is(':checked')) { - auto_update(poll_interval_mindelay); - } else { - stop_auto_update(); - $('#update_secs').text(""); - } - }); - - - var decrement_timer = function() { - poll_current_time = poll_current_time - 1000; - $('#update_secs').text(poll_current_time/1000); - - if (poll_current_time <= 0) { - poll(manualUpdate = false); - } + $('#auto_update_status').click(function() { + if($("#auto_update_status").is(':checked')) { + auto_update(poll_interval_mindelay); + } else { + stop_auto_update(); + $('#update_secs').text(""); } - var recheck_activated = function() { - if (new_posts && window_active && - $(window).scrollTop() + $(window).height() >= - $('div.boardlist.bottom').position().top) { + }); - new_posts = 0; - } - update_title(); - first_new_post = null; - }; - - // automatically updates the thread after a specified delay - var auto_update = function(delay) { - clearInterval(countdown_interval); - - poll_current_time = delay; - countdown_interval = setInterval(decrement_timer, 1000); - $('#update_secs').text(poll_current_time/1000); + + var decrement_timer = function() { + poll_current_time = poll_current_time - 1000; + $('#update_secs').text(poll_current_time/1000); + + if (poll_current_time <= 0) { + poll(manualUpdate = false); } - - var stop_auto_update = function() { - clearInterval(countdown_interval); + } + + var recheck_activated = function() { + if (new_posts && window_active && + $(window).scrollTop() + $(window).height() >= + $('footer').position().top) { + + new_posts = 0; } - - var epoch = (new Date).getTime(); - var epochold = epoch; - - var timeDiff = function (delay) { - if((epoch-epochold) > delay) { - epochold = epoch = (new Date).getTime(); - return true; - }else{ - epoch = (new Date).getTime(); - return; - } + update_title(); + first_new_post = null; + }; + + // automatically updates the thread after a specified delay + var auto_update = function(delay) { + clearInterval(countdown_interval); + + poll_current_time = delay; + countdown_interval = setInterval(decrement_timer, 1000); + $('#update_secs').text(poll_current_time/1000); + } + + var stop_auto_update = function() { + clearInterval(countdown_interval); + } + + var epoch = (new Date).getTime(); + var epochold = epoch; + + var timeDiff = function (delay) { + if((epoch-epochold) > delay) { + epochold = epoch = (new Date).getTime(); + return true; + }else{ + epoch = (new Date).getTime(); + return; } - - var poll = function(manualUpdate) { - stop_auto_update(); - $('#update_secs').text(_("Updating...")); - - $.ajax({ - url: document.location, - success: function(data) { - var loaded_posts = 0; // the number of new posts loaded in this update - $(data).find('div.post.reply').each(function() { - var id = $(this).attr('id'); - if($('#' + id).length == 0) { - if (!new_posts) { - first_new_post = this; - } - $(this).insertAfter($('div.post:last').next()).after('
'); - new_posts++; - loaded_posts++; - $(document).trigger('new_post', this); - recheck_activated(); - } - }); - time_loaded = Date.now(); // interop with watch.js - - - if ($('#auto_update_status').is(':checked')) { - // If there are no new posts, double the delay. Otherwise set it to the min. - if(loaded_posts == 0) { - // if the update was manual, don't increase the delay - if (manualUpdate == false) { - poll_interval_delay *= 2; - - // Don't increase the delay beyond the maximum - if(poll_interval_delay > poll_interval_maxdelay) { - poll_interval_delay = poll_interval_maxdelay; - } - } - } else { - poll_interval_delay = poll_interval_mindelay; - } - - auto_update(poll_interval_delay); - } else { - // Decide the message to show if auto update is disabled - if (loaded_posts > 0) - $('#update_secs').text(fmt(_("Thread updated with {0} new post(s)"), [loaded_posts])); - 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); - } + } + + var poll = function(manualUpdate) { + stop_auto_update(); + $('#update_secs').text(_("Updating...")); + + $.ajax({ + url: document.location, + success: function(data) { + var loaded_posts = 0; // the number of new posts loaded in this update + $(data).find('div.postcontainer').each(function() { + var id = $(this).attr('id').substring(2); + if($('#' + id).length == 0) { + if (!new_posts) { + first_new_post = this; + makeIcon(); } + $(this).insertAfter($('div.postcontainer:last').next()).after('
'); + new_posts++; + loaded_posts++; + $(document).trigger('new_post', this); + recheck_activated(); + } }); - - return false; - }; - - $(window).scroll(function() { - recheck_activated(); - - // if the newest post is not visible - if($(this).scrollTop() + $(this).height() < - $('div.post:last').position().top + $('div.post:last').height()) { - end_of_page = false; + time_loaded = Date.now(); // interop with watch.js + + + if ($('#auto_update_status').is(':checked')) { + // If there are no new posts, double the delay. Otherwise set it to the min. + if(loaded_posts == 0) { + // if the update was manual, don't increase the delay + if (manualUpdate == false) { + poll_interval_delay *= 2; + + // Don't increase the delay beyond the maximum + if(poll_interval_delay > poll_interval_maxdelay) { + poll_interval_delay = poll_interval_maxdelay; + } + } + } else { + poll_interval_delay = poll_interval_mindelay; + } + + auto_update(poll_interval_delay); + } else { + // Decide the message to show if auto update is disabled + if (loaded_posts > 0) + $('#update_secs').text(fmt(_("Thread updated with {0} new post(s)"), [loaded_posts])); + 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 { - if($("#auto_update_status").is(':checked') && timeDiff(poll_interval_mindelay)) { - poll(manualUpdate = true); - } - end_of_page = true; + $('#update_secs').text(_("Unknown error")); } - }); - $('#update_thread').on('click', function() { poll(manualUpdate = true); return false; }); + // Keep trying to update + if ($('#auto_update_status').is(':checked')) { + poll_interval_delay = poll_interval_errordelay; + auto_update(poll_interval_delay); + } + } + }); - if($("#auto_update_status").is(':checked')) { - auto_update(poll_interval_delay); + return false; + }; + + $(window).scroll(function() { + recheck_activated(); + + // if the newest post is not visible + if($(this).scrollTop() + $(this).height() < + $('div.post:last').position().top + $('div.post:last').height()) { + end_of_page = false; + return; + } else { + if($("#auto_update_status").is(':checked') && timeDiff(poll_interval_mindelay)) { + poll(manualUpdate = true); + } + end_of_page = true; } -}); + }); + + $('#update_thread').on('click', function() { poll(manualUpdate = true); return false; }); + if($("#auto_update_status").is(':checked')) { + auto_update(poll_interval_delay); + } +}); -- cgit v1.3