Change announcement hiding link to FontAwesome minus button and make it work on Tinyboard/vichan sites. #2171
This commit is contained in:
parent
5af268c602
commit
bbccf5e1b8
@ -1,15 +1,17 @@
|
||||
PSAHiding =
|
||||
init: ->
|
||||
return unless Conf['Announcement Hiding']
|
||||
return unless Conf['Announcement Hiding'] and g.SITE.selectors.psa
|
||||
$.addClass doc, 'hide-announcement'
|
||||
$.one d, '4chanXInitFinished', @setup
|
||||
$.onExists doc, g.SITE.selectors.psa, @setup
|
||||
$.ready ->
|
||||
$.rmClass doc, 'hide-announcement' if !$(g.SITE.selectors.psa)
|
||||
|
||||
setup: ->
|
||||
if not (psa = PSAHiding.psa = $.id 'globalMessage')
|
||||
$.rmClass doc, 'hide-announcement'
|
||||
return
|
||||
if (hr = $.id('globalToggle')?.previousElementSibling) and hr.nodeName is 'HR'
|
||||
setup: (psa) ->
|
||||
PSAHiding.psa = psa
|
||||
PSAHiding.text = psa.dataset.utc ? psa.innerHTML
|
||||
if g.SITE.selectors.psaTop and (hr = $(g.SITE.selectors.psaTop)?.previousElementSibling) and hr.nodeName is 'HR'
|
||||
PSAHiding.hr = hr
|
||||
PSAHiding.content = $.el 'div'
|
||||
|
||||
entry =
|
||||
el: $.el 'a',
|
||||
@ -17,40 +19,44 @@ PSAHiding =
|
||||
className: 'show-announcement'
|
||||
href: 'javascript:;'
|
||||
order: 50
|
||||
open: -> PSAHiding.hidden
|
||||
open: -> psa.hidden
|
||||
Header.menu.addEntry entry
|
||||
$.on entry.el, 'click', PSAHiding.toggle
|
||||
|
||||
PSAHiding.btn = btn = $.el 'span',
|
||||
PSAHiding.btn = btn = $.el 'a',
|
||||
title: 'Mark announcement as read and hide.'
|
||||
className: 'hide-announcement'
|
||||
|
||||
$.extend btn, <%= html('[<a href="javascript:;">Dismiss</a>]') %>
|
||||
|
||||
className: 'hide-announcement-button fa fa-minus-square'
|
||||
href: 'javascript:;'
|
||||
$.on btn, 'click', PSAHiding.toggle
|
||||
if psa.firstChild?.tagName is 'HR'
|
||||
$.after psa.firstChild, btn
|
||||
else
|
||||
$.prepend psa, btn
|
||||
|
||||
$.get 'hiddenPSA', 0, ({hiddenPSA}) ->
|
||||
PSAHiding.sync hiddenPSA
|
||||
$.add psa, btn
|
||||
$.rmClass doc, 'hide-announcement'
|
||||
PSAHiding.sync Conf['hiddenPSAList']
|
||||
$.rmClass doc, 'hide-announcement'
|
||||
|
||||
$.sync 'hiddenPSA', PSAHiding.sync
|
||||
$.sync 'hiddenPSAList', PSAHiding.sync
|
||||
|
||||
toggle: ->
|
||||
if $.hasClass @, 'hide-announcement'
|
||||
UTC = +$.id('globalMessage').dataset.utc
|
||||
$.set 'hiddenPSA', UTC
|
||||
else
|
||||
$.event 'CloseMenu'
|
||||
$.delete 'hiddenPSA'
|
||||
PSAHiding.sync UTC
|
||||
hide = $.hasClass @, 'hide-announcement-button'
|
||||
set = (hiddenPSAList) ->
|
||||
if hide
|
||||
hiddenPSAList[g.SITE.ID] = PSAHiding.text
|
||||
else
|
||||
delete hiddenPSAList[g.SITE.ID]
|
||||
set Conf['hiddenPSAList']
|
||||
PSAHiding.sync Conf['hiddenPSAList']
|
||||
$.get 'hiddenPSAList', Conf['hiddenPSAList'], ({hiddenPSAList}) ->
|
||||
set hiddenPSAList
|
||||
$.set 'hiddenPSAList', hiddenPSAList
|
||||
|
||||
sync: (UTC) ->
|
||||
{psa} = PSAHiding
|
||||
PSAHiding.hidden = PSAHiding.btn.hidden = UTC? and UTC >= +psa.dataset.utc
|
||||
if PSAHiding.hidden
|
||||
$.rm psa
|
||||
sync: (hiddenPSAList) ->
|
||||
{psa, content} = PSAHiding
|
||||
psa.hidden = (hiddenPSAList[g.SITE.ID] is PSAHiding.text)
|
||||
# Remove content to prevent autoplaying sounds from hidden announcements
|
||||
if psa.hidden
|
||||
$.add content, [psa.childNodes...]
|
||||
else
|
||||
$.after $.id('globalToggle'), psa
|
||||
PSAHiding.hr?.hidden = PSAHiding.hidden
|
||||
return
|
||||
$.add psa, [content.childNodes...]
|
||||
PSAHiding.hr?.hidden = psa.hidden
|
||||
|
||||
@ -1162,3 +1162,5 @@ Config =
|
||||
}]
|
||||
|
||||
fourchanImageHost: 'i.4cdn.org'
|
||||
|
||||
hiddenPSAList: [{}]
|
||||
|
||||
@ -1056,18 +1056,12 @@ textarea.copy-text-element {
|
||||
}
|
||||
|
||||
/* Announcement Hiding */
|
||||
:root.hide-announcement #globalMessage {
|
||||
:root.hide-announcement $site$psa {
|
||||
display: none;
|
||||
}
|
||||
span.hide-announcement {
|
||||
font-size: 11px;
|
||||
position: relative;
|
||||
bottom: 5px;
|
||||
}
|
||||
.globalMessage, h2, h3 {
|
||||
color: inherit !important;
|
||||
font-size: 13px;
|
||||
font-weight: 100;
|
||||
.hide-announcement-button {
|
||||
opacity: 0.4;
|
||||
float: left;
|
||||
}
|
||||
|
||||
/* Unread */
|
||||
|
||||
@ -664,7 +664,7 @@ if GM?.deleteValue? and window.BroadcastChannel and not GM_addValueChangeListene
|
||||
GM.listValues().then((keys) ->
|
||||
$.delete keys.map((key) -> key.replace g.NAMESPACE, ''), cb
|
||||
).catch( ->
|
||||
$.delete Object.keys(Conf).concat(['previousversion', 'QR Size', 'QR.persona', 'hiddenPSA']), cb
|
||||
$.delete Object.keys(Conf).concat(['previousversion', 'QR Size', 'QR.persona']), cb
|
||||
)
|
||||
else
|
||||
|
||||
@ -778,7 +778,7 @@ else
|
||||
# XXX https://github.com/greasemonkey/greasemonkey/issues/2033
|
||||
# Also support case where GM_listValues is not defined.
|
||||
$.delete Object.keys(Conf)
|
||||
$.delete ['previousversion', 'QR Size', 'QR.persona', 'hiddenPSA']
|
||||
$.delete ['previousversion', 'QR Size', 'QR.persona']
|
||||
try
|
||||
$.delete $.listValues().map (key) -> key.replace g.NAMESPACE, ''
|
||||
cb?()
|
||||
|
||||
@ -4,7 +4,6 @@ SW.tinyboard =
|
||||
|
||||
disabledFeatures: [
|
||||
'Index Generator'
|
||||
'Announcement Hiding'
|
||||
'Resurrect Quotes'
|
||||
'Quick Reply Personas'
|
||||
'Quick Reply'
|
||||
@ -96,6 +95,7 @@ SW.tinyboard =
|
||||
boardList: '.boardlist'
|
||||
boardListBottom: '.boardlist.bottom'
|
||||
styleSheet: '#stylesheet'
|
||||
psa: '.blotter'
|
||||
|
||||
xpath:
|
||||
thread: 'div[starts-with(@id,"thread_")]'
|
||||
|
||||
@ -52,6 +52,8 @@ SW.yotsuba =
|
||||
boardList: '#boardNavDesktop > .boardList'
|
||||
boardListBottom: '#boardNavDesktopFoot > .boardList'
|
||||
styleSheet: 'link[title=switch]'
|
||||
psa: '#globalMessage'
|
||||
psaTop: '#globalToggle'
|
||||
|
||||
xpath:
|
||||
thread: 'div[contains(concat(" ",@class," ")," thread ")]'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user