From 872612ad9fc32abaa0af9554895af4df7411fe75 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 10 Jan 2015 00:35:27 -0700 Subject: [PATCH] Add missing classes --- builds/appchan-x.user.js | 66 +++++++++++++++++++++++++++++++- builds/crx/script.js | 66 +++++++++++++++++++++++++++++++- src/General/lib/classes.coffee | 4 +- src/General/lib/connection.class | 16 ++++++++ src/General/lib/set.class | 16 ++++++++ 5 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 src/General/lib/connection.class create mode 100644 src/General/lib/set.class diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 8fdd5e184..de2e61d9f 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -115,7 +115,7 @@ 'use strict'; (function() { - var $, $$, Anonymize, AntiAutoplay, ArchiveLink, Banner, Board, Build, Callbacks, Captcha, CatalogLinks, CatalogThread, Clone, Color, Conf, Config, CrossOrigin, CustomCSS, DataBoard, DeleteLink, Dice, DownloadLink, E, Embedding, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Flash, Fourchan, Gallery, Get, GlobalMessage, Header, IDColor, IDHighlight, ImageCommon, ImageExpand, ImageHover, ImageLoader, Index, JSColor, Keybinds, Linkify, Main, MarkNewIPs, MascotTools, Mascots, Menu, Nav, Navigate, Notice, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteInline, QuoteMarkers, QuotePreview, QuoteStrikeThrough, QuoteThreading, Quotify, RandomAccessList, Recursive, Redirect, RelativeDates, RemoveSpoilers, ReportLink, RevealSpoilers, Rice, Sauce, Settings, SimpleDict, Style, ThemeTools, Themes, Thread, ThreadExcerpt, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, editMascot, editTheme, g, userNavigation, + var $, $$, Anonymize, AntiAutoplay, ArchiveLink, Banner, Board, Build, Callbacks, Captcha, CatalogLinks, CatalogThread, Clone, Color, Conf, Config, Connection, CrossOrigin, CustomCSS, DataBoard, DeleteLink, Dice, DownloadLink, E, Embedding, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Flash, Fourchan, Gallery, Get, GlobalMessage, Header, IDColor, IDHighlight, ImageCommon, ImageExpand, ImageHover, ImageLoader, Index, JSColor, Keybinds, Linkify, Main, MarkNewIPs, MascotTools, Mascots, Menu, Nav, Navigate, Notice, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteInline, QuoteMarkers, QuotePreview, QuoteStrikeThrough, QuoteThreading, Quotify, RandomAccessList, Recursive, Redirect, RelativeDates, RemoveSpoilers, ReportLink, RevealSpoilers, Rice, Sauce, Settings, ShimSet, SimpleDict, Style, ThemeTools, Themes, Thread, ThreadExcerpt, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, editMascot, editTheme, g, userNavigation, __slice = [].slice, __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; }, __hasProp = {}.hasOwnProperty, @@ -4228,6 +4228,70 @@ })(); + ShimSet = (function() { + function ShimSet() { + this.elements = {}; + this.size = 0; + } + + ShimSet.prototype.has = function(value) { + return value in this.elements; + }; + + ShimSet.prototype.add = function(value) { + if (this.elements[value]) { + return; + } + this.elements[value] = true; + return this.size++; + }; + + ShimSet.prototype["delete"] = function(value) { + if (!this.elements[value]) { + return; + } + delete this.elements[value]; + return this.size--; + }; + + return ShimSet; + + })(); + + if (!('Set' in window)) { + window.Set = ShimSet; + } + + Connection = (function() { + function Connection(target, origin, cb) { + this.target = target; + this.origin = origin; + this.cb = cb; + $.on(window, 'message', this.onMessage.bind(this)); + } + + Connection.prototype.send = function(data) { + return this.target.postMessage("" + g.NAMESPACE + (JSON.stringify(data)), this.origin); + }; + + Connection.prototype.onMessage = function(e) { + var data, type, value, _base; + if (!(e.source === this.target && e.origin === this.origin && typeof e.data === 'string' && e.data.slice(0, g.NAMESPACE.length) === g.NAMESPACE)) { + return; + } + data = JSON.parse(e.data.slice(g.NAMESPACE.length)); + for (type in data) { + value = data[type]; + if (typeof (_base = this.cb)[type] === "function") { + _base[type](value); + } + } + }; + + return Connection; + + })(); + Polyfill = { init: function() {}, toBlob: function() { diff --git a/builds/crx/script.js b/builds/crx/script.js index 3563b931a..842fdf724 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -88,7 +88,7 @@ 'use strict'; (function() { - var $, $$, Anonymize, AntiAutoplay, ArchiveLink, Banner, Board, Build, Callbacks, Captcha, CatalogLinks, CatalogThread, Clone, Color, Conf, Config, CrossOrigin, CustomCSS, DataBoard, DeleteLink, Dice, DownloadLink, E, Embedding, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Flash, Fourchan, Gallery, Get, GlobalMessage, Header, IDColor, IDHighlight, ImageCommon, ImageExpand, ImageHover, ImageLoader, Index, JSColor, Keybinds, Linkify, Main, MarkNewIPs, MascotTools, Mascots, Menu, Nav, Navigate, Notice, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteInline, QuoteMarkers, QuotePreview, QuoteStrikeThrough, QuoteThreading, Quotify, RandomAccessList, Recursive, Redirect, RelativeDates, RemoveSpoilers, ReportLink, RevealSpoilers, Rice, Sauce, Settings, SimpleDict, Style, ThemeTools, Themes, Thread, ThreadExcerpt, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, editMascot, editTheme, g, userNavigation, + var $, $$, Anonymize, AntiAutoplay, ArchiveLink, Banner, Board, Build, Callbacks, Captcha, CatalogLinks, CatalogThread, Clone, Color, Conf, Config, Connection, CrossOrigin, CustomCSS, DataBoard, DeleteLink, Dice, DownloadLink, E, Embedding, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Flash, Fourchan, Gallery, Get, GlobalMessage, Header, IDColor, IDHighlight, ImageCommon, ImageExpand, ImageHover, ImageLoader, Index, JSColor, Keybinds, Linkify, Main, MarkNewIPs, MascotTools, Mascots, Menu, Nav, Navigate, Notice, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteInline, QuoteMarkers, QuotePreview, QuoteStrikeThrough, QuoteThreading, Quotify, RandomAccessList, Recursive, Redirect, RelativeDates, RemoveSpoilers, ReportLink, RevealSpoilers, Rice, Sauce, Settings, ShimSet, SimpleDict, Style, ThemeTools, Themes, Thread, ThreadExcerpt, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, editMascot, editTheme, g, userNavigation, __slice = [].slice, __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; }, __hasProp = {}.hasOwnProperty, @@ -4255,6 +4255,70 @@ })(); + ShimSet = (function() { + function ShimSet() { + this.elements = {}; + this.size = 0; + } + + ShimSet.prototype.has = function(value) { + return value in this.elements; + }; + + ShimSet.prototype.add = function(value) { + if (this.elements[value]) { + return; + } + this.elements[value] = true; + return this.size++; + }; + + ShimSet.prototype["delete"] = function(value) { + if (!this.elements[value]) { + return; + } + delete this.elements[value]; + return this.size--; + }; + + return ShimSet; + + })(); + + if (!('Set' in window)) { + window.Set = ShimSet; + } + + Connection = (function() { + function Connection(target, origin, cb) { + this.target = target; + this.origin = origin; + this.cb = cb; + $.on(window, 'message', this.onMessage.bind(this)); + } + + Connection.prototype.send = function(data) { + return this.target.postMessage("" + g.NAMESPACE + (JSON.stringify(data)), this.origin); + }; + + Connection.prototype.onMessage = function(e) { + var data, type, value, _base; + if (!(e.source === this.target && e.origin === this.origin && typeof e.data === 'string' && e.data.slice(0, g.NAMESPACE.length) === g.NAMESPACE)) { + return; + } + data = JSON.parse(e.data.slice(g.NAMESPACE.length)); + for (type in data) { + value = data[type]; + if (typeof (_base = this.cb)[type] === "function") { + _base[type](value); + } + } + }; + + return Connection; + + })(); + Polyfill = { init: function() { return this.toBlob(); diff --git a/src/General/lib/classes.coffee b/src/General/lib/classes.coffee index 2e3525006..7f579bf6d 100755 --- a/src/General/lib/classes.coffee +++ b/src/General/lib/classes.coffee @@ -7,4 +7,6 @@ <%= grunt.file.read('src/General/lib/databoard.class') %> <%= grunt.file.read('src/General/lib/notice.class') %> <%= grunt.file.read('src/General/lib/randomaccesslist.class') %> -<%= grunt.file.read('src/General/lib/simpledict.class') %> \ No newline at end of file +<%= grunt.file.read('src/General/lib/simpledict.class') %> +<%= grunt.file.read('src/General/lib/set.class') %> +<%= grunt.file.read('src/General/lib/connection.class') %> \ No newline at end of file diff --git a/src/General/lib/connection.class b/src/General/lib/connection.class new file mode 100644 index 000000000..455948563 --- /dev/null +++ b/src/General/lib/connection.class @@ -0,0 +1,16 @@ +class Connection + constructor: (@target, @origin, @cb) -> + $.on window, 'message', @onMessage.bind @ + + send: (data) -> + @target.postMessage "#{g.NAMESPACE}#{JSON.stringify data}", @origin + + onMessage: (e) -> + return unless e.source is @target and + e.origin is @origin and + typeof e.data is 'string' and + e.data[...g.NAMESPACE.length] is g.NAMESPACE + data = JSON.parse e.data[g.NAMESPACE.length..] + for type, value of data + @cb[type]? value + return diff --git a/src/General/lib/set.class b/src/General/lib/set.class new file mode 100644 index 000000000..b48d6e160 --- /dev/null +++ b/src/General/lib/set.class @@ -0,0 +1,16 @@ +class ShimSet + constructor: -> + @elements = {} + @size = 0 + has: (value) -> + value of @elements + add: (value) -> + return if @elements[value] + @elements[value] = true + @size++ + delete: (value) -> + return unless @elements[value] + delete @elements[value] + @size-- + +window.Set = ShimSet unless 'Set' of window