diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index ae991b9db..044f7b5d0 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -115,7 +115,7 @@ 'use strict'; (function() { - var $, $$, Anonymize, ArchiveLink, Banner, Board, Build, Callbacks, 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, 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, Report, 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, 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, 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, Report, ReportLink, RevealSpoilers, Rice, Sauce, Settings, 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, @@ -12673,16 +12673,19 @@ Menu = { init: function() { - var a; - if (!Conf['Menu']) { + var _ref; + if (!(((_ref = g.VIEW) === 'index' || _ref === 'thread') && Conf['Menu'])) { return; } - a = $.el('a', { + this.button = $.el('a', { className: 'menu-button', innerHTML: '', href: 'javascript:;' }); - this.menu = new UI.Menu(); + $.extend(this.button, { + innerHTML: "" + }); + this.menu = new UI.Menu('post'); Post.callbacks.push({ name: 'Menu', cb: this.node @@ -12694,39 +12697,27 @@ }, node: function() { if (this.isClone) { - $.on($('.menu-button', this.nodes.info), 'click', Menu.toggle); + Menu.makeButton(this, $('.menu-button', this.nodes.info)); return; } - return $.add(this.nodes.info, Menu.makeButton()); + return $.add(this.nodes.info, Menu.makeButton(this)); }, catalogNode: function() { - return $.add(this.nodes.thumb, Menu.makeButton()); + return $.after(this.nodes.icons, Menu.makeButton(this.thread.OP)); }, - makeButton: (function() { - var a; - a = $.el('a', { - className: 'menu-button', - innerHTML: '\uf107', - href: 'javascript:;' + makeButton: function(post, button) { + button || (button = Menu.button.cloneNode(true)); + $.on(button, 'click', function(e) { + return Menu.menu.toggle(e, this, post); }); - return function() { - var clone; - clone = a.cloneNode(true); - $.on(clone, 'click', Menu.toggle); - return clone; - }; - })(), - toggle: function(e) { - var fullID; - fullID = $.x('ancestor::*[@data-full-i-d][1]', this).dataset.fullID; - return Menu.menu.toggle(e, this, g.posts[fullID]); + return button; } }; ReportLink = { init: function() { - var a; - if (!Conf['Menu'] || !Conf['Report Link']) { + var a, _ref; + if (!(((_ref = g.VIEW) === 'index' || _ref === 'thread') && Conf['Menu'] && Conf['Report Link'])) { return; } a = $.el('a', { @@ -12749,7 +12740,7 @@ post = ReportLink.post; url = "//sys.4chan.org/" + post.board + "/imgboard.php?mode=report&no=" + post; id = Date.now(); - set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200"; + set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=285"; return window.open(url, id, set); } }; @@ -14367,6 +14358,7 @@ var btn, entry, psa; $.off(d, '4chanXInitFinished', PSAHiding.setup); if (!(psa = $.id('globalMessage'))) { + $.rmClass(doc, 'hide-announcement'); return; } entry = { @@ -14383,11 +14375,12 @@ Header.menu.addEntry(entry); $.on(entry.el, 'click', PSAHiding.toggle); PSAHiding.btn = btn = $.el('span', { - innerHTML: '[Dismiss]', title: 'Mark announcement as read and hide.', className: 'hide-announcement', - href: 'javascript:;', - textContent: '[ - ]' + href: 'javascript:;' + }); + $.extend(btn, { + innerHTML: "[Dismiss]" }); $.on(btn, 'click', PSAHiding.toggle); $.get('hiddenPSA', 0, function(_arg) { @@ -14420,6 +14413,64 @@ } }; + AntiAutoplay = { + init: function() { + var audio, _i, _len, _ref; + if (!Conf['Disable Autoplaying Sounds']) { + return; + } + $.addClass(doc, 'anti-autoplay'); + _ref = $$('audio[autoplay]', doc); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + audio = _ref[_i]; + this.stop(audio); + } + window.addEventListener('loadstart', ((function(_this) { + return function(e) { + return _this.stop(e.target); + }; + })(this)), true); + Post.callbacks.push({ + name: 'Disable Autoplaying Sounds', + cb: this.node + }); + CatalogThread.callbacks.push({ + name: 'Disable Autoplaying Sounds', + cb: this.node + }); + return $.ready((function(_this) { + return function() { + return _this.process(d.body); + }; + })(this)); + }, + stop: function(audio) { + if (!audio.autoplay) { + return; + } + audio.pause(); + audio.autoplay = false; + if (audio.controls) { + return; + } + audio.controls = true; + return $.addClass(audio, 'controls-added'); + }, + node: function() { + return AntiAutoplay.process(this.nodes.root); + }, + process: function(root) { + var iframe, _i, _len, _ref, _results; + _ref = $$('iframe[src*="youtube"][src*="autoplay=1"]', root); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + iframe = _ref[_i]; + _results.push(iframe.src = iframe.src.replace(/\?autoplay=1&?/, '?').replace('&autoplay=1', '')); + } + return _results; + } + }; + CatalogLinks = { init: function() { var el, input; diff --git a/builds/crx/script.js b/builds/crx/script.js index 03faff257..c08a4a8e3 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -88,7 +88,7 @@ 'use strict'; (function() { - var $, $$, Anonymize, ArchiveLink, Banner, Board, Build, Callbacks, 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, 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, Report, 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, 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, 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, Report, ReportLink, RevealSpoilers, Rice, Sauce, Settings, 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, @@ -12695,16 +12695,19 @@ Menu = { init: function() { - var a; - if (!Conf['Menu']) { + var _ref; + if (!(((_ref = g.VIEW) === 'index' || _ref === 'thread') && Conf['Menu'])) { return; } - a = $.el('a', { + this.button = $.el('a', { className: 'menu-button', innerHTML: '', href: 'javascript:;' }); - this.menu = new UI.Menu(); + $.extend(this.button, { + innerHTML: "" + }); + this.menu = new UI.Menu('post'); Post.callbacks.push({ name: 'Menu', cb: this.node @@ -12716,39 +12719,27 @@ }, node: function() { if (this.isClone) { - $.on($('.menu-button', this.nodes.info), 'click', Menu.toggle); + Menu.makeButton(this, $('.menu-button', this.nodes.info)); return; } - return $.add(this.nodes.info, Menu.makeButton()); + return $.add(this.nodes.info, Menu.makeButton(this)); }, catalogNode: function() { - return $.add(this.nodes.thumb, Menu.makeButton()); + return $.after(this.nodes.icons, Menu.makeButton(this.thread.OP)); }, - makeButton: (function() { - var a; - a = $.el('a', { - className: 'menu-button', - innerHTML: '\uf107', - href: 'javascript:;' + makeButton: function(post, button) { + button || (button = Menu.button.cloneNode(true)); + $.on(button, 'click', function(e) { + return Menu.menu.toggle(e, this, post); }); - return function() { - var clone; - clone = a.cloneNode(true); - $.on(clone, 'click', Menu.toggle); - return clone; - }; - })(), - toggle: function(e) { - var fullID; - fullID = $.x('ancestor::*[@data-full-i-d][1]', this).dataset.fullID; - return Menu.menu.toggle(e, this, g.posts[fullID]); + return button; } }; ReportLink = { init: function() { - var a; - if (!Conf['Menu'] || !Conf['Report Link']) { + var a, _ref; + if (!(((_ref = g.VIEW) === 'index' || _ref === 'thread') && Conf['Menu'] && Conf['Report Link'])) { return; } a = $.el('a', { @@ -12771,7 +12762,7 @@ post = ReportLink.post; url = "//sys.4chan.org/" + post.board + "/imgboard.php?mode=report&no=" + post; id = Date.now(); - set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200"; + set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=285"; return window.open(url, id, set); } }; @@ -14388,6 +14379,7 @@ var btn, entry, psa; $.off(d, '4chanXInitFinished', PSAHiding.setup); if (!(psa = $.id('globalMessage'))) { + $.rmClass(doc, 'hide-announcement'); return; } entry = { @@ -14404,11 +14396,12 @@ Header.menu.addEntry(entry); $.on(entry.el, 'click', PSAHiding.toggle); PSAHiding.btn = btn = $.el('span', { - innerHTML: '[Dismiss]', title: 'Mark announcement as read and hide.', className: 'hide-announcement', - href: 'javascript:;', - textContent: '[ - ]' + href: 'javascript:;' + }); + $.extend(btn, { + innerHTML: "[Dismiss]" }); $.on(btn, 'click', PSAHiding.toggle); $.get('hiddenPSA', 0, function(_arg) { @@ -14441,6 +14434,64 @@ } }; + AntiAutoplay = { + init: function() { + var audio, _i, _len, _ref; + if (!Conf['Disable Autoplaying Sounds']) { + return; + } + $.addClass(doc, 'anti-autoplay'); + _ref = $$('audio[autoplay]', doc); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + audio = _ref[_i]; + this.stop(audio); + } + window.addEventListener('loadstart', ((function(_this) { + return function(e) { + return _this.stop(e.target); + }; + })(this)), true); + Post.callbacks.push({ + name: 'Disable Autoplaying Sounds', + cb: this.node + }); + CatalogThread.callbacks.push({ + name: 'Disable Autoplaying Sounds', + cb: this.node + }); + return $.ready((function(_this) { + return function() { + return _this.process(d.body); + }; + })(this)); + }, + stop: function(audio) { + if (!audio.autoplay) { + return; + } + audio.pause(); + audio.autoplay = false; + if (audio.controls) { + return; + } + audio.controls = true; + return $.addClass(audio, 'controls-added'); + }, + node: function() { + return AntiAutoplay.process(this.nodes.root); + }, + process: function(root) { + var iframe, _i, _len, _ref, _results; + _ref = $$('iframe[src*="youtube"][src*="autoplay=1"]', root); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + iframe = _ref[_i]; + _results.push(iframe.src = iframe.src.replace(/\?autoplay=1&?/, '?').replace('&autoplay=1', '')); + } + return _results; + } + }; + CatalogLinks = { init: function() { var el, input; diff --git a/src/Menu/Menu.coffee b/src/Menu/Menu.coffee index 262523855..8b3655ff1 100644 --- a/src/Menu/Menu.coffee +++ b/src/Menu/Menu.coffee @@ -1,13 +1,15 @@ Menu = init: -> - return if !Conf['Menu'] + return unless g.VIEW in ['index', 'thread'] and Conf['Menu'] - a = $.el 'a', + @button = $.el 'a', className: 'menu-button' innerHTML: '' href: 'javascript:;' - @menu = new UI.Menu() + $.extend @button, <%= html('') %> + + @menu = new UI.Menu 'post' Post.callbacks.push name: 'Menu' cb: @node @@ -18,22 +20,15 @@ Menu = node: -> if @isClone - $.on $('.menu-button', @nodes.info), 'click', Menu.toggle + Menu.makeButton @, $('.menu-button', @nodes.info) return - $.add @nodes.info, Menu.makeButton() + $.add @nodes.info, Menu.makeButton @ + catalogNode: -> - $.add @nodes.thumb, Menu.makeButton() + $.after @nodes.icons, Menu.makeButton @thread.OP - makeButton: do -> - a = $.el 'a', - className: 'menu-button' - innerHTML: '\uf107' - href: 'javascript:;' - -> - clone = a.cloneNode true - $.on clone, 'click', Menu.toggle - clone - - toggle: (e) -> - fullID = $.x('ancestor::*[@data-full-i-d][1]', @).dataset.fullID - Menu.menu.toggle e, @, g.posts[fullID] + makeButton: (post, button) -> + button or= Menu.button.cloneNode true + $.on button, 'click', (e) -> + Menu.menu.toggle e, @, post + button diff --git a/src/Menu/ReportLink.coffee b/src/Menu/ReportLink.coffee index 58d2dc6bb..73b60a661 100755 --- a/src/Menu/ReportLink.coffee +++ b/src/Menu/ReportLink.coffee @@ -1,6 +1,6 @@ ReportLink = init: -> - return if !Conf['Menu'] or !Conf['Report Link'] + return unless g.VIEW in ['index', 'thread'] and Conf['Menu'] and Conf['Report Link'] a = $.el 'a', className: 'report-link' @@ -17,5 +17,5 @@ ReportLink = {post} = ReportLink url = "//sys.4chan.org/#{post.board}/imgboard.php?mode=report&no=#{post}" id = Date.now() - set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=200" + set = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1,width=685,height=285" window.open url, id, set diff --git a/src/Miscellaneous/AnnouncementHiding.coffee b/src/Miscellaneous/AnnouncementHiding.coffee index 23d86cc56..7ddb99dc1 100755 --- a/src/Miscellaneous/AnnouncementHiding.coffee +++ b/src/Miscellaneous/AnnouncementHiding.coffee @@ -8,6 +8,7 @@ PSAHiding = $.off d, '4chanXInitFinished', PSAHiding.setup unless psa = $.id 'globalMessage' + $.rmClass doc, 'hide-announcement' return entry = @@ -21,11 +22,11 @@ PSAHiding = $.on entry.el, 'click', PSAHiding.toggle PSAHiding.btn = btn = $.el 'span', - innerHTML: '[Dismiss]' title: 'Mark announcement as read and hide.' className: 'hide-announcement' href: 'javascript:;' - textContent: '[ - ]' + + $.extend btn, <%= html('[Dismiss]') %> $.on btn, 'click', PSAHiding.toggle diff --git a/src/Miscellaneous/AntiAutoplay.coffee b/src/Miscellaneous/AntiAutoplay.coffee new file mode 100644 index 000000000..5ea2e61e3 --- /dev/null +++ b/src/Miscellaneous/AntiAutoplay.coffee @@ -0,0 +1,28 @@ +AntiAutoplay = + init: -> + return if !Conf['Disable Autoplaying Sounds'] + $.addClass doc, 'anti-autoplay' + @stop audio for audio in $$ 'audio[autoplay]', doc + window.addEventListener 'loadstart', ((e) => @stop e.target), true + Post.callbacks.push + name: 'Disable Autoplaying Sounds' + cb: @node + CatalogThread.callbacks.push + name: 'Disable Autoplaying Sounds' + cb: @node + $.ready => @process d.body + + stop: (audio) -> + return unless audio.autoplay + audio.pause() + audio.autoplay = false + return if audio.controls + audio.controls = true + $.addClass audio, 'controls-added' + + node: -> + AntiAutoplay.process @nodes.root + + process: (root) -> + for iframe in $$ 'iframe[src*="youtube"][src*="autoplay=1"]', root + iframe.src = iframe.src.replace(/\?autoplay=1&?/, '?').replace('&autoplay=1', '') \ No newline at end of file