diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b9aeb50c..4729f608d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- **New feature**: `Announcement Hiding`, enabled by default. - Fix support for www.4chan.org/frames on Chrome. - Fix quote features not working on dead quotelinks in inlined posts. - Fix resurrecting dead quotelinks on HTTP. diff --git a/css/style.css b/css/style.css index 30d916302..0dcd18830 100644 --- a/css/style.css +++ b/css/style.css @@ -370,6 +370,11 @@ a[href="javascript:;"] { overflow: hidden; } +/* Announcement Hiding */ +:root.hide-announcement #globalMessage { + display: none; +} + /* Unread */ #unread-line { margin: 0; diff --git a/src/config.coffee b/src/config.coffee index bd1452991..acc178684 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -3,6 +3,7 @@ Config = 'Miscellaneous': 'Enable 4chan\'s Extension': [false, 'Compatibility between <%= meta.name %> and 4chan\'s inline extension is NOT guaranteed.'] 'Custom Board Navigation': [true, 'Show custom links instead of the full board list'] + 'Announcement Hiding': [true, 'Add button to hide 4chan announcements.'] '404 Redirect': [true, 'Redirect dead threads and images.'] 'Keybinds': [true, 'Bind actions to keyboard shortcuts.'] 'Time Formatting': [true, 'Localize and format timestamps.'] diff --git a/src/features.coffee b/src/features.coffee index 8333a410e..a55f4168b 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -783,6 +783,55 @@ Settings = @value = key $.cb.value.call @ +PSAHiding = + init: -> + return if !Conf['Announcement Hiding'] + + $.addClass doc, 'hide-announcement' + + $.on d, '4chanXInitFinished', @setup + setup: -> + $.off d, '4chanXInitFinished', PSAHiding.setup + + unless psa = $.id 'globalMessage' + $.rmClass doc, 'hide-announcement' + return + + PSAHiding.btn = btn = $.el 'a', + title: 'Toggle announcement.' + href: 'javascript:;' + $.on btn, 'click', PSAHiding.toggle + + text = PSAHiding.trim psa + $.get 'hiddenPSAs', [], (item) -> + PSAHiding.sync item['hiddenPSAs'] + $.before psa, btn + $.rmClass doc, 'hide-announcement' + + $.sync 'hiddenPSAs', PSAHiding.sync + toggle: (e) -> + hide = $.hasClass @, 'hide-announcement' + text = PSAHiding.trim $.id 'globalMessage' + $.get 'hiddenPSAs', [], (item) -> + {hiddenPSAs} = item + if hide + hiddenPSAs.push text + else + i = hiddenPSAs.indexOf text + hiddenPSAs.splice i, 1 + hiddenPSAs = hiddenPSAs[-5..] + PSAHiding.sync hiddenPSAs + $.set 'hiddenPSAs', hiddenPSAs + sync: (hiddenPSAs) -> + {btn} = PSAHiding + psa = $.id 'globalMessage' + [psa.hidden, btn.innerHTML, btn.className] = if PSAHiding.trim(psa) in hiddenPSAs + [true, '[ + ]', 'show-announcement'] + else + [false, '[ - ]', 'hide-announcement'] + trim: (psa) -> + psa.textContent.replace(/\W+/g, '').toLowerCase() + Fourchan = init: -> return if g.VIEW is 'catalog' diff --git a/src/main.coffee b/src/main.coffee index b59e18916..c99e13483 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -346,6 +346,7 @@ Main = initFeature 'Polyfill', Polyfill initFeature 'Header', Header initFeature 'Settings', Settings + initFeature 'Announcement Hiding', PSAHiding initFeature 'Fourchan thingies', Fourchan initFeature 'Custom CSS', CustomCSS initFeature 'Resurrect Quotes', Quotify