diff --git a/CHANGELOG.md b/CHANGELOG.md index 92f9c1686..5de52ae11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ **MayhemYDG**: +- **New feature**: `Show Dice Roll` (with @carboncopy) + - Shows dice that were entered into the email field on /tg/. - Fix impossibility to create new threads when in dead threads. - Fix flag filtering on /sp/ and /int/. -- Update archives. (with woxxy and proplex) +- Update archives. (with @woxxy and @proplex) - Minor fixes. - Minor optimizations. diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 0f8fb21f4..cf4d6addc 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -111,7 +111,7 @@ 'use strict'; (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, 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, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, Dice, 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; }, @@ -133,6 +133,7 @@ 'Thread Expansion': [true, 'Add buttons to expand threads.'], 'Index Navigation': [false, 'Add buttons to navigate between threads.'], 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'], + 'Show Dice Roll': [true, 'Show dice that were entered into the email field.'], 'Check for Updates': [true, 'Check for updated versions of 4chan X.'], 'Show Updated Notifications': [true, 'Show notifications when 4chan X is successfully updated.'], 'Emoji': [false, 'Adds icons next to names for different emails'], @@ -447,7 +448,7 @@ var reqs; reqs = {}; - return function(url, cb) { + return function(url, cb, options) { var err, req, rm; if (req = reqs[url]) { @@ -462,25 +463,23 @@ return delete reqs[url]; }; try { - req = $.ajax(url, { - onload: function(e) { - var _i, _len, _ref; - - _ref = this.callbacks; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - cb = _ref[_i]; - cb.call(this, e); - } - this.evt = e; - return delete this.callbacks; - }, - onabort: rm, - onerror: rm - }); + req = $.ajax(url, options); } catch (_error) { err = _error; return; } + $.on(req, 'load', function(e) { + var _i, _len, _ref; + + _ref = this.callbacks; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + cb = _ref[_i]; + cb.call(this, e); + } + this.evt = e; + return delete this.callbacks; + }); + $.on(req, 'abort error', rm); req.callbacks = [cb]; return reqs[url] = req; }; @@ -2073,6 +2072,8 @@ })) { return $.cache(url, function() { return Get.archivedPost(this, boardID, postID, root, context); + }, { + withCredentials: url.archive.withCredentials }); } }, @@ -2105,6 +2106,8 @@ })) { $.cache(url, function() { return Get.archivedPost(this, boardID, postID, root, context); + }, { + withCredentials: url.archive.withCredentials }); } else { $.addClass(root, 'warning'); @@ -2126,6 +2129,8 @@ })) { $.cache(url, function() { return Get.archivedPost(this, boardID, postID, root, context); + }, { + withCredentials: url.archive.withCredentials }); } else { $.addClass(root, 'warning'); @@ -8183,6 +8188,7 @@ domain: 'beta.foolz.us', http: true, https: true, + withCredentials: true, software: 'foolfuuka', boards: ['a', 'co', 'gd', 'h', 'jp', 'm', 'mlp', 'q', 'sp', 'tg', 'tv', 'u', 'v', 'vg', 'vp', 'vr', 'wsg'], files: ['a', 'gd', 'h', 'jp', 'm', 'q', 'tg', 'u', 'vg', 'vp', 'vr', 'wsg'] @@ -8275,14 +8281,16 @@ return "" + (Redirect.protocol(archive)) + archive.domain + "/" + path; }, post: function(archive, _arg) { - var boardID, postID, protocol; + var URL, boardID, postID, protocol; boardID = _arg.boardID, postID = _arg.postID; protocol = Redirect.protocol(archive); if (['Foolz', 'NSFW Foolz'].contains(archive.name)) { protocol = 'https://'; } - return "" + protocol + archive.domain + "/_/api/chan/post/?board=" + boardID + "&num=" + postID; + URL = new String("" + protocol + archive.domain + "/_/api/chan/post/?board=" + boardID + "&num=" + postID); + URL.archive = archive; + return URL; }, file: function(archive, _arg) { var boardID, filename; @@ -8498,6 +8506,27 @@ } }; + Dice = { + init: function() { + if (g.BOARD.ID !== 'tg' || g.VIEW === 'catalog' || !Conf['Show Dice Roll']) { + return; + } + return Post.prototype.callbacks.push({ + name: 'Show Dice Roll', + cb: this.node + }); + }, + node: function() { + var dicestats, roll, _ref; + + if (this.isClone || !(dicestats = (_ref = this.info.email) != null ? _ref.match(/dice[+\s](\d+)d(\d+)/) : void 0)) { + return; + } + roll = $('b', this.nodes.comment).firstChild; + return roll.data = "Rolled " + dicestats[1] + "d" + dicestats[2] + " and got " + (roll.data.slice(7)); + } + }; + Emoji = { init: function() { var css, icon, name, pos, _ref; @@ -9650,7 +9679,7 @@ return Time.zeroPad(this.getSeconds()); }, y: function() { - return this.getFullYear() % 100; + return this.getFullYear().toString().slice(2); }, Y: function() { return this.getFullYear(); @@ -10472,7 +10501,8 @@ 'Thread Updater': ThreadUpdater, 'Thread Watcher': ThreadWatcher, 'Index Navigation': Nav, - 'Keybinds': Keybinds + 'Keybinds': Keybinds, + 'Show Dice Roll': Dice }); $.on(d, 'AddCallback', Main.addCallback); return $.ready(Main.initReady); diff --git a/builds/crx/script.js b/builds/crx/script.js index cd6c5b4cd..1e575d241 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -92,7 +92,7 @@ 'use strict'; (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, 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, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, Dice, 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, @@ -115,6 +115,7 @@ 'Thread Expansion': [true, 'Add buttons to expand threads.'], 'Index Navigation': [false, 'Add buttons to navigate between threads.'], 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'], + 'Show Dice Roll': [true, 'Show dice that were entered into the email field.'], 'Show Updated Notifications': [true, 'Show notifications when 4chan X is successfully updated.'], 'Emoji': [false, 'Adds icons next to names for different emails'], 'Color User IDs': [false, 'Assign unique colors to user IDs on boards that use them'], @@ -428,7 +429,7 @@ var reqs; reqs = {}; - return function(url, cb) { + return function(url, cb, options) { var err, req, rm; if (req = reqs[url]) { @@ -443,25 +444,23 @@ return delete reqs[url]; }; try { - req = $.ajax(url, { - onload: function(e) { - var _i, _len, _ref; - - _ref = this.callbacks; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - cb = _ref[_i]; - cb.call(this, e); - } - this.evt = e; - return delete this.callbacks; - }, - onabort: rm, - onerror: rm - }); + req = $.ajax(url, options); } catch (_error) { err = _error; return; } + $.on(req, 'load', function(e) { + var _i, _len, _ref; + + _ref = this.callbacks; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + cb = _ref[_i]; + cb.call(this, e); + } + this.evt = e; + return delete this.callbacks; + }); + $.on(req, 'abort error', rm); req.callbacks = [cb]; return reqs[url] = req; }; @@ -2085,6 +2084,8 @@ })) { return $.cache(url, function() { return Get.archivedPost(this, boardID, postID, root, context); + }, { + withCredentials: url.archive.withCredentials }); } }, @@ -2117,6 +2118,8 @@ })) { $.cache(url, function() { return Get.archivedPost(this, boardID, postID, root, context); + }, { + withCredentials: url.archive.withCredentials }); } else { $.addClass(root, 'warning'); @@ -2138,6 +2141,8 @@ })) { $.cache(url, function() { return Get.archivedPost(this, boardID, postID, root, context); + }, { + withCredentials: url.archive.withCredentials }); } else { $.addClass(root, 'warning'); @@ -8169,6 +8174,7 @@ domain: 'beta.foolz.us', http: true, https: true, + withCredentials: true, software: 'foolfuuka', boards: ['a', 'co', 'gd', 'h', 'jp', 'm', 'mlp', 'q', 'sp', 'tg', 'tv', 'u', 'v', 'vg', 'vp', 'vr', 'wsg'], files: ['a', 'gd', 'h', 'jp', 'm', 'q', 'tg', 'u', 'vg', 'vp', 'vr', 'wsg'] @@ -8261,14 +8267,16 @@ return "" + (Redirect.protocol(archive)) + archive.domain + "/" + path; }, post: function(archive, _arg) { - var boardID, postID, protocol; + var URL, boardID, postID, protocol; boardID = _arg.boardID, postID = _arg.postID; protocol = Redirect.protocol(archive); if (['Foolz', 'NSFW Foolz'].contains(archive.name)) { protocol = 'https://'; } - return "" + protocol + archive.domain + "/_/api/chan/post/?board=" + boardID + "&num=" + postID; + URL = new String("" + protocol + archive.domain + "/_/api/chan/post/?board=" + boardID + "&num=" + postID); + URL.archive = archive; + return URL; }, file: function(archive, _arg) { var boardID, filename; @@ -8484,6 +8492,27 @@ } }; + Dice = { + init: function() { + if (g.BOARD.ID !== 'tg' || g.VIEW === 'catalog' || !Conf['Show Dice Roll']) { + return; + } + return Post.prototype.callbacks.push({ + name: 'Show Dice Roll', + cb: this.node + }); + }, + node: function() { + var dicestats, roll, _ref; + + if (this.isClone || !(dicestats = (_ref = this.info.email) != null ? _ref.match(/dice[+\s](\d+)d(\d+)/) : void 0)) { + return; + } + roll = $('b', this.nodes.comment).firstChild; + return roll.data = "Rolled " + dicestats[1] + "d" + dicestats[2] + " and got " + (roll.data.slice(7)); + } + }; + Emoji = { init: function() { var css, icon, name, pos, _ref; @@ -9636,7 +9665,7 @@ return Time.zeroPad(this.getSeconds()); }, y: function() { - return this.getFullYear() % 100; + return this.getFullYear().toString().slice(2); }, Y: function() { return this.getFullYear(); @@ -10456,7 +10485,8 @@ 'Thread Updater': ThreadUpdater, 'Thread Watcher': ThreadWatcher, 'Index Navigation': Nav, - 'Keybinds': Keybinds + 'Keybinds': Keybinds, + 'Show Dice Roll': Dice }); $.on(d, 'AddCallback', Main.addCallback); return $.ready(Main.initReady); diff --git a/json/archives.json b/json/archives.json index 15c52e369..95ac1a37a 100644 --- a/json/archives.json +++ b/json/archives.json @@ -103,6 +103,7 @@ "domain": "beta.foolz.us", "http": true, "https": true, + "withCredentials": true, "software": "foolfuuka", "boards": ["a", "co", "gd", "h", "jp", "m", "mlp", "q", "sp", "tg", "tv", "u", "v", "vg", "vp", "vr", "wsg"], "files": ["a", "gd", "h", "jp", "m", "q", "tg", "u", "vg", "vp", "vr", "wsg"] diff --git a/src/Archive/Redirect.coffee b/src/Archive/Redirect.coffee index 156d0d567..3f3904287 100644 --- a/src/Archive/Redirect.coffee +++ b/src/Archive/Redirect.coffee @@ -56,7 +56,8 @@ Redirect = 'Foolz Beta': domain: 'beta.foolz.us' http: true - https: true, + https: true + withCredentials: true software: 'foolfuuka' boards: ['a', 'co', 'gd', 'h', 'jp', 'm', 'mlp', 'q', 'sp', 'tg', 'tv', 'u', 'v', 'vg', 'vp', 'vr', 'wsg'], files: ['a', 'gd', 'h', 'jp', 'm', 'q', 'tg', 'u', 'vg', 'vp', 'vr', 'wsg'] @@ -150,7 +151,9 @@ Redirect = # Remove necessary HTTPS procotol in September 2013. if ['Foolz', 'NSFW Foolz'].contains archive.name protocol = 'https://' - "#{protocol}#{archive.domain}/_/api/chan/post/?board=#{boardID}&num=#{postID}" + URL = new String "#{protocol}#{archive.domain}/_/api/chan/post/?board=#{boardID}&num=#{postID}" + URL.archive = archive + URL file: (archive, {boardID, filename}) -> "#{Redirect.protocol archive}#{archive.domain}/#{boardID}/full_image/#{filename}" diff --git a/src/General/Config.coffee b/src/General/Config.coffee index dff2c4219..819779b89 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -53,6 +53,10 @@ Config = false 'Add buttons to navigate to top / bottom of thread.' ] + 'Show Dice Roll': [ + true + 'Show dice that were entered into the email field.' + ] <% if (type !== 'crx') { %> 'Check for Updates': [ true diff --git a/src/General/Get.coffee b/src/General/Get.coffee index 43787f62d..6b9d94e86 100644 --- a/src/General/Get.coffee +++ b/src/General/Get.coffee @@ -71,8 +71,10 @@ Get = $.cache "//api.4chan.org/#{boardID}/res/#{threadID}.json", -> Get.fetchedPost @, boardID, threadID, postID, root, context else if url = Redirect.to 'post', {boardID, postID} - $.cache url, -> - Get.archivedPost @, boardID, postID, root, context + $.cache url, + -> Get.archivedPost @, boardID, postID, root, context + , + withCredentials: url.archive.withCredentials insert: (post, root, context) -> # Stop here if the container has been removed while loading. return unless root.parentNode @@ -97,8 +99,10 @@ Get = unless [200, 304].contains status # The thread can die by the time we check a quote. if url = Redirect.to 'post', {boardID, postID} - $.cache url, -> - Get.archivedPost @, boardID, postID, root, context + $.cache url, + -> Get.archivedPost @, boardID, postID, root, context + , + withCredentials: url.archive.withCredentials else $.addClass root, 'warning' root.textContent = @@ -115,8 +119,10 @@ Get = if post.no > postID # The post can be deleted by the time we check a quote. if url = Redirect.to 'post', {boardID, postID} - $.cache url, -> - Get.archivedPost @, boardID, postID, root, context + $.cache url, + -> Get.archivedPost @, boardID, postID, root, context + , + withCredentials: url.archive.withCredentials else $.addClass root, 'warning' root.textContent = "Post No.#{postID} was not found." @@ -228,4 +234,4 @@ Get = when '[banned]' '' when '[/banned]' - '' \ No newline at end of file + '' diff --git a/src/General/Main.coffee b/src/General/Main.coffee index e4deba2bc..86b92e391 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -128,6 +128,7 @@ Main = 'Thread Watcher': ThreadWatcher 'Index Navigation': Nav 'Keybinds': Keybinds + 'Show Dice Roll': Dice # c.timeEnd 'All initializations' diff --git a/src/General/lib/$.coffee b/src/General/lib/$.coffee index 34a0e8af7..238c79a0b 100644 --- a/src/General/lib/$.coffee +++ b/src/General/lib/$.coffee @@ -72,7 +72,7 @@ $.ajax = (url, options, extra={}) -> $.cache = do -> reqs = {} - (url, cb) -> + (url, cb, options) -> if req = reqs[url] if req.readyState is 4 cb.call req, req.evt @@ -81,15 +81,14 @@ $.cache = do -> return rm = -> delete reqs[url] try - req = $.ajax url, - onload: (e) -> - cb.call @, e for cb in @callbacks - @evt = e - delete @callbacks - onabort: rm - onerror: rm + req = $.ajax url, options catch err return + $.on req, 'load', (e) -> + cb.call @, e for cb in @callbacks + @evt = e + delete @callbacks + $.on req, 'abort error', rm req.callbacks = [cb] reqs[url] = req diff --git a/src/Miscellaneous/Dice.coffee b/src/Miscellaneous/Dice.coffee new file mode 100644 index 000000000..93bdb06cd --- /dev/null +++ b/src/Miscellaneous/Dice.coffee @@ -0,0 +1,11 @@ +Dice = + init: -> + return if g.BOARD.ID isnt 'tg' or g.VIEW is 'catalog' or !Conf['Show Dice Roll'] + Post::callbacks.push + name: 'Show Dice Roll' + cb: @node + node: -> + return if @isClone or not dicestats = @info.email?.match /dice[+\s](\d+)d(\d+)/ + # Use the text node directly, as the has two
. + roll = $('b', @nodes.comment).firstChild + roll.data = "Rolled #{dicestats[1]}d#{dicestats[2]} and got #{roll.data.slice 7}" diff --git a/src/Miscellaneous/Time.coffee b/src/Miscellaneous/Time.coffee index c772792cc..540cfb637 100644 --- a/src/Miscellaneous/Time.coffee +++ b/src/Miscellaneous/Time.coffee @@ -56,5 +56,6 @@ Time = p: -> if @getHours() < 12 then 'AM' else 'PM' P: -> if @getHours() < 12 then 'am' else 'pm' S: -> Time.zeroPad @getSeconds() - y: -> @getFullYear() % 100 - Y: -> @getFullYear() \ No newline at end of file + y: -> @getFullYear().toString()[2..] + Y: -> @getFullYear() +