add $.event
This commit is contained in:
parent
fec837ecdc
commit
f4f53b92f2
211
4chan_x.user.js
211
4chan_x.user.js
@ -780,6 +780,11 @@
|
||||
el.removeEventListener(event, handler, false);
|
||||
}
|
||||
},
|
||||
event: function(event, detail) {
|
||||
return d.dispatchEvent(new CustomEvent(event, {
|
||||
detail: detail
|
||||
}));
|
||||
},
|
||||
open: function(url) {
|
||||
return (GM_openInTab || window.open)(url, '_blank');
|
||||
},
|
||||
@ -1017,12 +1022,10 @@
|
||||
href: 'javascript:;'
|
||||
});
|
||||
$.on(link, 'click', Settings.open);
|
||||
d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: {
|
||||
type: 'header',
|
||||
el: link
|
||||
}
|
||||
}));
|
||||
$.event('AddMenuEntry', {
|
||||
type: 'header',
|
||||
el: link
|
||||
});
|
||||
link = $.el('a', {
|
||||
className: 'fourchan-settings-link',
|
||||
textContent: '4chan Settings',
|
||||
@ -1031,15 +1034,13 @@
|
||||
$.on(link, 'click', function() {
|
||||
return $.id('settingsWindowLink').click();
|
||||
});
|
||||
d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: {
|
||||
type: 'header',
|
||||
el: link,
|
||||
open: function() {
|
||||
return !Conf['Disable 4chan\'s extension'];
|
||||
}
|
||||
$.event('AddMenuEntry', {
|
||||
type: 'header',
|
||||
el: link,
|
||||
open: function() {
|
||||
return !Conf['Disable 4chan\'s extension'];
|
||||
}
|
||||
}));
|
||||
});
|
||||
if (!Conf['Disable 4chan\'s extension']) {
|
||||
return;
|
||||
}
|
||||
@ -1275,9 +1276,7 @@
|
||||
type = _ref[_i];
|
||||
entry.subEntries.push(Filter.menu.createSubEntry(type[0], type[1]));
|
||||
}
|
||||
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: entry
|
||||
}));
|
||||
return $.event('AddMenuEntry', entry);
|
||||
},
|
||||
createSubEntry: function(text, type) {
|
||||
var el;
|
||||
@ -1423,28 +1422,26 @@
|
||||
makeStub = $.el('label', {
|
||||
innerHTML: "<input type=checkbox checked=" + Conf['Stubs'] + "> Make stub"
|
||||
});
|
||||
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: {
|
||||
type: 'post',
|
||||
el: div,
|
||||
open: function(_arg) {
|
||||
var isReply, thread;
|
||||
thread = _arg.thread, isReply = _arg.isReply;
|
||||
if (isReply || thread.isHidden) {
|
||||
return false;
|
||||
}
|
||||
ThreadHiding.menu.thread = thread;
|
||||
return true;
|
||||
},
|
||||
subEntries: [
|
||||
{
|
||||
el: apply
|
||||
}, {
|
||||
el: makeStub
|
||||
}
|
||||
]
|
||||
}
|
||||
}));
|
||||
return $.event('AddMenuEntry', {
|
||||
type: 'post',
|
||||
el: div,
|
||||
open: function(_arg) {
|
||||
var isReply, thread;
|
||||
thread = _arg.thread, isReply = _arg.isReply;
|
||||
if (isReply || thread.isHidden) {
|
||||
return false;
|
||||
}
|
||||
ThreadHiding.menu.thread = thread;
|
||||
return true;
|
||||
},
|
||||
subEntries: [
|
||||
{
|
||||
el: apply
|
||||
}, {
|
||||
el: makeStub
|
||||
}
|
||||
]
|
||||
});
|
||||
},
|
||||
hide: function() {
|
||||
var makeStub, thread;
|
||||
@ -1634,30 +1631,28 @@
|
||||
makeStub = $.el('label', {
|
||||
innerHTML: "<input type=checkbox name=makeStub checked=" + Conf['Stubs'] + "> Make stub"
|
||||
});
|
||||
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: {
|
||||
type: 'post',
|
||||
el: div,
|
||||
open: function(post) {
|
||||
if (!post.isReply || post.isClone) {
|
||||
return false;
|
||||
}
|
||||
ReplyHiding.menu.post = post;
|
||||
return true;
|
||||
},
|
||||
subEntries: [
|
||||
{
|
||||
el: apply
|
||||
}, {
|
||||
el: thisPost
|
||||
}, {
|
||||
el: replies
|
||||
}, {
|
||||
el: makeStub
|
||||
}
|
||||
]
|
||||
}
|
||||
}));
|
||||
return $.event('AddMenuEntry', {
|
||||
type: 'post',
|
||||
el: div,
|
||||
open: function(post) {
|
||||
if (!post.isReply || post.isClone) {
|
||||
return false;
|
||||
}
|
||||
ReplyHiding.menu.post = post;
|
||||
return true;
|
||||
},
|
||||
subEntries: [
|
||||
{
|
||||
el: apply
|
||||
}, {
|
||||
el: thisPost
|
||||
}, {
|
||||
el: replies
|
||||
}, {
|
||||
el: makeStub
|
||||
}
|
||||
]
|
||||
});
|
||||
},
|
||||
hide: function() {
|
||||
var makeStub, parent, post, replies, thisPost;
|
||||
@ -1875,16 +1870,14 @@
|
||||
textContent: 'Report this post'
|
||||
});
|
||||
$.on(a, 'click', ReportLink.report);
|
||||
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: {
|
||||
type: 'post',
|
||||
el: a,
|
||||
open: function(post) {
|
||||
ReportLink.post = post;
|
||||
return !post.isDead;
|
||||
}
|
||||
return $.event('AddMenuEntry', {
|
||||
type: 'post',
|
||||
el: a,
|
||||
open: function(post) {
|
||||
ReportLink.post = post;
|
||||
return !post.isDead;
|
||||
}
|
||||
}));
|
||||
});
|
||||
},
|
||||
report: function() {
|
||||
var id, post, set, url;
|
||||
@ -1932,29 +1925,27 @@
|
||||
return !!file;
|
||||
}
|
||||
};
|
||||
d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: {
|
||||
type: 'post',
|
||||
el: div,
|
||||
open: function(post) {
|
||||
var node, seconds;
|
||||
if (post.isDead) {
|
||||
return false;
|
||||
}
|
||||
DeleteLink.post = post;
|
||||
node = div.firstChild;
|
||||
if (seconds = DeleteLink.cooldown[post.fullID]) {
|
||||
node.textContent = "Delete (" + seconds + ")";
|
||||
DeleteLink.cooldown.el = node;
|
||||
} else {
|
||||
node.textContent = 'Delete';
|
||||
delete DeleteLink.cooldown.el;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
subEntries: [postEntry, fileEntry]
|
||||
}
|
||||
}));
|
||||
$.event('AddMenuEntry', {
|
||||
type: 'post',
|
||||
el: div,
|
||||
open: function(post) {
|
||||
var node, seconds;
|
||||
if (post.isDead) {
|
||||
return false;
|
||||
}
|
||||
DeleteLink.post = post;
|
||||
node = div.firstChild;
|
||||
if (seconds = DeleteLink.cooldown[post.fullID]) {
|
||||
node.textContent = "Delete (" + seconds + ")";
|
||||
DeleteLink.cooldown.el = node;
|
||||
} else {
|
||||
node.textContent = 'Delete';
|
||||
delete DeleteLink.cooldown.el;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
subEntries: [postEntry, fileEntry]
|
||||
});
|
||||
return $.on(d, 'QRPostSuccessful', this.cooldown.start);
|
||||
},
|
||||
"delete": function() {
|
||||
@ -2045,22 +2036,20 @@
|
||||
className: 'download-link',
|
||||
textContent: 'Download file'
|
||||
});
|
||||
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: {
|
||||
type: 'post',
|
||||
el: a,
|
||||
open: function(_arg) {
|
||||
var file;
|
||||
file = _arg.file;
|
||||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
a.href = file.URL;
|
||||
a.download = file.name;
|
||||
return true;
|
||||
return $.event('AddMenuEntry', {
|
||||
type: 'post',
|
||||
el: a,
|
||||
open: function(_arg) {
|
||||
var file;
|
||||
file = _arg.file;
|
||||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
a.href = file.URL;
|
||||
a.download = file.name;
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -2093,9 +2082,7 @@
|
||||
type = _ref[_i];
|
||||
entry.subEntries.push(this.createSubEntry(type[0], type[1]));
|
||||
}
|
||||
return d.dispatchEvent(new CustomEvent('AddMenuEntry', {
|
||||
detail: entry
|
||||
}));
|
||||
return $.event('AddMenuEntry', entry);
|
||||
},
|
||||
createSubEntry: function(text, type) {
|
||||
var el, open;
|
||||
|
||||
@ -134,6 +134,8 @@ $.extend $,
|
||||
for event in events.split ' '
|
||||
el.removeEventListener event, handler, false
|
||||
return
|
||||
event: (event, detail) ->
|
||||
d.dispatchEvent new CustomEvent event, {detail}
|
||||
open: (url) ->
|
||||
(GM_openInTab or window.open) url, '_blank'
|
||||
hidden: ->
|
||||
|
||||
@ -101,10 +101,9 @@ Settings =
|
||||
textContent: '4chan X Settings'
|
||||
href: 'javascript:;'
|
||||
$.on link, 'click', Settings.open
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail:
|
||||
type: 'header'
|
||||
el: link
|
||||
$.event 'AddMenuEntry',
|
||||
type: 'header'
|
||||
el: link
|
||||
|
||||
# 4chan settings link
|
||||
link = $.el 'a',
|
||||
@ -112,11 +111,10 @@ Settings =
|
||||
textContent: '4chan Settings'
|
||||
href: 'javascript:;'
|
||||
$.on link, 'click', -> $.id('settingsWindowLink').click()
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail:
|
||||
type: 'header'
|
||||
el: link
|
||||
open: -> !Conf['Disable 4chan\'s extension']
|
||||
$.event 'AddMenuEntry',
|
||||
type: 'header'
|
||||
el: link
|
||||
open: -> !Conf['Disable 4chan\'s extension']
|
||||
|
||||
return unless Conf['Disable 4chan\'s extension']
|
||||
settings = JSON.parse(localStorage.getItem '4chan-settings') or {}
|
||||
@ -328,8 +326,7 @@ Filter =
|
||||
# Add a sub entry for each filter type.
|
||||
entry.subEntries.push Filter.menu.createSubEntry type[0], type[1]
|
||||
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail: entry
|
||||
$.event 'AddMenuEntry', entry
|
||||
|
||||
createSubEntry: (text, type) ->
|
||||
el = $.el 'a',
|
||||
@ -481,16 +478,15 @@ ThreadHiding =
|
||||
makeStub = $.el 'label',
|
||||
innerHTML: "<input type=checkbox checked=#{Conf['Stubs']}> Make stub"
|
||||
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail:
|
||||
type: 'post'
|
||||
el: div
|
||||
open: ({thread, isReply}) ->
|
||||
if isReply or thread.isHidden
|
||||
return false
|
||||
ThreadHiding.menu.thread = thread
|
||||
true
|
||||
subEntries: [el: apply; el: makeStub]
|
||||
$.event 'AddMenuEntry',
|
||||
type: 'post'
|
||||
el: div
|
||||
open: ({thread, isReply}) ->
|
||||
if isReply or thread.isHidden
|
||||
return false
|
||||
ThreadHiding.menu.thread = thread
|
||||
true
|
||||
subEntries: [el: apply; el: makeStub]
|
||||
hide: ->
|
||||
makeStub = $('input', @parentNode).checked
|
||||
{thread} = ThreadHiding.menu
|
||||
@ -634,16 +630,15 @@ ReplyHiding =
|
||||
makeStub = $.el 'label',
|
||||
innerHTML: "<input type=checkbox name=makeStub checked=#{Conf['Stubs']}> Make stub"
|
||||
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail:
|
||||
type: 'post'
|
||||
el: div
|
||||
open: (post) ->
|
||||
if !post.isReply or post.isClone
|
||||
return false
|
||||
ReplyHiding.menu.post = post
|
||||
true
|
||||
subEntries: [{el: apply}, {el: thisPost}, {el: replies}, {el: makeStub}]
|
||||
$.event 'AddMenuEntry',
|
||||
type: 'post'
|
||||
el: div
|
||||
open: (post) ->
|
||||
if !post.isReply or post.isClone
|
||||
return false
|
||||
ReplyHiding.menu.post = post
|
||||
true
|
||||
subEntries: [{el: apply}, {el: thisPost}, {el: replies}, {el: makeStub}]
|
||||
hide: ->
|
||||
parent = @parentNode
|
||||
thisPost = $('input[name=thisPost]', parent).checked
|
||||
@ -804,13 +799,12 @@ ReportLink =
|
||||
href: 'javascript:;'
|
||||
textContent: 'Report this post'
|
||||
$.on a, 'click', ReportLink.report
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail:
|
||||
type: 'post'
|
||||
el: a
|
||||
open: (post) ->
|
||||
ReportLink.post = post
|
||||
!post.isDead
|
||||
$.event 'AddMenuEntry',
|
||||
type: 'post'
|
||||
el: a
|
||||
open: (post) ->
|
||||
ReportLink.post = post
|
||||
!post.isDead
|
||||
report: ->
|
||||
{post} = ReportLink
|
||||
url = "//sys.4chan.org/#{post.board}/imgboard.php?mode=report&no=#{post}"
|
||||
@ -845,22 +839,21 @@ DeleteLink =
|
||||
$.on fileEl, 'click', DeleteLink.delete
|
||||
!!file
|
||||
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail:
|
||||
type: 'post'
|
||||
el: div
|
||||
open: (post) ->
|
||||
return false if post.isDead
|
||||
DeleteLink.post = post
|
||||
node = div.firstChild
|
||||
if seconds = DeleteLink.cooldown[post.fullID]
|
||||
node.textContent = "Delete (#{seconds})"
|
||||
DeleteLink.cooldown.el = node
|
||||
else
|
||||
node.textContent = 'Delete'
|
||||
delete DeleteLink.cooldown.el
|
||||
true
|
||||
subEntries: [postEntry, fileEntry]
|
||||
$.event 'AddMenuEntry',
|
||||
type: 'post'
|
||||
el: div
|
||||
open: (post) ->
|
||||
return false if post.isDead
|
||||
DeleteLink.post = post
|
||||
node = div.firstChild
|
||||
if seconds = DeleteLink.cooldown[post.fullID]
|
||||
node.textContent = "Delete (#{seconds})"
|
||||
DeleteLink.cooldown.el = node
|
||||
else
|
||||
node.textContent = 'Delete'
|
||||
delete DeleteLink.cooldown.el
|
||||
true
|
||||
subEntries: [postEntry, fileEntry]
|
||||
|
||||
$.on d, 'QRPostSuccessful', @cooldown.start
|
||||
|
||||
@ -935,15 +928,14 @@ DownloadLink =
|
||||
a = $.el 'a',
|
||||
className: 'download-link'
|
||||
textContent: 'Download file'
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail:
|
||||
type: 'post'
|
||||
el: a
|
||||
open: ({file}) ->
|
||||
return false unless file
|
||||
a.href = file.URL
|
||||
a.download = file.name
|
||||
true
|
||||
$.event 'AddMenuEntry',
|
||||
type: 'post'
|
||||
el: a
|
||||
open: ({file}) ->
|
||||
return false unless file
|
||||
a.href = file.URL
|
||||
a.download = file.name
|
||||
true
|
||||
|
||||
ArchiveLink =
|
||||
init: ->
|
||||
@ -975,8 +967,7 @@ ArchiveLink =
|
||||
# Add a sub entry for each type.
|
||||
entry.subEntries.push @createSubEntry type[0], type[1]
|
||||
|
||||
d.dispatchEvent new CustomEvent 'AddMenuEntry',
|
||||
detail: entry
|
||||
$.event 'AddMenuEntry', entry
|
||||
|
||||
createSubEntry: (text, type) ->
|
||||
el = $.el 'a',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user