From 38b71787afc1853a1c8d0db61096bf05ec34e892 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 16 Apr 2011 20:01:17 -0700 Subject: [PATCH] imgPreloading --- 4chan_x.js | 33 +++++++++++++++++++-------------- script.coffee | 14 +++++++++----- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/4chan_x.js b/4chan_x.js index c3d01629c..9f7acd5ff 100644 --- a/4chan_x.js +++ b/4chan_x.js @@ -59,7 +59,7 @@ */ (function() { - var $, $$, NAMESPACE, anonymize, autoWatch, callback, config, d, delform, el, expand, expandComment, expandThread, g, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageType, imageTypeChange, keybinds, localize, log, nav, navtopr, nodeInserted, option, options, pathname, qr, quickReport, recaptcha, recaptchaListener, recaptchaReload, redirect, replyHiding, sauce, scroll, temp, threadHiding, titlePost, tzOffset, ui, updateFavicon, updateTitle, updater, watcher, _config, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4; + var $, $$, NAMESPACE, anonymize, autoWatch, callback, config, d, delform, el, expand, expandComment, expandThread, g, imageClick, imageExpand, imageExpandClick, imageHover, imageResize, imageThumb, imageToggle, imageType, imageTypeChange, imgPreloading, keybinds, localize, log, nav, navtopr, nodeInserted, option, options, pathname, qr, quickReport, recaptcha, recaptchaListener, recaptchaReload, redirect, replyHiding, sauce, scroll, temp, threadHiding, titlePost, tzOffset, ui, updateFavicon, updateTitle, updater, watcher, _config, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4; var __slice = Array.prototype.slice; if (typeof console != "undefined" && console !== null) { log = console.log; @@ -1654,6 +1654,23 @@ return d.title = "/" + g.BOARD + "/ - " + el.textContent; } }; + imgPreloading = { + init: function() { + return g.callbacks.push(function(root) { + var el, parent, thumb, thumbs, _i, _len, _results; + thumbs = $$('img[md5]', root); + _results = []; + for (_i = 0, _len = thumbs.length; _i < _len; _i++) { + thumb = thumbs[_i]; + parent = thumb.parentNode; + _results.push(el = $.el('img', { + src: parent.href + })); + } + return _results; + }); + } + }; imageClick = function(e) { if (e.shiftKey || e.altKey || e.ctrlKey) { return; @@ -2137,19 +2154,7 @@ updater.init(); } if ($.config('Image Preloading')) { - g.callbacks.push(function(root) { - var parent, thumb, thumbs, _i, _len, _results; - thumbs = $$('img[md5]', root); - _results = []; - for (_i = 0, _len = thumbs.length; _i < _len; _i++) { - thumb = thumbs[_i]; - parent = thumb.parentNode; - _results.push(el = $.el('img', { - src: parent.href - })); - } - return _results; - }); + imgPreloading.init(); } if ($.config('Quick Reply') && $.config('Persistent QR')) { qr.persist(); diff --git a/script.coffee b/script.coffee index 27ecc2820..a55f5f588 100644 --- a/script.coffee +++ b/script.coffee @@ -1295,6 +1295,14 @@ titlePost = el = $('span.filetitle') or $('blockquote') d.title = "/#{g.BOARD}/ - #{el.textContent}" +imgPreloading = + init: -> + g.callbacks.push (root) -> + thumbs = $$ 'img[md5]', root + for thumb in thumbs + parent = thumb.parentNode + el = $.el 'img', src: parent.href + # TODO rewrite these ************************************************************************** imageClick = (e) -> @@ -1690,11 +1698,7 @@ if g.REPLY updater.init() if $.config 'Image Preloading' - g.callbacks.push (root) -> - thumbs = $$ 'img[md5]', root - for thumb in thumbs - parent = thumb.parentNode - el = $.el 'img', src: parent.href + imgPreloading.init() if $.config('Quick Reply') and $.config 'Persistent QR' qr.persist() if $.config 'Post in Title'