diff --git a/4chan_x.user.js b/4chan_x.user.js index 3c8fc7d80..73e71fef4 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan x -// @version 2.24.0 +// @version 2.24.2 // @namespace aeosynth // @description Adds various features. // @copyright 2009-2011 James Campos @@ -17,7 +17,7 @@ * Copyright (c) 2009-2011 James Campos * Copyright (c) 2012 Nicolas Stepien * http://mayhemydg.github.com/4chan-x/ - * 4chan X 2.24.0 + * 4chan X 2.24.2 * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -199,7 +199,7 @@ NAMESPACE = '4chan_x.'; - VERSION = '2.24.0'; + VERSION = '2.24.2'; SECOND = 1000; @@ -304,7 +304,7 @@ }; $.extend($, { - onLoad: function(fc) { + ready: function(fc) { var cb; if (/interactive|complete/.test(d.readyState)) return fc(); cb = function() { @@ -464,54 +464,44 @@ $.cache.requests = {}; - if (typeof GM_deleteValue !== "undefined" && GM_deleteValue !== null) { - $.extend($, { - "delete": function(name) { - name = NAMESPACE + name; - return GM_deleteValue(name); - }, - get: function(name, defaultValue) { - var value; - name = NAMESPACE + name; - if (value = GM_getValue(name)) { - return JSON.parse(value); - } else { - return defaultValue; - } - }, - openInTab: function(url) { - return GM_openInTab(url); - }, - set: function(name, value) { - name = NAMESPACE + name; - localStorage[name] = JSON.stringify(value); - return GM_setValue(name, JSON.stringify(value)); + $.extend($, typeof GM_deleteValue !== "undefined" && GM_deleteValue !== null ? { + "delete": function(name) { + name = NAMESPACE + name; + return GM_deleteValue(name); + }, + get: function(name, defaultValue) { + var value; + name = NAMESPACE + name; + if (value = GM_getValue(name)) { + return JSON.parse(value); + } else { + return defaultValue; } - }); - } else { - $.extend($, { - "delete": function(name) { - name = NAMESPACE + name; - return delete localStorage[name]; - }, - get: function(name, defaultValue) { - var value; - name = NAMESPACE + name; - if (value = localStorage[name]) { - return JSON.parse(value); - } else { - return defaultValue; - } - }, - openInTab: function(url) { - return window.open(url, "_blank"); - }, - set: function(name, value) { - name = NAMESPACE + name; - return localStorage[name] = JSON.stringify(value); + }, + set: function(name, value) { + name = NAMESPACE + name; + localStorage[name] = JSON.stringify(value); + return GM_setValue(name, JSON.stringify(value)); + } + } : { + "delete": function(name) { + name = NAMESPACE + name; + return delete localStorage[name]; + }, + get: function(name, defaultValue) { + var value; + name = NAMESPACE + name; + if (value = localStorage[name]) { + return JSON.parse(value); + } else { + return defaultValue; } - }); - } + }, + set: function(name, value) { + name = NAMESPACE + name; + return localStorage[name] = JSON.stringify(value); + } + }); for (key in conf) { val = conf[key]; @@ -1067,11 +1057,12 @@ return $('textarea', qr.el).focus(); }, open: function(thread, tab) { - var id, url; + var id, open, url; id = thread.firstChild.id; url = "http://boards.4chan.org/" + g.BOARD + "/res/" + id; if (tab) { - return $.openInTab(url); + open = GM_openInTab || window.open; + return open(url, "_blank"); } else { return location.href = url; } @@ -1410,12 +1401,12 @@ $.on(a, 'click', options.dialog); $.replace(home, a); if (!$.get('firstrun')) { - options.dialog(); - return $.set('firstrun', true); + $.set('firstrun', true); + return options.dialog(); } }, dialog: function() { - var arr, back, checked, description, dialog, favicon, hiddenNum, hiddenThreads, indicator, indicators, input, key, li, obj, option, overlay, ta, time, ul, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _ref4, _ref5; + var arr, back, checked, description, dialog, favicon, hiddenNum, hiddenThreads, indicator, indicators, input, key, li, obj, overlay, ta, time, ul, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4; dialog = $.el('div', { id: 'options', className: 'reply dialog', @@ -1476,11 +1467,11 @@
Unread Count is disabled.
\ Unread favicons
\ \ \ \ @@ -1553,27 +1544,20 @@ $.on(time, 'keyup', $.cb.value); $.on(time, 'keyup', options.time); favicon = $('select', dialog); - _ref3 = favicon.options; - for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { - option = _ref3[_j]; - if (option.textContent === conf['favicon']) { - option.selected = true; - break; - } - } + favicon.value = conf['favicon']; $.on(favicon, 'change', $.cb.value); $.on(favicon, 'change', options.favicon); - _ref4 = $$('#keybinds_tab + div input', dialog); - for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) { - input = _ref4[_k]; + _ref3 = $$('#keybinds_tab + div input', dialog); + for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) { + input = _ref3[_j]; input.type = 'text'; input.value = conf[input.name]; $.on(input, 'keydown', options.keybind); } indicators = {}; - _ref5 = $$('.error', dialog); - for (_l = 0, _len4 = _ref5.length; _l < _len4; _l++) { - indicator = _ref5[_l]; + _ref4 = $$('.error', dialog); + for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) { + indicator = _ref4[_k]; key = indicator.firstChild.textContent; indicator.hidden = conf[key]; indicators[key] = indicator; @@ -2553,7 +2537,7 @@ threadStats.postcountEl.textContent = ++threadStats.posts; if ($('img[md5]', root)) { threadStats.imagecountEl.textContent = ++threadStats.images; - if (threadStats.images > 150) { + if (threadStats.images > 151) { return threadStats.imagecountEl.className = 'error'; } } @@ -2562,11 +2546,11 @@ unread = { init: function() { - unread.replies = []; d.title = '(0) ' + d.title; $.on(window, 'scroll', unread.scroll); return g.callbacks.push(unread.node); }, + replies: [], node: function(root) { if (root.hidden || root.className) return; unread.replies.push(root); @@ -2859,21 +2843,14 @@ if (!thumb.hidden) return imgExpand.expand(thumb); }, dialog: function() { - var controls, form, imageType, option, select, _i, _len, _ref; + var controls, form, imageType, select; controls = $.el('div', { id: 'imgControls', - innerHTML: " " + innerHTML: "" }); imageType = $.get('imageType', 'full'); select = $('select', controls); - _ref = select.options; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - option = _ref[_i]; - if (option.textContent === imageType) { - option.selected = true; - break; - } - } + select.value = imageType; imgExpand.cb.typeChange.call(select); $.on(select, 'change', $.cb.value); $.on(select, 'change', imgExpand.cb.typeChange); @@ -2898,22 +2875,20 @@ g.PAGENUM = parseInt(temp) || 0; } if (location.hostname === 'sys.4chan.org') { - $.onLoad(qr.sys); + $.ready(qr.sys); return; } if (location.hostname === 'images.4chan.org') { - if (conf['404 Redirect']) { - $.onLoad(function() { - if (d.title === '4chan - 404') return redirect.init(); - }); - } + $.ready(function() { + if (d.title === '4chan - 404') return redirect.init(); + }); return; } - $.onLoad(options.init); + $.ready(options.init); $.on(window, 'message', Main.message); now = Date.now(); if (conf['Check for Updates'] && $.get('lastUpdate', 0) < now - 6 * HOUR) { - $.onLoad(function() { + $.ready(function() { return $.add(d.head, $.el('script', { src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' })); @@ -2945,15 +2920,16 @@ if (conf['Sauce']) sauce.init(); if (conf['Image Auto-Gif']) imgGif.init(); if (conf['Image Hover']) imgHover.init(); + if (conf['Reveal Spoilers']) revealSpoilers.init(); if (conf['Report Button']) reportButton.init(); if (conf['Quote Inline']) quoteInline.init(); if (conf['Quote Preview']) quotePreview.init(); if (conf['Quote Backlinks']) quoteBacklink.init(); if (conf['Indicate OP quote']) quoteOP.init(); if (conf['Indicate Cross-thread Quotes']) quoteDR.init(); - return $.onLoad(Main.onLoad); + return $.ready(Main.ready); }, - onLoad: function() { + ready: function() { var callback, node, nodes, _i, _j, _len, _len2, _ref; if (conf['404 Redirect'] && d.title === '4chan - 404') { redirect.init(); @@ -2966,19 +2942,19 @@ Favicon.init(); if (conf['Quick Reply']) qr.init(); if (conf['Image Expansion']) imgExpand.init(); - if (conf['Reveal Spoilers'] && $('.postarea label')) revealSpoilers.init(); if (conf['Thread Watcher']) watcher.init(); if (conf['Keybinds']) keybinds.init(); - if (conf['Reply Navigation'] || conf['Index Navigation']) nav.init(); if (g.REPLY) { if (conf['Thread Updater']) updater.init(); if (conf['Thread Stats']) threadStats.init(); + if (conf['Reply Navigation']) nav.init(); if (conf['Post in Title']) titlePost.init(); if (conf['Unread Count']) unread.init(); } else { if (conf['Thread Hiding']) threadHiding.init(); if (conf['Thread Expansion']) expandThread.init(); if (conf['Comment Expansion']) expandComment.init(); + if (conf['Index Navigation']) nav.init(); } nodes = $$('.op, a + table'); _ref = g.callbacks; @@ -3020,10 +2996,10 @@ }, css: '\ /* dialog styling */\ - div.dialog {\ - border: 1px solid;\ + .dialog {\ + border: 1px solid rgba(0,0,0,.25);\ }\ - div.dialog > div.move {\ + .move {\ cursor: move;\ }\ label, a, .favicon {\ @@ -3093,6 +3069,7 @@ bottom: 0;\ text-align: center;\ background: rgba(0,0,0,.5);\ + z-index: 1;\ }\ #overlay::after {\ content: "";\ diff --git a/Cakefile b/Cakefile index f524d45c5..44559868a 100644 --- a/Cakefile +++ b/Cakefile @@ -2,7 +2,7 @@ {exec} = require 'child_process' fs = require 'fs' -VERSION = '2.24.0' +VERSION = '2.24.2' HEADER = """ // ==UserScript== diff --git a/changelog b/changelog index f4c9d5f14..6a1953df1 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,14 @@ master +2.24.2 +- mayhem + fix options popping up everytime a page loads + +2.24.1 +- mayhem + fix Open thread in new tab keybind for Safari with Ninjakit + fix Index/Reply Navigation working in both cases when only one is enabled + 2.24.0 - mayhem redirect 404'd pictures to archives when possible diff --git a/latest.js b/latest.js index 7a8079fdf..dc2190293 100644 --- a/latest.js +++ b/latest.js @@ -1 +1 @@ -postMessage({version:'2.24.0'},'*'); +postMessage({version:'2.24.2'},'*'); diff --git a/script.coffee b/script.coffee index e6770ddb2..2e41bb9b5 100644 --- a/script.coffee +++ b/script.coffee @@ -121,7 +121,7 @@ conf = {} ) null, config NAMESPACE = '4chan_x.' -VERSION = '2.24.0' +VERSION = '2.24.2' SECOND = 1000 MINUTE = 60*SECOND HOUR = 60*MINUTE @@ -221,7 +221,7 @@ $.extend = (object, properties) -> object $.extend $, - onLoad: (fc) -> + ready: (fc) -> if /interactive|complete/.test d.readyState return fc() cb = -> @@ -353,8 +353,8 @@ $.extend $, $.cache.requests = {} -if GM_deleteValue? - $.extend $, +$.extend $, + if GM_deleteValue? delete: (name) -> name = NAMESPACE + name GM_deleteValue name @@ -364,15 +364,12 @@ if GM_deleteValue? JSON.parse value else defaultValue - openInTab: (url) -> - GM_openInTab url set: (name, value) -> name = NAMESPACE + name # for `storage` events localStorage[name] = JSON.stringify value GM_setValue name, JSON.stringify value -else - $.extend $, + else delete: (name) -> name = NAMESPACE + name delete localStorage[name] @@ -382,8 +379,6 @@ else JSON.parse value else defaultValue - openInTab: (url) -> - window.open url, "_blank" set: (name, value) -> name = NAMESPACE + name localStorage[name] = JSON.stringify value @@ -761,7 +756,8 @@ keybinds = id = thread.firstChild.id url = "http://boards.4chan.org/#{g.BOARD}/res/#{id}" if tab - $.openInTab url + open = GM_openInTab or window.open + open url, "_blank" else location.href = url @@ -1146,8 +1142,8 @@ options = $.on a, 'click', options.dialog $.replace home, a unless $.get 'firstrun' - options.dialog() $.set 'firstrun', true + options.dialog() dialog: -> dialog = $.el 'div' @@ -1210,11 +1206,11 @@ options =
Unread Count is disabled.
Unread favicons
@@ -1282,10 +1278,7 @@ options = $.on time, 'keyup', $.cb.value $.on time, 'keyup', options.time favicon = $ 'select', dialog - for option in favicon.options - if option.textContent is conf['favicon'] - option.selected = true - break + favicon.value = conf['favicon'] $.on favicon, 'change', $.cb.value $.on favicon, 'change', options.favicon @@ -2031,16 +2024,17 @@ threadStats = threadStats.postcountEl.textContent = ++threadStats.posts if $ 'img[md5]', root threadStats.imagecountEl.textContent = ++threadStats.images - if threadStats.images > 150 + if threadStats.images > 151 threadStats.imagecountEl.className = 'error' unread = init: -> - unread.replies = [] d.title = '(0) ' + d.title $.on window, 'scroll', unread.scroll g.callbacks.push unread.node + replies: [] + node: (root) -> return if root.hidden or root.className unread.replies.push root @@ -2128,7 +2122,6 @@ Favicon = redirect = init: -> url = - # waiting for https://github.com/FoOlRulez/FoOlFuuka/issues/11 if location.hostname is 'images.4chan.org' redirect.image g.BOARD, location.pathname.split('/')[3] else if /^\d+$/.test g.THREAD_ID @@ -2260,14 +2253,10 @@ imgExpand = controls = $.el 'div', id: 'imgControls' innerHTML: - " - " + "" imageType = $.get 'imageType', 'full' select = $ 'select', controls - for option in select.options - if option.textContent is imageType - option.selected = true - break + select.value = imageType imgExpand.cb.typeChange.call select $.on select, 'change', $.cb.value $.on select, 'change', imgExpand.cb.typeChange @@ -2290,20 +2279,19 @@ Main = g.PAGENUM = parseInt(temp) or 0 if location.hostname is 'sys.4chan.org' - $.onLoad qr.sys + $.ready qr.sys return if location.hostname is 'images.4chan.org' - if conf['404 Redirect'] - $.onLoad -> redirect.init() if d.title is '4chan - 404' + $.ready -> redirect.init() if d.title is '4chan - 404' return - $.onLoad options.init + $.ready options.init $.on window, 'message', Main.message now = Date.now() if conf['Check for Updates'] and $.get('lastUpdate', 0) < now - 6*HOUR - $.onLoad -> $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' + $.ready -> $.add d.head, $.el 'script', src: 'https://raw.github.com/mayhemydg/4chan-x/master/latest.js' $.set 'lastUpdate', now g.hiddenReplies = $.get "hiddenReplies/#{g.BOARD}/", {} @@ -2350,6 +2338,9 @@ Main = if conf['Image Hover'] imgHover.init() + if conf['Reveal Spoilers'] + revealSpoilers.init() + if conf['Report Button'] reportButton.init() @@ -2369,9 +2360,9 @@ Main = quoteDR.init() - $.onLoad Main.onLoad + $.ready Main.ready - onLoad: -> + ready: -> if conf['404 Redirect'] and d.title is '4chan - 404' redirect.init() return @@ -2389,18 +2380,12 @@ Main = if conf['Image Expansion'] imgExpand.init() - if conf['Reveal Spoilers'] and $('.postarea label') - revealSpoilers.init() - if conf['Thread Watcher'] watcher.init() if conf['Keybinds'] keybinds.init() - if conf['Reply Navigation'] or conf['Index Navigation'] - nav.init() - if g.REPLY if conf['Thread Updater'] updater.init() @@ -2408,6 +2393,9 @@ Main = if conf['Thread Stats'] threadStats.init() + if conf['Reply Navigation'] + nav.init() + if conf['Post in Title'] titlePost.init() @@ -2424,6 +2412,9 @@ Main = if conf['Comment Expansion'] expandComment.init() + if conf['Index Navigation'] + nav.init() + nodes = $$ '.op, a + table' for callback in g.callbacks @@ -2450,10 +2441,10 @@ Main = css: ' /* dialog styling */ - div.dialog { - border: 1px solid; + .dialog { + border: 1px solid rgba(0,0,0,.25); } - div.dialog > div.move { + .move { cursor: move; } label, a, .favicon { @@ -2523,6 +2514,7 @@ Main = bottom: 0; text-align: center; background: rgba(0,0,0,.5); + z-index: 1; } #overlay::after { content: "";