diff --git a/LICENSE b/LICENSE index f8b9c7b4d..9db28436d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.2.8 - 2013-05-24 +* 4chan X - Version 1.2.8 - 2013-05-25 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.js b/builds/4chan-X.js index 7be0cdedc..deb726751 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -19,7 +19,7 @@ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // ==/UserScript== /* -* 4chan X - Version 1.2.8 - 2013-05-24 +* 4chan X - Version 1.2.8 - 2013-05-25 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -109,7 +109,7 @@ * */ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageLoader, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __slice = [].slice, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -162,6 +162,7 @@ 'Replace GIF': [false, 'Replace thumbnail of gifs with its actual image.'], 'Replace PNG': [false, 'Replace pngs.'], 'Replace JPG': [false, 'Replace jpgs.'], + 'Image Prefetching': [false, 'Preload images'], 'Fappe Tyme': [false, 'Hide posts without images. *hint* *hint*'] }, 'Menu': { @@ -258,7 +259,7 @@ }, time: '%m/%d/%y(%a)%H:%M:%S', backlink: '>>%id', - fileInfo: '%L (%p%s, %r)', + fileInfo: '%l (%p%s, %r)', favicon: 'ferongr', usercss: '', hotkeys: { @@ -6188,7 +6189,7 @@ } }, toggle: function(post) { - var headRect, rect, root, thumb, top; + var headRect, node, rect, root, thumb, top; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6196,7 +6197,21 @@ return; } ImageExpand.contract(post); - rect = Conf['Advance on contract'] && !($.hasClass(doc, 'fappeTyme')) ? post.nodes.root.nextSibling.getBoundingClientRect() : post.nodes.root.getBoundingClientRect(); + node = post.nodes.root; + rect = Conf['Advance on contract'] ? (function() { + while (node.nextElementSibling) { + if (!(node = node.nextElementSibling)) { + return post.nodes.root; + } + if (!$.hasClass(node, 'postContainer')) { + continue; + } + if (node.offsetHeight > 0 && !$('.stub', node)) { + break; + } + } + return node.getBoundingClientRect(); + })() : post.nodes.root.getBoundingClientRect(); if (!(rect.top <= 0 || rect.left <= 0)) { return; } @@ -6466,24 +6481,42 @@ } }; - ImageReplace = { + ImageLoader = { init: function() { + var prefetch; + if (g.VIEW === 'catalog') { return; } - return Post.prototype.callbacks.push({ + if (!(Conf["Image Prefetching"] || Conf["Replace JPG"] || Conf["Replace PNG"] || Conf["Replace GIF"])) { + return; + } + Post.prototype.callbacks.push({ name: 'Image Replace', cb: this.node }); + if (!(Conf['Image Prefetching'] && g.VIEW === 'thread')) { + return; + } + prefetch = $.el('label', { + innerHTML: ' Prefetch Images' + }); + this.el = prefetch.firstElementChild; + $.on(this.el, 'change', this.toggle); + return $.event('AddMenuEntry', { + type: 'header', + el: prefetch, + order: 120 + }); }, node: function() { - var URL, img, style, thumb, type, _ref, _ref1; + var URL, img, string, style, thumb, type, _ref, _ref1; if (this.isClone || this.isHidden || this.thread.isHidden || !((_ref = this.file) != null ? _ref.isImage : void 0)) { return; } _ref1 = this.file, thumb = _ref1.thumb, URL = _ref1.URL; - if (!(Conf["Replace " + ((type = (URL.match(/\w{3}$/))[0].toUpperCase()) === 'PEG' ? 'JPG' : type)] && !/spoiler/.test(thumb.src))) { + if (!((Conf[string = "Replace " + ((type = (URL.match(/\w{3}$/))[0].toUpperCase()) === 'PEG' ? 'JPG' : type)] && !/spoiler/.test(thumb.src)) || Conf['prefetch'])) { return; } if (this.file.isSpoiler) { @@ -6491,10 +6524,24 @@ style.maxHeight = style.maxWidth = this.isReply ? '125px' : '250px'; } img = $.el('img'); - $.on(img, 'load', function() { - return thumb.src = URL; - }); + if (Conf[string]) { + $.on(img, 'load', function() { + return thumb.src = URL; + }); + } return img.src = URL; + }, + toggle: function() { + var enabled, id, post, _ref; + + enabled = Conf['prefetch'] = this.checked; + if (enabled) { + _ref = g.threads["" + g.BOARD.ID + "." + g.THREADID].posts; + for (id in _ref) { + post = _ref[id]; + ImageLoader.node.call(post); + } + } } }; @@ -10069,11 +10116,10 @@ } Conf['selectedArchives'] = {}; $.get(Conf, Main.initFeatures); - $.on(d, '4chanMainInit', Main.initStyle); return $.asap((function() { var _ref; - return d.head && $('link[rel="shortcut icon"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); + return d.head && $('link[rel="canonical"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); }), Main.initStyle); }, initFeatures: function(items) { @@ -10180,7 +10226,7 @@ 'Image Expansion': ImageExpand, 'Image Expansion (Menu)': ImageExpand.menu, 'Reveal Spoilers': RevealSpoilers, - 'Image Replace': ImageReplace, + 'Image Loading': ImageLoader, 'Image Hover': ImageHover, 'Comment Expansion': ExpandComment, 'Thread Expansion': ExpandThread, diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 1e2c35e3f..53648dba7 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -19,7 +19,7 @@ // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // ==/UserScript== /* -* 4chan X - Version 1.2.8 - 2013-05-24 +* 4chan X - Version 1.2.8 - 2013-05-25 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -109,7 +109,7 @@ * */ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageLoader, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __slice = [].slice, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -162,6 +162,7 @@ 'Replace GIF': [false, 'Replace thumbnail of gifs with its actual image.'], 'Replace PNG': [false, 'Replace pngs.'], 'Replace JPG': [false, 'Replace jpgs.'], + 'Image Prefetching': [false, 'Preload images'], 'Fappe Tyme': [false, 'Hide posts without images. *hint* *hint*'] }, 'Menu': { @@ -259,7 +260,7 @@ }, time: '%m/%d/%y(%a)%H:%M:%S', backlink: '>>%id', - fileInfo: '%L (%p%s, %r)', + fileInfo: '%l (%p%s, %r)', favicon: 'ferongr', usercss: '', hotkeys: { @@ -6197,7 +6198,7 @@ } }, toggle: function(post) { - var headRect, rect, root, thumb, top; + var headRect, node, rect, root, thumb, top; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6205,7 +6206,21 @@ return; } ImageExpand.contract(post); - rect = Conf['Advance on contract'] && !($.hasClass(doc, 'fappeTyme')) ? post.nodes.root.nextSibling.getBoundingClientRect() : post.nodes.root.getBoundingClientRect(); + node = post.nodes.root; + rect = Conf['Advance on contract'] ? (function() { + while (node.nextElementSibling) { + if (!(node = node.nextElementSibling)) { + return post.nodes.root; + } + if (!$.hasClass(node, 'postContainer')) { + continue; + } + if (node.offsetHeight > 0 && !$('.stub', node)) { + break; + } + } + return node.getBoundingClientRect(); + })() : post.nodes.root.getBoundingClientRect(); if (!(rect.top <= 0 || rect.left <= 0)) { return; } @@ -6475,24 +6490,42 @@ } }; - ImageReplace = { + ImageLoader = { init: function() { + var prefetch; + if (g.VIEW === 'catalog') { return; } - return Post.prototype.callbacks.push({ + if (!(Conf["Image Prefetching"] || Conf["Replace JPG"] || Conf["Replace PNG"] || Conf["Replace GIF"])) { + return; + } + Post.prototype.callbacks.push({ name: 'Image Replace', cb: this.node }); + if (!(Conf['Image Prefetching'] && g.VIEW === 'thread')) { + return; + } + prefetch = $.el('label', { + innerHTML: ' Prefetch Images' + }); + this.el = prefetch.firstElementChild; + $.on(this.el, 'change', this.toggle); + return $.event('AddMenuEntry', { + type: 'header', + el: prefetch, + order: 120 + }); }, node: function() { - var URL, img, style, thumb, type, _ref, _ref1; + var URL, img, string, style, thumb, type, _ref, _ref1; if (this.isClone || this.isHidden || this.thread.isHidden || !((_ref = this.file) != null ? _ref.isImage : void 0)) { return; } _ref1 = this.file, thumb = _ref1.thumb, URL = _ref1.URL; - if (!(Conf["Replace " + ((type = (URL.match(/\w{3}$/))[0].toUpperCase()) === 'PEG' ? 'JPG' : type)] && !/spoiler/.test(thumb.src))) { + if (!((Conf[string = "Replace " + ((type = (URL.match(/\w{3}$/))[0].toUpperCase()) === 'PEG' ? 'JPG' : type)] && !/spoiler/.test(thumb.src)) || Conf['prefetch'])) { return; } if (this.file.isSpoiler) { @@ -6500,10 +6533,24 @@ style.maxHeight = style.maxWidth = this.isReply ? '125px' : '250px'; } img = $.el('img'); - $.on(img, 'load', function() { - return thumb.src = URL; - }); + if (Conf[string]) { + $.on(img, 'load', function() { + return thumb.src = URL; + }); + } return img.src = URL; + }, + toggle: function() { + var enabled, id, post, _ref; + + enabled = Conf['prefetch'] = this.checked; + if (enabled) { + _ref = g.threads["" + g.BOARD.ID + "." + g.THREADID].posts; + for (id in _ref) { + post = _ref[id]; + ImageLoader.node.call(post); + } + } } }; @@ -10080,11 +10127,10 @@ } Conf['selectedArchives'] = {}; $.get(Conf, Main.initFeatures); - $.on(d, '4chanMainInit', Main.initStyle); return $.asap((function() { var _ref; - return d.head && $('link[rel="shortcut icon"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); + return d.head && $('link[rel="canonical"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); }), Main.initStyle); }, initFeatures: function(items) { @@ -10191,7 +10237,7 @@ 'Image Expansion': ImageExpand, 'Image Expansion (Menu)': ImageExpand.menu, 'Reveal Spoilers': RevealSpoilers, - 'Image Replace': ImageReplace, + 'Image Loading': ImageLoader, 'Image Hover': ImageHover, 'Comment Expansion': ExpandComment, 'Thread Expansion': ExpandThread, diff --git a/builds/crx/script.js b/builds/crx/script.js index e35fcfc2f..c6ea3132e 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.2.8 - 2013-05-24 +* 4chan X - Version 1.2.8 - 2013-05-25 * * Licensed under the MIT license. * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE @@ -90,7 +90,7 @@ * */ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageLoader, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __slice = [].slice, __hasProp = {}.hasOwnProperty, @@ -143,6 +143,7 @@ 'Replace GIF': [false, 'Replace thumbnail of gifs with its actual image.'], 'Replace PNG': [false, 'Replace pngs.'], 'Replace JPG': [false, 'Replace jpgs.'], + 'Image Prefetching': [false, 'Preload images'], 'Fappe Tyme': [false, 'Hide posts without images. *hint* *hint*'] }, 'Menu': { @@ -240,7 +241,7 @@ }, time: '%m/%d/%y(%a)%H:%M:%S', backlink: '>>%id', - fileInfo: '%L (%p%s, %r)', + fileInfo: '%l (%p%s, %r)', favicon: 'ferongr', usercss: '', hotkeys: { @@ -6175,7 +6176,7 @@ } }, toggle: function(post) { - var headRect, rect, root, thumb, top; + var headRect, node, rect, root, thumb, top; thumb = post.file.thumb; if (!(post.file.isExpanded || $.hasClass(thumb, 'expanding'))) { @@ -6183,7 +6184,21 @@ return; } ImageExpand.contract(post); - rect = Conf['Advance on contract'] && !($.hasClass(doc, 'fappeTyme')) ? post.nodes.root.nextSibling.getBoundingClientRect() : post.nodes.root.getBoundingClientRect(); + node = post.nodes.root; + rect = Conf['Advance on contract'] ? (function() { + while (node.nextElementSibling) { + if (!(node = node.nextElementSibling)) { + return post.nodes.root; + } + if (!$.hasClass(node, 'postContainer')) { + continue; + } + if (node.offsetHeight > 0 && !$('.stub', node)) { + break; + } + } + return node.getBoundingClientRect(); + })() : post.nodes.root.getBoundingClientRect(); if (!(rect.top <= 0 || rect.left <= 0)) { return; } @@ -6453,24 +6468,42 @@ } }; - ImageReplace = { + ImageLoader = { init: function() { + var prefetch; + if (g.VIEW === 'catalog') { return; } - return Post.prototype.callbacks.push({ + if (!(Conf["Image Prefetching"] || Conf["Replace JPG"] || Conf["Replace PNG"] || Conf["Replace GIF"])) { + return; + } + Post.prototype.callbacks.push({ name: 'Image Replace', cb: this.node }); + if (!(Conf['Image Prefetching'] && g.VIEW === 'thread')) { + return; + } + prefetch = $.el('label', { + innerHTML: ' Prefetch Images' + }); + this.el = prefetch.firstElementChild; + $.on(this.el, 'change', this.toggle); + return $.event('AddMenuEntry', { + type: 'header', + el: prefetch, + order: 120 + }); }, node: function() { - var URL, img, style, thumb, type, _ref, _ref1; + var URL, img, string, style, thumb, type, _ref, _ref1; if (this.isClone || this.isHidden || this.thread.isHidden || !((_ref = this.file) != null ? _ref.isImage : void 0)) { return; } _ref1 = this.file, thumb = _ref1.thumb, URL = _ref1.URL; - if (!(Conf["Replace " + ((type = (URL.match(/\w{3}$/))[0].toUpperCase()) === 'PEG' ? 'JPG' : type)] && !/spoiler/.test(thumb.src))) { + if (!((Conf[string = "Replace " + ((type = (URL.match(/\w{3}$/))[0].toUpperCase()) === 'PEG' ? 'JPG' : type)] && !/spoiler/.test(thumb.src)) || Conf['prefetch'])) { return; } if (this.file.isSpoiler) { @@ -6478,10 +6511,24 @@ style.maxHeight = style.maxWidth = this.isReply ? '125px' : '250px'; } img = $.el('img'); - $.on(img, 'load', function() { - return thumb.src = URL; - }); + if (Conf[string]) { + $.on(img, 'load', function() { + return thumb.src = URL; + }); + } return img.src = URL; + }, + toggle: function() { + var enabled, id, post, _ref; + + enabled = Conf['prefetch'] = this.checked; + if (enabled) { + _ref = g.threads["" + g.BOARD.ID + "." + g.THREADID].posts; + for (id in _ref) { + post = _ref[id]; + ImageLoader.node.call(post); + } + } } }; @@ -10061,11 +10108,10 @@ } Conf['selectedArchives'] = {}; $.get(Conf, Main.initFeatures); - $.on(d, '4chanMainInit', Main.initStyle); return $.asap((function() { var _ref; - return d.head && $('link[rel="shortcut icon"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); + return d.head && $('link[rel="canonical"]', d.head) || ((_ref = d.readyState) === 'interactive' || _ref === 'complete'); }), Main.initStyle); }, initFeatures: function(items) { @@ -10172,7 +10218,7 @@ 'Image Expansion': ImageExpand, 'Image Expansion (Menu)': ImageExpand.menu, 'Reveal Spoilers': RevealSpoilers, - 'Image Replace': ImageReplace, + 'Image Loading': ImageLoader, 'Image Hover': ImageHover, 'Comment Expansion': ExpandComment, 'Thread Expansion': ExpandThread, diff --git a/src/General/Config.coffee b/src/General/Config.coffee index da1726add..173038f73 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -155,6 +155,10 @@ Config = false 'Replace jpgs.' ] + 'Image Prefetching': [ + false + 'Preload images' + ] 'Fappe Tyme': [ false 'Hide posts without images. *hint* *hint*' @@ -475,7 +479,7 @@ http://iqdb.org/?url=%TURL backlink: '>>%id' - fileInfo: '%L (%p%s, %r)' + fileInfo: '%l (%p%s, %r)' favicon: 'ferongr' diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 3776a0add..76150ac8e 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -18,8 +18,7 @@ Main = $.get Conf, Main.initFeatures - $.on d, '4chanMainInit', Main.initStyle - $.asap (-> d.head and $('link[rel="shortcut icon"]', d.head) or d.readyState in ['interactive', 'complete']), + $.asap (-> d.head and $('link[rel="canonical"]', d.head) or d.readyState in ['interactive', 'complete']), Main.initStyle initFeatures: (items) -> @@ -113,7 +112,7 @@ Main = 'Image Expansion': ImageExpand 'Image Expansion (Menu)': ImageExpand.menu 'Reveal Spoilers': RevealSpoilers - 'Image Replace': ImageReplace + 'Image Loading': ImageLoader 'Image Hover': ImageHover 'Comment Expansion': ExpandComment 'Thread Expansion': ExpandThread diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index c711a7627..7fef8b63e 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -68,8 +68,14 @@ ImageExpand = ImageExpand.expand post return ImageExpand.contract post - rect = if Conf['Advance on contract'] and !($.hasClass doc, 'fappeTyme') - post.nodes.root.nextSibling.getBoundingClientRect() + node = post.nodes.root + rect = if Conf['Advance on contract'] then do -> + # FIXME does not work with Quote Threading + while node.nextElementSibling + return post.nodes.root unless node = node.nextElementSibling + continue unless $.hasClass node, 'postContainer' + break if node.offsetHeight > 0 and not $ '.stub', node + node.getBoundingClientRect() else post.nodes.root.getBoundingClientRect() return unless rect.top <= 0 or rect.left <= 0 diff --git a/src/Images/ImageLoader.coffee b/src/Images/ImageLoader.coffee new file mode 100644 index 000000000..4146116b5 --- /dev/null +++ b/src/Images/ImageLoader.coffee @@ -0,0 +1,42 @@ +ImageLoader = + init: -> + return if g.VIEW is 'catalog' + return unless Conf["Image Prefetching"] or Conf["Replace JPG"] or Conf["Replace PNG"] or Conf["Replace GIF"] + + Post::callbacks.push + name: 'Image Replace' + cb: @node + + return unless Conf['Image Prefetching'] and g.VIEW is 'thread' + + prefetch = $.el 'label', + innerHTML: ' Prefetch Images' + + @el = prefetch.firstElementChild + $.on @el, 'change', @toggle + + $.event 'AddMenuEntry', + type: 'header' + el: prefetch + order: 120 + + node: -> + return if @isClone or @isHidden or @thread.isHidden or !@file?.isImage + {thumb, URL} = @file + return unless (Conf[string = "Replace #{if (type = (URL.match /\w{3}$/)[0].toUpperCase()) is 'PEG' then 'JPG' else type}"] and !/spoiler/.test thumb.src) or Conf['prefetch'] + if @file.isSpoiler + # Revealed spoilers do not have height/width set, this fixes the image's dimensions. + {style} = thumb + style.maxHeight = style.maxWidth = if @isReply then '125px' else '250px' + img = $.el 'img' + if Conf[string] + $.on img, 'load', -> + # Replace the thumbnail once the GIF has finished loading. + thumb.src = URL + img.src = URL + + toggle: -> + enabled = Conf['prefetch'] = @checked + if enabled + ImageLoader.node.call post for id, post of g.threads["#{g.BOARD.ID}.#{g.THREADID}"].posts + return \ No newline at end of file diff --git a/src/Images/ImageReplace.coffee b/src/Images/ImageReplace.coffee deleted file mode 100644 index ffd53b88e..000000000 --- a/src/Images/ImageReplace.coffee +++ /dev/null @@ -1,21 +0,0 @@ -ImageReplace = - init: -> - return if g.VIEW is 'catalog' - - Post::callbacks.push - name: 'Image Replace' - cb: @node - - node: -> - return if @isClone or @isHidden or @thread.isHidden or !@file?.isImage - {thumb, URL} = @file - return unless Conf["Replace #{if (type = (URL.match /\w{3}$/)[0].toUpperCase()) is 'PEG' then 'JPG' else type}"] and !/spoiler/.test thumb.src - if @file.isSpoiler - # Revealed spoilers do not have height/width set, this fixes auto-gifs dimensions. - {style} = thumb - style.maxHeight = style.maxWidth = if @isReply then '125px' else '250px' - img = $.el 'img' - $.on img, 'load', -> - # Replace the thumbnail once the GIF has finished loading. - thumb.src = URL - img.src = URL \ No newline at end of file