diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e73fee14..43b8ae2bc 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ The links to individual versions below are to copies of the script with the upda ### v1.10.14 +**v1.10.14.4** *(2015-06-19)* - [[Firefox](https://raw.githubusercontent.com/ccd0/4chan-x/1.10.14.4/builds/4chan-X-noupdate.user.js "Firefox version")] [[Chromium](https://raw.githubusercontent.com/ccd0/4chan-x/1.10.14.4/builds/4chan-X-noupdate.crx "Chromium version")] +- Update script for new non-Javascript captcha using image selection. + **v1.10.14.3** *(2015-06-16)* - [[Firefox](https://raw.githubusercontent.com/ccd0/4chan-x/1.10.14.3/builds/4chan-X-noupdate.user.js "Firefox version")] [[Chromium](https://raw.githubusercontent.com/ccd0/4chan-x/1.10.14.3/builds/4chan-X-noupdate.crx "Chromium version")] - Fix words being cut off in non-Javascript captcha. diff --git a/builds/4chan-X-beta.crx b/builds/4chan-X-beta.crx index 0f9fca457..f10c79c62 100644 Binary files a/builds/4chan-X-beta.crx and b/builds/4chan-X-beta.crx differ diff --git a/builds/4chan-X-beta.meta.js b/builds/4chan-X-beta.meta.js index b4929b815..5cfe335a3 100644 --- a/builds/4chan-X-beta.meta.js +++ b/builds/4chan-X-beta.meta.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X beta -// @version 1.10.14.3 +// @version 1.10.14.4 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X diff --git a/builds/4chan-X-beta.user.js b/builds/4chan-X-beta.user.js index 3e507c78b..84929454a 100644 --- a/builds/4chan-X-beta.user.js +++ b/builds/4chan-X-beta.user.js @@ -1,7 +1,7 @@ // Generated by CoffeeScript // ==UserScript== // @name 4chan X beta -// @version 1.10.14.3 +// @version 1.10.14.4 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -398,7 +398,7 @@ doc = d.documentElement; g = { - VERSION: '1.10.14.3', + VERSION: '1.10.14.4', NAMESPACE: '4chan X.', boards: {} }; @@ -6708,7 +6708,7 @@ QR = { mimeTypes: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/vnd.adobe.flash.movie', 'application/x-shockwave-flash', 'video/webm'], init: function() { - var noscript, sc; + var sc; if (!Conf['Quick Reply']) { return; } @@ -6717,8 +6717,7 @@ if (g.VIEW === 'archive') { return; } - noscript = Conf['Force Noscript Captcha'] || !$.hasClass(doc, 'js-enabled'); - this.captcha = Captcha[noscript ? 'noscript' : 'v2']; + this.captcha = Captcha.v2; $.on(d, '4chanXInitFinished', this.initReady); Post.callbacks.push({ name: 'Quick Reply', @@ -7763,55 +7762,6 @@ }; Captcha.noscript = { - lifetime: 2 * $.MINUTE, - iframeURL: '//www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc', - init: function() { - var container, input; - if (d.cookie.indexOf('pass_enabled=1') >= 0) { - return; - } - if (!(this.isEnabled = !!$.id('g-recaptcha'))) { - return; - } - container = $.el('div', { - className: 'captcha-img', - title: 'Reload reCAPTCHA' - }); - input = $.el('input', { - className: 'captcha-input field', - title: 'Verification', - autocomplete: 'off', - spellcheck: false - }); - this.nodes = { - container: container, - input: input - }; - $.on(input, 'keydown', this.keydown.bind(this)); - $.on(this.nodes.container, 'click', (function(_this) { - return function() { - _this.reload(); - return _this.nodes.input.focus(); - }; - })(this)); - this.conn = new Connection(null, location.protocol + "//www.google.com", { - challenge: this.load.bind(this), - token: this.save.bind(this), - error: this.error.bind(this) - }); - $.addClass(QR.nodes.el, 'has-captcha'); - $.after(QR.nodes.com.parentNode, [container, input]); - this.captchas = []; - $.get('captchas', [], function(arg) { - var captchas; - captchas = arg.captchas; - QR.captcha.sync(captchas); - return QR.captcha.clear(); - }); - $.sync('captchas', this.sync); - this.beforeSetup(); - return this.setup(); - }, initFrame: function() { var cb, conn, img, ref, ref1; conn = new Connection(window.parent, location.protocol + "//boards.4chan.org", { @@ -7842,247 +7792,12 @@ } else { return $.on(img, 'load', cb); } - }, - timers: {}, - cb: { - focus: function() { - return QR.captcha.setup(false, true); - } - }, - beforeSetup: function() { - var container, input, ref; - ref = this.nodes, container = ref.container, input = ref.input; - container.hidden = true; - input.value = ''; - input.placeholder = 'Focus to load reCAPTCHA'; - this.count(); - return $.on(input, 'focus click', this.cb.focus); - }, - needed: function() { - var captchaCount, postsCount; - captchaCount = this.captchas.length; - if (QR.req) { - captchaCount++; - } - postsCount = QR.posts.length; - if (postsCount === 1 && !Conf['Auto-load captcha'] && !QR.posts[0].com && !QR.posts[0].file) { - postsCount = 0; - } - return captchaCount < postsCount; - }, - onNewPost: function() {}, - onPostChange: function() {}, - setup: function(focus, force) { - if (!(this.isEnabled && (this.needed() || force))) { - return; - } - if (!this.nodes.iframe) { - this.nodes.iframe = $.el('iframe', { - id: 'qr-captcha-iframe', - src: this.iframeURL - }); - $.add(d.body, this.nodes.iframe); - this.conn.target = this.nodes.iframe.contentWindow; - } else if (!this.occupied || force) { - this.nodes.iframe.src = this.iframeURL; - } - this.occupied = true; - if (focus) { - return this.nodes.input.focus(); - } - }, - afterSetup: function() { - var container, input, ref; - ref = this.nodes, container = ref.container, input = ref.input; - container.hidden = false; - input.placeholder = 'Verification'; - this.count(); - $.off(input, 'focus click', this.cb.focus); - if (QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight) { - QR.nodes.el.style.top = ''; - return QR.nodes.el.style.bottom = '0px'; - } - }, - destroy: function() { - if (!this.isEnabled) { - return; - } - if (this.nodes.img) { - $.rm(this.nodes.img); - } - delete this.nodes.img; - if (this.nodes.iframe) { - $.rm(this.nodes.iframe); - } - delete this.nodes.iframe; - delete this.occupied; - return this.beforeSetup(); - }, - sync: function(captchas) { - if (captchas == null) { - captchas = []; - } - QR.captcha.captchas = captchas; - return QR.captcha.count(); - }, - getOne: function() { - var captcha; - this.clear(); - if (captcha = this.captchas.shift()) { - this.count(); - $.set('captchas', this.captchas); - return captcha.response; - } else if (/\S/.test(this.nodes.input.value)) { - return (function(_this) { - return function(cb) { - _this.submitCB = cb; - return _this.sendResponse(); - }; - })(this); - } else { - return null; - } - }, - sendResponse: function() { - var response; - response = this.nodes.input.value; - if (/\S/.test(response)) { - return this.conn.send({ - response: response - }); - } - }, - save: function(token) { - delete this.occupied; - this.nodes.input.value = ''; - if (this.submitCB) { - this.submitCB(token); - delete this.submitCB; - if (this.needed()) { - return this.reload(); - } else { - return this.destroy(); - } - } else { - $.forceSync('captchas'); - this.captchas.push({ - response: token, - timeout: this.timeout - }); - this.count(); - $.set('captchas', this.captchas); - return this.reload(); - } - }, - error: function(message) { - this.occupied = true; - this.nodes.input.value = ''; - if (this.submitCB) { - this.submitCB(); - delete this.submitCB; - } - return QR.error("Captcha Error: " + message); - }, - clear: function() { - var captcha, i, k, len1, now, ref; - if (!this.captchas.length) { - return; - } - $.forceSync('captchas'); - now = Date.now(); - ref = this.captchas; - for (i = k = 0, len1 = ref.length; k < len1; i = ++k) { - captcha = ref[i]; - if (captcha.timeout > now) { - break; - } - } - if (!i) { - return; - } - this.captchas = this.captchas.slice(i); - this.count(); - return $.set('captchas', this.captchas); - }, - load: function(src) { - var container, img, input, ref; - ref = this.nodes, container = ref.container, input = ref.input, img = ref.img; - this.occupied = true; - this.timeout = Date.now() + this.lifetime; - if (!img) { - img = this.nodes.img = new Image(); - $.one(img, 'load', this.afterSetup.bind(this)); - $.on(img, 'load', function() { - return this.hidden = false; - }); - $.add(container, img); - } - img.src = src; - input.value = ''; - this.clear(); - clearTimeout(this.timers.expire); - return this.timers.expire = setTimeout(this.expire.bind(this), this.lifetime); - }, - count: function() { - var count, placeholder; - count = this.captchas ? this.captchas.length : 0; - placeholder = this.nodes.input.placeholder.replace(/\ \(.*\)$/, ''); - placeholder += (function() { - switch (count) { - case 0: - if (placeholder === 'Verification') { - return ' (Shift + Enter to cache)'; - } else { - return ''; - } - break; - case 1: - return ' (1 cached captcha)'; - default: - return " (" + count + " cached captchas)"; - } - })(); - this.nodes.input.placeholder = placeholder; - this.nodes.input.alt = count; - clearTimeout(this.timers.clear); - if (this.captchas.length) { - return this.timers.clear = setTimeout(this.clear.bind(this), this.captchas[0].timeout - Date.now()); - } - }, - expire: function() { - if (!this.nodes.iframe) { - return; - } - if (!d.hidden && (this.needed() || d.activeElement === this.nodes.input)) { - return this.reload(); - } else { - return this.destroy(); - } - }, - reload: function() { - var ref; - this.nodes.iframe.src = this.iframeURL; - this.occupied = true; - return (ref = this.nodes.img) != null ? ref.hidden = true : void 0; - }, - keydown: function(e) { - if (e.keyCode === 8 && !this.nodes.input.value) { - if (this.nodes.iframe) { - this.reload(); - } else { - this.setup(); - } - } else if (e.keyCode === 13 && e.shiftKey) { - this.sendResponse(); - } else { - return; - } - return e.preventDefault(); } }; Captcha.v2 = { lifetime: 2 * $.MINUTE, + noscriptURL: '//www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc', init: function() { var counter, root; if (d.cookie.indexOf('pass_enabled=1') >= 0) { @@ -8091,6 +7806,15 @@ if (!(this.isEnabled = !!$.id('g-recaptcha'))) { return; } + if (this.noscript = Conf['Force Noscript Captcha'] || !$.hasClass(doc, 'js-enabled')) { + this.conn = new Connection(null, location.protocol + "//www.google.com", { + token: (function(_this) { + return function(token) { + return _this.save(true, token); + }; + })(this) + }); + } this.captchas = []; $.get('captchas', [], function(arg) { var captchas; @@ -8183,6 +7907,22 @@ childList: true, subtree: true }); + if (this.noscript) { + return this.setupNoscript(); + } else { + return this.setupJS(); + } + }, + setupNoscript: function() { + var iframe; + iframe = $.el('iframe', { + id: 'qr-captcha-iframe', + src: this.noscriptURL + }); + $.add(this.nodes.container, iframe); + return this.conn.target = iframe.contentWindow; + }, + setupJS: function() { return $.globalEval('(function() {\n function render() {\n var container = document.querySelector("#qr .captcha-container");\n container.dataset.widgetID = window.grecaptcha.render(container, {\n sitekey: \'6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc\',\n theme: document.documentElement.classList.contains(\'tomorrow\') ? \'dark\' : \'light\',\n callback: function(response) {\n window.dispatchEvent(new CustomEvent("captcha:success", {detail: response}));\n }\n });\n }\n if (window.grecaptcha) {\n render();\n } else {\n var cbNative = window.onRecaptchaLoaded;\n window.onRecaptchaLoaded = function() {\n render();\n cbNative();\n }\n }\n})();'); }, afterSetup: function(mutations) { @@ -8259,12 +7999,12 @@ return null; } }, - save: function(pasted) { + save: function(pasted, token) { var base1, focus, ref, ref1; $.forceSync('captchas'); this.captchas.push({ - response: $('textarea', this.nodes.container).value, - timeout: (pasted ? this.setupTime : Date.now()) + this.lifetime + response: token || $('textarea', this.nodes.container).value, + timeout: Date.now() + this.lifetime }); $.set('captchas', this.captchas); this.count(); @@ -8324,7 +8064,11 @@ } }, reload: function() { - return $.globalEval('(function() {\n var container = document.querySelector("#qr .captcha-container");\n window.grecaptcha.reset(container.dataset.widgetID);\n})();'); + if (this.noscript) { + return $('iframe', this.nodes.container).src = this.noscriptURL; + } else { + return $.globalEval('(function() {\n var container = document.querySelector("#qr .captcha-container");\n window.grecaptcha.reset(container.dataset.widgetID);\n})();'); + } } }; @@ -15467,8 +15211,11 @@ }; Report = { - css: "noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + + css: "noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + "}\n" + ":root:not(.js-enabled) #g-recaptcha {\n" + " height: auto;\n" + @@ -17329,8 +17076,14 @@ " 0% {transform:rotate(0deg);}\n" + " 100% {transform:rotate(359deg);}\n" + "}\n" + -"noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + +"noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + +"}\n" + +":root:not(.js-enabled) #g-recaptcha {\n" + +" height: auto;\n" + "}\n" + "/* General */\n" + ".dialog {\n" + @@ -18530,23 +18283,7 @@ " position: relative;\n" + " top: 2px;\n" + "}\n" + -"/* Noscript Recaptcha */\n" + -".captcha-img {\n" + -" margin: 0px;\n" + -" text-align: center;\n" + -" background-image: #fff;\n" + -" font-size: 0px;\n" + -" min-height: 59px;\n" + -" min-width: 302px;\n" + -"}\n" + -".captcha-input{\n" + -" width: 100%;\n" + -" margin: 1px 0 0;\n" + -"}\n" + -"#qr-captcha-iframe {\n" + -" display: none;\n" + -"}\n" + -"/* Recaptcha v2 */\n" + +"/* Captcha */\n" + "#qr .captcha-root {\n" + " position: relative;\n" + "}\n" + @@ -18570,6 +18307,13 @@ " display: block;\n" + " width: 100%;\n" + "}\n" + +"#qr-captcha-iframe {\n" + +" width: 302px;\n" + +" height: 423px;\n" + +" max-width: 100vw;\n" + +" max-height: calc(100vh - 210px);\n" + +" overflow: auto;\n" + +"}\n" + ".goog-bubble-content {\n" + " max-width: 100vw;\n" + " max-height: 100vh;\n" + @@ -19728,8 +19472,14 @@ " font-family: sans-serif !important;\n" + " text-shadow: 1px 1px 1px rgba(0,74,153,0.6);\n" + "}", - cssWWW: "noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + + cssWWW: "noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + +"}\n" + +":root:not(.js-enabled) #g-recaptcha {\n" + +" height: auto;\n" + "}\n" + "#captcha-cnt {\n" + " height: auto;\n" + diff --git a/builds/4chan-X-noupdate.crx b/builds/4chan-X-noupdate.crx index 21cf6114b..47f309b44 100644 Binary files a/builds/4chan-X-noupdate.crx and b/builds/4chan-X-noupdate.crx differ diff --git a/builds/4chan-X-noupdate.user.js b/builds/4chan-X-noupdate.user.js index 0caa86ab9..77fba6432 100644 --- a/builds/4chan-X-noupdate.user.js +++ b/builds/4chan-X-noupdate.user.js @@ -1,7 +1,7 @@ // Generated by CoffeeScript // ==UserScript== // @name 4chan X -// @version 1.10.14.3 +// @version 1.10.14.4 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -397,7 +397,7 @@ doc = d.documentElement; g = { - VERSION: '1.10.14.3', + VERSION: '1.10.14.4', NAMESPACE: '4chan X.', boards: {} }; @@ -6707,7 +6707,7 @@ QR = { mimeTypes: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/vnd.adobe.flash.movie', 'application/x-shockwave-flash', 'video/webm'], init: function() { - var noscript, sc; + var sc; if (!Conf['Quick Reply']) { return; } @@ -6716,8 +6716,7 @@ if (g.VIEW === 'archive') { return; } - noscript = Conf['Force Noscript Captcha'] || !$.hasClass(doc, 'js-enabled'); - this.captcha = Captcha[noscript ? 'noscript' : 'v2']; + this.captcha = Captcha.v2; $.on(d, '4chanXInitFinished', this.initReady); Post.callbacks.push({ name: 'Quick Reply', @@ -7762,55 +7761,6 @@ }; Captcha.noscript = { - lifetime: 2 * $.MINUTE, - iframeURL: '//www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc', - init: function() { - var container, input; - if (d.cookie.indexOf('pass_enabled=1') >= 0) { - return; - } - if (!(this.isEnabled = !!$.id('g-recaptcha'))) { - return; - } - container = $.el('div', { - className: 'captcha-img', - title: 'Reload reCAPTCHA' - }); - input = $.el('input', { - className: 'captcha-input field', - title: 'Verification', - autocomplete: 'off', - spellcheck: false - }); - this.nodes = { - container: container, - input: input - }; - $.on(input, 'keydown', this.keydown.bind(this)); - $.on(this.nodes.container, 'click', (function(_this) { - return function() { - _this.reload(); - return _this.nodes.input.focus(); - }; - })(this)); - this.conn = new Connection(null, location.protocol + "//www.google.com", { - challenge: this.load.bind(this), - token: this.save.bind(this), - error: this.error.bind(this) - }); - $.addClass(QR.nodes.el, 'has-captcha'); - $.after(QR.nodes.com.parentNode, [container, input]); - this.captchas = []; - $.get('captchas', [], function(arg) { - var captchas; - captchas = arg.captchas; - QR.captcha.sync(captchas); - return QR.captcha.clear(); - }); - $.sync('captchas', this.sync); - this.beforeSetup(); - return this.setup(); - }, initFrame: function() { var cb, conn, img, ref, ref1; conn = new Connection(window.parent, location.protocol + "//boards.4chan.org", { @@ -7841,247 +7791,12 @@ } else { return $.on(img, 'load', cb); } - }, - timers: {}, - cb: { - focus: function() { - return QR.captcha.setup(false, true); - } - }, - beforeSetup: function() { - var container, input, ref; - ref = this.nodes, container = ref.container, input = ref.input; - container.hidden = true; - input.value = ''; - input.placeholder = 'Focus to load reCAPTCHA'; - this.count(); - return $.on(input, 'focus click', this.cb.focus); - }, - needed: function() { - var captchaCount, postsCount; - captchaCount = this.captchas.length; - if (QR.req) { - captchaCount++; - } - postsCount = QR.posts.length; - if (postsCount === 1 && !Conf['Auto-load captcha'] && !QR.posts[0].com && !QR.posts[0].file) { - postsCount = 0; - } - return captchaCount < postsCount; - }, - onNewPost: function() {}, - onPostChange: function() {}, - setup: function(focus, force) { - if (!(this.isEnabled && (this.needed() || force))) { - return; - } - if (!this.nodes.iframe) { - this.nodes.iframe = $.el('iframe', { - id: 'qr-captcha-iframe', - src: this.iframeURL - }); - $.add(d.body, this.nodes.iframe); - this.conn.target = this.nodes.iframe.contentWindow; - } else if (!this.occupied || force) { - this.nodes.iframe.src = this.iframeURL; - } - this.occupied = true; - if (focus) { - return this.nodes.input.focus(); - } - }, - afterSetup: function() { - var container, input, ref; - ref = this.nodes, container = ref.container, input = ref.input; - container.hidden = false; - input.placeholder = 'Verification'; - this.count(); - $.off(input, 'focus click', this.cb.focus); - if (QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight) { - QR.nodes.el.style.top = ''; - return QR.nodes.el.style.bottom = '0px'; - } - }, - destroy: function() { - if (!this.isEnabled) { - return; - } - if (this.nodes.img) { - $.rm(this.nodes.img); - } - delete this.nodes.img; - if (this.nodes.iframe) { - $.rm(this.nodes.iframe); - } - delete this.nodes.iframe; - delete this.occupied; - return this.beforeSetup(); - }, - sync: function(captchas) { - if (captchas == null) { - captchas = []; - } - QR.captcha.captchas = captchas; - return QR.captcha.count(); - }, - getOne: function() { - var captcha; - this.clear(); - if (captcha = this.captchas.shift()) { - this.count(); - $.set('captchas', this.captchas); - return captcha.response; - } else if (/\S/.test(this.nodes.input.value)) { - return (function(_this) { - return function(cb) { - _this.submitCB = cb; - return _this.sendResponse(); - }; - })(this); - } else { - return null; - } - }, - sendResponse: function() { - var response; - response = this.nodes.input.value; - if (/\S/.test(response)) { - return this.conn.send({ - response: response - }); - } - }, - save: function(token) { - delete this.occupied; - this.nodes.input.value = ''; - if (this.submitCB) { - this.submitCB(token); - delete this.submitCB; - if (this.needed()) { - return this.reload(); - } else { - return this.destroy(); - } - } else { - $.forceSync('captchas'); - this.captchas.push({ - response: token, - timeout: this.timeout - }); - this.count(); - $.set('captchas', this.captchas); - return this.reload(); - } - }, - error: function(message) { - this.occupied = true; - this.nodes.input.value = ''; - if (this.submitCB) { - this.submitCB(); - delete this.submitCB; - } - return QR.error("Captcha Error: " + message); - }, - clear: function() { - var captcha, i, k, len1, now, ref; - if (!this.captchas.length) { - return; - } - $.forceSync('captchas'); - now = Date.now(); - ref = this.captchas; - for (i = k = 0, len1 = ref.length; k < len1; i = ++k) { - captcha = ref[i]; - if (captcha.timeout > now) { - break; - } - } - if (!i) { - return; - } - this.captchas = this.captchas.slice(i); - this.count(); - return $.set('captchas', this.captchas); - }, - load: function(src) { - var container, img, input, ref; - ref = this.nodes, container = ref.container, input = ref.input, img = ref.img; - this.occupied = true; - this.timeout = Date.now() + this.lifetime; - if (!img) { - img = this.nodes.img = new Image(); - $.one(img, 'load', this.afterSetup.bind(this)); - $.on(img, 'load', function() { - return this.hidden = false; - }); - $.add(container, img); - } - img.src = src; - input.value = ''; - this.clear(); - clearTimeout(this.timers.expire); - return this.timers.expire = setTimeout(this.expire.bind(this), this.lifetime); - }, - count: function() { - var count, placeholder; - count = this.captchas ? this.captchas.length : 0; - placeholder = this.nodes.input.placeholder.replace(/\ \(.*\)$/, ''); - placeholder += (function() { - switch (count) { - case 0: - if (placeholder === 'Verification') { - return ' (Shift + Enter to cache)'; - } else { - return ''; - } - break; - case 1: - return ' (1 cached captcha)'; - default: - return " (" + count + " cached captchas)"; - } - })(); - this.nodes.input.placeholder = placeholder; - this.nodes.input.alt = count; - clearTimeout(this.timers.clear); - if (this.captchas.length) { - return this.timers.clear = setTimeout(this.clear.bind(this), this.captchas[0].timeout - Date.now()); - } - }, - expire: function() { - if (!this.nodes.iframe) { - return; - } - if (!d.hidden && (this.needed() || d.activeElement === this.nodes.input)) { - return this.reload(); - } else { - return this.destroy(); - } - }, - reload: function() { - var ref; - this.nodes.iframe.src = this.iframeURL; - this.occupied = true; - return (ref = this.nodes.img) != null ? ref.hidden = true : void 0; - }, - keydown: function(e) { - if (e.keyCode === 8 && !this.nodes.input.value) { - if (this.nodes.iframe) { - this.reload(); - } else { - this.setup(); - } - } else if (e.keyCode === 13 && e.shiftKey) { - this.sendResponse(); - } else { - return; - } - return e.preventDefault(); } }; Captcha.v2 = { lifetime: 2 * $.MINUTE, + noscriptURL: '//www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc', init: function() { var counter, root; if (d.cookie.indexOf('pass_enabled=1') >= 0) { @@ -8090,6 +7805,15 @@ if (!(this.isEnabled = !!$.id('g-recaptcha'))) { return; } + if (this.noscript = Conf['Force Noscript Captcha'] || !$.hasClass(doc, 'js-enabled')) { + this.conn = new Connection(null, location.protocol + "//www.google.com", { + token: (function(_this) { + return function(token) { + return _this.save(true, token); + }; + })(this) + }); + } this.captchas = []; $.get('captchas', [], function(arg) { var captchas; @@ -8182,6 +7906,22 @@ childList: true, subtree: true }); + if (this.noscript) { + return this.setupNoscript(); + } else { + return this.setupJS(); + } + }, + setupNoscript: function() { + var iframe; + iframe = $.el('iframe', { + id: 'qr-captcha-iframe', + src: this.noscriptURL + }); + $.add(this.nodes.container, iframe); + return this.conn.target = iframe.contentWindow; + }, + setupJS: function() { return $.globalEval('(function() {\n function render() {\n var container = document.querySelector("#qr .captcha-container");\n container.dataset.widgetID = window.grecaptcha.render(container, {\n sitekey: \'6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc\',\n theme: document.documentElement.classList.contains(\'tomorrow\') ? \'dark\' : \'light\',\n callback: function(response) {\n window.dispatchEvent(new CustomEvent("captcha:success", {detail: response}));\n }\n });\n }\n if (window.grecaptcha) {\n render();\n } else {\n var cbNative = window.onRecaptchaLoaded;\n window.onRecaptchaLoaded = function() {\n render();\n cbNative();\n }\n }\n})();'); }, afterSetup: function(mutations) { @@ -8258,12 +7998,12 @@ return null; } }, - save: function(pasted) { + save: function(pasted, token) { var base1, focus, ref, ref1; $.forceSync('captchas'); this.captchas.push({ - response: $('textarea', this.nodes.container).value, - timeout: (pasted ? this.setupTime : Date.now()) + this.lifetime + response: token || $('textarea', this.nodes.container).value, + timeout: Date.now() + this.lifetime }); $.set('captchas', this.captchas); this.count(); @@ -8323,7 +8063,11 @@ } }, reload: function() { - return $.globalEval('(function() {\n var container = document.querySelector("#qr .captcha-container");\n window.grecaptcha.reset(container.dataset.widgetID);\n})();'); + if (this.noscript) { + return $('iframe', this.nodes.container).src = this.noscriptURL; + } else { + return $.globalEval('(function() {\n var container = document.querySelector("#qr .captcha-container");\n window.grecaptcha.reset(container.dataset.widgetID);\n})();'); + } } }; @@ -15466,8 +15210,11 @@ }; Report = { - css: "noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + + css: "noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + "}\n" + ":root:not(.js-enabled) #g-recaptcha {\n" + " height: auto;\n" + @@ -17328,8 +17075,14 @@ " 0% {transform:rotate(0deg);}\n" + " 100% {transform:rotate(359deg);}\n" + "}\n" + -"noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + +"noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + +"}\n" + +":root:not(.js-enabled) #g-recaptcha {\n" + +" height: auto;\n" + "}\n" + "/* General */\n" + ".dialog {\n" + @@ -18529,23 +18282,7 @@ " position: relative;\n" + " top: 2px;\n" + "}\n" + -"/* Noscript Recaptcha */\n" + -".captcha-img {\n" + -" margin: 0px;\n" + -" text-align: center;\n" + -" background-image: #fff;\n" + -" font-size: 0px;\n" + -" min-height: 59px;\n" + -" min-width: 302px;\n" + -"}\n" + -".captcha-input{\n" + -" width: 100%;\n" + -" margin: 1px 0 0;\n" + -"}\n" + -"#qr-captcha-iframe {\n" + -" display: none;\n" + -"}\n" + -"/* Recaptcha v2 */\n" + +"/* Captcha */\n" + "#qr .captcha-root {\n" + " position: relative;\n" + "}\n" + @@ -18569,6 +18306,13 @@ " display: block;\n" + " width: 100%;\n" + "}\n" + +"#qr-captcha-iframe {\n" + +" width: 302px;\n" + +" height: 423px;\n" + +" max-width: 100vw;\n" + +" max-height: calc(100vh - 210px);\n" + +" overflow: auto;\n" + +"}\n" + ".goog-bubble-content {\n" + " max-width: 100vw;\n" + " max-height: 100vh;\n" + @@ -19727,8 +19471,14 @@ " font-family: sans-serif !important;\n" + " text-shadow: 1px 1px 1px rgba(0,74,153,0.6);\n" + "}", - cssWWW: "noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + + cssWWW: "noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + +"}\n" + +":root:not(.js-enabled) #g-recaptcha {\n" + +" height: auto;\n" + "}\n" + "#captcha-cnt {\n" + " height: auto;\n" + diff --git a/builds/4chan-X.crx b/builds/4chan-X.crx index ec4bfa96f..d1e94d8a5 100644 Binary files a/builds/4chan-X.crx and b/builds/4chan-X.crx differ diff --git a/builds/4chan-X.meta.js b/builds/4chan-X.meta.js index dbb4ab924..0193eb846 100644 --- a/builds/4chan-X.meta.js +++ b/builds/4chan-X.meta.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X -// @version 1.10.14.3 +// @version 1.10.14.4 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 8bba99011..d77c7dc61 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -1,7 +1,7 @@ // Generated by CoffeeScript // ==UserScript== // @name 4chan X -// @version 1.10.14.3 +// @version 1.10.14.4 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -398,7 +398,7 @@ doc = d.documentElement; g = { - VERSION: '1.10.14.3', + VERSION: '1.10.14.4', NAMESPACE: '4chan X.', boards: {} }; @@ -6708,7 +6708,7 @@ QR = { mimeTypes: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/vnd.adobe.flash.movie', 'application/x-shockwave-flash', 'video/webm'], init: function() { - var noscript, sc; + var sc; if (!Conf['Quick Reply']) { return; } @@ -6717,8 +6717,7 @@ if (g.VIEW === 'archive') { return; } - noscript = Conf['Force Noscript Captcha'] || !$.hasClass(doc, 'js-enabled'); - this.captcha = Captcha[noscript ? 'noscript' : 'v2']; + this.captcha = Captcha.v2; $.on(d, '4chanXInitFinished', this.initReady); Post.callbacks.push({ name: 'Quick Reply', @@ -7763,55 +7762,6 @@ }; Captcha.noscript = { - lifetime: 2 * $.MINUTE, - iframeURL: '//www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc', - init: function() { - var container, input; - if (d.cookie.indexOf('pass_enabled=1') >= 0) { - return; - } - if (!(this.isEnabled = !!$.id('g-recaptcha'))) { - return; - } - container = $.el('div', { - className: 'captcha-img', - title: 'Reload reCAPTCHA' - }); - input = $.el('input', { - className: 'captcha-input field', - title: 'Verification', - autocomplete: 'off', - spellcheck: false - }); - this.nodes = { - container: container, - input: input - }; - $.on(input, 'keydown', this.keydown.bind(this)); - $.on(this.nodes.container, 'click', (function(_this) { - return function() { - _this.reload(); - return _this.nodes.input.focus(); - }; - })(this)); - this.conn = new Connection(null, location.protocol + "//www.google.com", { - challenge: this.load.bind(this), - token: this.save.bind(this), - error: this.error.bind(this) - }); - $.addClass(QR.nodes.el, 'has-captcha'); - $.after(QR.nodes.com.parentNode, [container, input]); - this.captchas = []; - $.get('captchas', [], function(arg) { - var captchas; - captchas = arg.captchas; - QR.captcha.sync(captchas); - return QR.captcha.clear(); - }); - $.sync('captchas', this.sync); - this.beforeSetup(); - return this.setup(); - }, initFrame: function() { var cb, conn, img, ref, ref1; conn = new Connection(window.parent, location.protocol + "//boards.4chan.org", { @@ -7842,247 +7792,12 @@ } else { return $.on(img, 'load', cb); } - }, - timers: {}, - cb: { - focus: function() { - return QR.captcha.setup(false, true); - } - }, - beforeSetup: function() { - var container, input, ref; - ref = this.nodes, container = ref.container, input = ref.input; - container.hidden = true; - input.value = ''; - input.placeholder = 'Focus to load reCAPTCHA'; - this.count(); - return $.on(input, 'focus click', this.cb.focus); - }, - needed: function() { - var captchaCount, postsCount; - captchaCount = this.captchas.length; - if (QR.req) { - captchaCount++; - } - postsCount = QR.posts.length; - if (postsCount === 1 && !Conf['Auto-load captcha'] && !QR.posts[0].com && !QR.posts[0].file) { - postsCount = 0; - } - return captchaCount < postsCount; - }, - onNewPost: function() {}, - onPostChange: function() {}, - setup: function(focus, force) { - if (!(this.isEnabled && (this.needed() || force))) { - return; - } - if (!this.nodes.iframe) { - this.nodes.iframe = $.el('iframe', { - id: 'qr-captcha-iframe', - src: this.iframeURL - }); - $.add(d.body, this.nodes.iframe); - this.conn.target = this.nodes.iframe.contentWindow; - } else if (!this.occupied || force) { - this.nodes.iframe.src = this.iframeURL; - } - this.occupied = true; - if (focus) { - return this.nodes.input.focus(); - } - }, - afterSetup: function() { - var container, input, ref; - ref = this.nodes, container = ref.container, input = ref.input; - container.hidden = false; - input.placeholder = 'Verification'; - this.count(); - $.off(input, 'focus click', this.cb.focus); - if (QR.nodes.el.getBoundingClientRect().bottom > doc.clientHeight) { - QR.nodes.el.style.top = ''; - return QR.nodes.el.style.bottom = '0px'; - } - }, - destroy: function() { - if (!this.isEnabled) { - return; - } - if (this.nodes.img) { - $.rm(this.nodes.img); - } - delete this.nodes.img; - if (this.nodes.iframe) { - $.rm(this.nodes.iframe); - } - delete this.nodes.iframe; - delete this.occupied; - return this.beforeSetup(); - }, - sync: function(captchas) { - if (captchas == null) { - captchas = []; - } - QR.captcha.captchas = captchas; - return QR.captcha.count(); - }, - getOne: function() { - var captcha; - this.clear(); - if (captcha = this.captchas.shift()) { - this.count(); - $.set('captchas', this.captchas); - return captcha.response; - } else if (/\S/.test(this.nodes.input.value)) { - return (function(_this) { - return function(cb) { - _this.submitCB = cb; - return _this.sendResponse(); - }; - })(this); - } else { - return null; - } - }, - sendResponse: function() { - var response; - response = this.nodes.input.value; - if (/\S/.test(response)) { - return this.conn.send({ - response: response - }); - } - }, - save: function(token) { - delete this.occupied; - this.nodes.input.value = ''; - if (this.submitCB) { - this.submitCB(token); - delete this.submitCB; - if (this.needed()) { - return this.reload(); - } else { - return this.destroy(); - } - } else { - $.forceSync('captchas'); - this.captchas.push({ - response: token, - timeout: this.timeout - }); - this.count(); - $.set('captchas', this.captchas); - return this.reload(); - } - }, - error: function(message) { - this.occupied = true; - this.nodes.input.value = ''; - if (this.submitCB) { - this.submitCB(); - delete this.submitCB; - } - return QR.error("Captcha Error: " + message); - }, - clear: function() { - var captcha, i, k, len1, now, ref; - if (!this.captchas.length) { - return; - } - $.forceSync('captchas'); - now = Date.now(); - ref = this.captchas; - for (i = k = 0, len1 = ref.length; k < len1; i = ++k) { - captcha = ref[i]; - if (captcha.timeout > now) { - break; - } - } - if (!i) { - return; - } - this.captchas = this.captchas.slice(i); - this.count(); - return $.set('captchas', this.captchas); - }, - load: function(src) { - var container, img, input, ref; - ref = this.nodes, container = ref.container, input = ref.input, img = ref.img; - this.occupied = true; - this.timeout = Date.now() + this.lifetime; - if (!img) { - img = this.nodes.img = new Image(); - $.one(img, 'load', this.afterSetup.bind(this)); - $.on(img, 'load', function() { - return this.hidden = false; - }); - $.add(container, img); - } - img.src = src; - input.value = ''; - this.clear(); - clearTimeout(this.timers.expire); - return this.timers.expire = setTimeout(this.expire.bind(this), this.lifetime); - }, - count: function() { - var count, placeholder; - count = this.captchas ? this.captchas.length : 0; - placeholder = this.nodes.input.placeholder.replace(/\ \(.*\)$/, ''); - placeholder += (function() { - switch (count) { - case 0: - if (placeholder === 'Verification') { - return ' (Shift + Enter to cache)'; - } else { - return ''; - } - break; - case 1: - return ' (1 cached captcha)'; - default: - return " (" + count + " cached captchas)"; - } - })(); - this.nodes.input.placeholder = placeholder; - this.nodes.input.alt = count; - clearTimeout(this.timers.clear); - if (this.captchas.length) { - return this.timers.clear = setTimeout(this.clear.bind(this), this.captchas[0].timeout - Date.now()); - } - }, - expire: function() { - if (!this.nodes.iframe) { - return; - } - if (!d.hidden && (this.needed() || d.activeElement === this.nodes.input)) { - return this.reload(); - } else { - return this.destroy(); - } - }, - reload: function() { - var ref; - this.nodes.iframe.src = this.iframeURL; - this.occupied = true; - return (ref = this.nodes.img) != null ? ref.hidden = true : void 0; - }, - keydown: function(e) { - if (e.keyCode === 8 && !this.nodes.input.value) { - if (this.nodes.iframe) { - this.reload(); - } else { - this.setup(); - } - } else if (e.keyCode === 13 && e.shiftKey) { - this.sendResponse(); - } else { - return; - } - return e.preventDefault(); } }; Captcha.v2 = { lifetime: 2 * $.MINUTE, + noscriptURL: '//www.google.com/recaptcha/api/fallback?k=6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc', init: function() { var counter, root; if (d.cookie.indexOf('pass_enabled=1') >= 0) { @@ -8091,6 +7806,15 @@ if (!(this.isEnabled = !!$.id('g-recaptcha'))) { return; } + if (this.noscript = Conf['Force Noscript Captcha'] || !$.hasClass(doc, 'js-enabled')) { + this.conn = new Connection(null, location.protocol + "//www.google.com", { + token: (function(_this) { + return function(token) { + return _this.save(true, token); + }; + })(this) + }); + } this.captchas = []; $.get('captchas', [], function(arg) { var captchas; @@ -8183,6 +7907,22 @@ childList: true, subtree: true }); + if (this.noscript) { + return this.setupNoscript(); + } else { + return this.setupJS(); + } + }, + setupNoscript: function() { + var iframe; + iframe = $.el('iframe', { + id: 'qr-captcha-iframe', + src: this.noscriptURL + }); + $.add(this.nodes.container, iframe); + return this.conn.target = iframe.contentWindow; + }, + setupJS: function() { return $.globalEval('(function() {\n function render() {\n var container = document.querySelector("#qr .captcha-container");\n container.dataset.widgetID = window.grecaptcha.render(container, {\n sitekey: \'6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc\',\n theme: document.documentElement.classList.contains(\'tomorrow\') ? \'dark\' : \'light\',\n callback: function(response) {\n window.dispatchEvent(new CustomEvent("captcha:success", {detail: response}));\n }\n });\n }\n if (window.grecaptcha) {\n render();\n } else {\n var cbNative = window.onRecaptchaLoaded;\n window.onRecaptchaLoaded = function() {\n render();\n cbNative();\n }\n }\n})();'); }, afterSetup: function(mutations) { @@ -8259,12 +7999,12 @@ return null; } }, - save: function(pasted) { + save: function(pasted, token) { var base1, focus, ref, ref1; $.forceSync('captchas'); this.captchas.push({ - response: $('textarea', this.nodes.container).value, - timeout: (pasted ? this.setupTime : Date.now()) + this.lifetime + response: token || $('textarea', this.nodes.container).value, + timeout: Date.now() + this.lifetime }); $.set('captchas', this.captchas); this.count(); @@ -8324,7 +8064,11 @@ } }, reload: function() { - return $.globalEval('(function() {\n var container = document.querySelector("#qr .captcha-container");\n window.grecaptcha.reset(container.dataset.widgetID);\n})();'); + if (this.noscript) { + return $('iframe', this.nodes.container).src = this.noscriptURL; + } else { + return $.globalEval('(function() {\n var container = document.querySelector("#qr .captcha-container");\n window.grecaptcha.reset(container.dataset.widgetID);\n})();'); + } } }; @@ -15467,8 +15211,11 @@ }; Report = { - css: "noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + + css: "noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + "}\n" + ":root:not(.js-enabled) #g-recaptcha {\n" + " height: auto;\n" + @@ -17329,8 +17076,14 @@ " 0% {transform:rotate(0deg);}\n" + " 100% {transform:rotate(359deg);}\n" + "}\n" + -"noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + +"noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + +"}\n" + +":root:not(.js-enabled) #g-recaptcha {\n" + +" height: auto;\n" + "}\n" + "/* General */\n" + ".dialog {\n" + @@ -18530,23 +18283,7 @@ " position: relative;\n" + " top: 2px;\n" + "}\n" + -"/* Noscript Recaptcha */\n" + -".captcha-img {\n" + -" margin: 0px;\n" + -" text-align: center;\n" + -" background-image: #fff;\n" + -" font-size: 0px;\n" + -" min-height: 59px;\n" + -" min-width: 302px;\n" + -"}\n" + -".captcha-input{\n" + -" width: 100%;\n" + -" margin: 1px 0 0;\n" + -"}\n" + -"#qr-captcha-iframe {\n" + -" display: none;\n" + -"}\n" + -"/* Recaptcha v2 */\n" + +"/* Captcha */\n" + "#qr .captcha-root {\n" + " position: relative;\n" + "}\n" + @@ -18570,6 +18307,13 @@ " display: block;\n" + " width: 100%;\n" + "}\n" + +"#qr-captcha-iframe {\n" + +" width: 302px;\n" + +" height: 423px;\n" + +" max-width: 100vw;\n" + +" max-height: calc(100vh - 210px);\n" + +" overflow: auto;\n" + +"}\n" + ".goog-bubble-content {\n" + " max-width: 100vw;\n" + " max-height: 100vh;\n" + @@ -19728,8 +19472,14 @@ " font-family: sans-serif !important;\n" + " text-shadow: 1px 1px 1px rgba(0,74,153,0.6);\n" + "}", - cssWWW: "noscript div:first-child, noscript iframe {\n" + -" height: 422px !important;\n" + + cssWWW: "noscript > div, noscript > div > div {\n" + +" height: 545px !important;\n" + +"}\n" + +"noscript > div > div > div:first-child, noscript iframe {\n" + +" height: 423px !important;\n" + +"}\n" + +":root:not(.js-enabled) #g-recaptcha {\n" + +" height: auto;\n" + "}\n" + "#captcha-cnt {\n" + " height: auto;\n" + diff --git a/builds/4chan-X.zip b/builds/4chan-X.zip index 71584d89a..143573e51 100644 Binary files a/builds/4chan-X.zip and b/builds/4chan-X.zip differ diff --git a/builds/updates-beta.xml b/builds/updates-beta.xml index a32d45e90..483e8f24e 100644 --- a/builds/updates-beta.xml +++ b/builds/updates-beta.xml @@ -1,7 +1,7 @@ - + diff --git a/builds/updates.xml b/builds/updates.xml index 2ab3c0366..5c19a0977 100644 --- a/builds/updates.xml +++ b/builds/updates.xml @@ -1,7 +1,7 @@ - + diff --git a/package.json b/package.json index 697b6c5f3..686fa58cb 100755 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "description": "Cross-browser userscript for maximum lurking on 4chan.", "meta": { "name": "4chan X", - "version": "1.10.14.3", - "date": "2015-06-16T17:33:56.334Z", + "version": "1.10.14.4", + "date": "2015-06-19T22:45:36.581Z", "repo": "https://github.com/ccd0/4chan-x/", "page": "https://github.com/ccd0/4chan-x", "downloads": "https://ccd0.github.io/4chan-x/builds/",