Use constructors to create events. Add post/thread IDs to QRPostSuccessful's details.
This commit is contained in:
parent
00a660533e
commit
2f6e5f2443
@ -470,10 +470,7 @@
|
|||||||
open: function(url) {
|
open: function(url) {
|
||||||
return (GM_openInTab || window.open)(location.protocol + url, '_blank');
|
return (GM_openInTab || window.open)(location.protocol + url, '_blank');
|
||||||
},
|
},
|
||||||
event: function(el, name, type) {
|
event: function(el, e) {
|
||||||
var e;
|
|
||||||
e = d.createEvent(type || 'CustomEvent');
|
|
||||||
e.initEvent(name, true, false);
|
|
||||||
return el.dispatchEvent(e);
|
return el.dispatchEvent(e);
|
||||||
},
|
},
|
||||||
globalEval: function(code) {
|
globalEval: function(code) {
|
||||||
@ -1282,7 +1279,7 @@
|
|||||||
ta.value = value.slice(0, selStart) + ("[" + tag + "]") + value.slice(selStart, selEnd) + ("[/" + tag + "]") + value.slice(selEnd);
|
ta.value = value.slice(0, selStart) + ("[" + tag + "]") + value.slice(selStart, selEnd) + ("[/" + tag + "]") + value.slice(selEnd);
|
||||||
range = ("[" + tag + "]").length + selEnd;
|
range = ("[" + tag + "]").length + selEnd;
|
||||||
ta.setSelectionRange(range, range);
|
ta.setSelectionRange(range, range);
|
||||||
return $.event(ta, 'input', 'Event');
|
return $.event(ta, new Event('input'));
|
||||||
},
|
},
|
||||||
img: function(thread, all) {
|
img: function(thread, all) {
|
||||||
var thumb;
|
var thumb;
|
||||||
@ -1592,7 +1589,7 @@
|
|||||||
range += text.match(/\n/g).length;
|
range += text.match(/\n/g).length;
|
||||||
}
|
}
|
||||||
ta.setSelectionRange(range, range);
|
ta.setSelectionRange(range, range);
|
||||||
return $.event(ta, 'input', 'Event');
|
return $.event(ta, new Event('input'));
|
||||||
},
|
},
|
||||||
characterCount: function() {
|
characterCount: function() {
|
||||||
var count, counter;
|
var count, counter;
|
||||||
@ -2046,7 +2043,9 @@
|
|||||||
QR.cooldown.init();
|
QR.cooldown.init();
|
||||||
QR.captcha.init();
|
QR.captcha.init();
|
||||||
$.add(d.body, QR.el);
|
$.add(d.body, QR.el);
|
||||||
return $.event(QR.el, 'QRDialogCreation');
|
return $.event(QR.el, new CustomEvent('QRDialogCreation', {
|
||||||
|
bubbles: true
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
submit: function(e) {
|
submit: function(e) {
|
||||||
var callbacks, captcha, captchas, challenge, err, m, opts, post, reply, response, threadID;
|
var callbacks, captcha, captchas, challenge, err, m, opts, post, reply, response, threadID;
|
||||||
@ -2147,7 +2146,7 @@
|
|||||||
return QR.ajax = $.ajax($.id('postForm').parentNode.action, callbacks, opts);
|
return QR.ajax = $.ajax($.id('postForm').parentNode.action, callbacks, opts);
|
||||||
},
|
},
|
||||||
response: function(html) {
|
response: function(html) {
|
||||||
var bs, doc, err, msg, persona, postNumber, reply, thread, _, _ref;
|
var bs, doc, err, msg, persona, postID, reply, threadID, _, _ref;
|
||||||
doc = d.implementation.createHTMLDocument('');
|
doc = d.implementation.createHTMLDocument('');
|
||||||
doc.documentElement.innerHTML = html;
|
doc.documentElement.innerHTML = html;
|
||||||
if (doc.title === '4chan - Banned') {
|
if (doc.title === '4chan - Banned') {
|
||||||
@ -2175,7 +2174,6 @@
|
|||||||
QR.error(err);
|
QR.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$.event(QR.el, 'QRPostSuccessful');
|
|
||||||
reply = QR.replies[0];
|
reply = QR.replies[0];
|
||||||
persona = $.get('QR.persona', {});
|
persona = $.get('QR.persona', {});
|
||||||
persona = {
|
persona = {
|
||||||
@ -2184,17 +2182,23 @@
|
|||||||
sub: Conf['Remember Subject'] ? reply.sub : null
|
sub: Conf['Remember Subject'] ? reply.sub : null
|
||||||
};
|
};
|
||||||
$.set('QR.persona', persona);
|
$.set('QR.persona', persona);
|
||||||
_ref = msg.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], thread = _ref[1], postNumber = _ref[2];
|
_ref = msg.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], threadID = _ref[1], postID = _ref[2];
|
||||||
if (thread === '0') {
|
$.event(QR.el, new CustomEvent('QRPostSuccessful', {
|
||||||
if (Conf['Thread Watcher'] && Conf['Auto Watch']) {
|
detail: {
|
||||||
$.set('autoWatch', postNumber);
|
threadID: threadID,
|
||||||
|
postID: postID
|
||||||
}
|
}
|
||||||
location.pathname = "/" + g.BOARD + "/res/" + postNumber;
|
}));
|
||||||
|
if (threadID === '0') {
|
||||||
|
if (Conf['Thread Watcher'] && Conf['Auto Watch']) {
|
||||||
|
$.set('autoWatch', postID);
|
||||||
|
}
|
||||||
|
location.pathname = "/" + g.BOARD + "/res/" + postID;
|
||||||
} else {
|
} else {
|
||||||
QR.cooldown.auto = QR.replies.length > 1;
|
QR.cooldown.auto = QR.replies.length > 1;
|
||||||
QR.cooldown.set(/sage/i.test(reply.email) ? 60 : 30);
|
QR.cooldown.set(/sage/i.test(reply.email) ? 60 : 30);
|
||||||
if (Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto) {
|
if (Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto) {
|
||||||
$.open("//boards.4chan.org/" + g.BOARD + "/res/" + thread + "#" + postNumber);
|
$.open("//boards.4chan.org/" + g.BOARD + "/res/" + threadID + "#p" + postID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Conf['Persistent QR'] || QR.cooldown.auto) {
|
if (Conf['Persistent QR'] || QR.cooldown.auto) {
|
||||||
@ -2203,7 +2207,7 @@
|
|||||||
QR.close();
|
QR.close();
|
||||||
}
|
}
|
||||||
if (g.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) {
|
if (g.REPLY && (Conf['Unread Count'] || Conf['Unread Favicon'])) {
|
||||||
Unread.foresee.push(postNumber);
|
Unread.foresee.push(postID);
|
||||||
}
|
}
|
||||||
if (g.REPLY && Conf['Thread Updater'] && Conf['Auto Update This']) {
|
if (g.REPLY && Conf['Thread Updater'] && Conf['Auto Update This']) {
|
||||||
Updater.update();
|
Updater.update();
|
||||||
|
|||||||
@ -352,9 +352,7 @@ $.extend $,
|
|||||||
return
|
return
|
||||||
open: (url) ->
|
open: (url) ->
|
||||||
(GM_openInTab or window.open) location.protocol + url, '_blank'
|
(GM_openInTab or window.open) location.protocol + url, '_blank'
|
||||||
event: (el, name, type) ->
|
event: (el, e) ->
|
||||||
e = d.createEvent type or 'CustomEvent'
|
|
||||||
e.initEvent name, true, false
|
|
||||||
el.dispatchEvent e
|
el.dispatchEvent e
|
||||||
globalEval: (code) ->
|
globalEval: (code) ->
|
||||||
script = $.el 'script', textContent: code
|
script = $.el 'script', textContent: code
|
||||||
@ -936,7 +934,7 @@ Keybinds =
|
|||||||
ta.setSelectionRange range, range
|
ta.setSelectionRange range, range
|
||||||
|
|
||||||
# Fire the 'input' event
|
# Fire the 'input' event
|
||||||
$.event ta, 'input', 'Event'
|
$.event ta, new Event 'input'
|
||||||
|
|
||||||
img: (thread, all) ->
|
img: (thread, all) ->
|
||||||
if all
|
if all
|
||||||
@ -1178,7 +1176,7 @@ QR =
|
|||||||
ta.setSelectionRange range, range
|
ta.setSelectionRange range, range
|
||||||
|
|
||||||
# Fire the 'input' event
|
# Fire the 'input' event
|
||||||
$.event ta, 'input', 'Event'
|
$.event ta, new Event 'input'
|
||||||
|
|
||||||
characterCount: ->
|
characterCount: ->
|
||||||
counter = QR.charaCounter
|
counter = QR.charaCounter
|
||||||
@ -1532,7 +1530,8 @@ QR =
|
|||||||
|
|
||||||
# Create a custom event when the QR dialog is first initialized.
|
# Create a custom event when the QR dialog is first initialized.
|
||||||
# Use it to extend the QR's functionalities, or for XTRM RICE.
|
# Use it to extend the QR's functionalities, or for XTRM RICE.
|
||||||
$.event QR.el, 'QRDialogCreation'
|
$.event QR.el, new CustomEvent 'QRDialogCreation',
|
||||||
|
bubbles: true
|
||||||
|
|
||||||
submit: (e) ->
|
submit: (e) ->
|
||||||
e?.preventDefault()
|
e?.preventDefault()
|
||||||
@ -1655,9 +1654,6 @@ QR =
|
|||||||
QR.error err
|
QR.error err
|
||||||
return
|
return
|
||||||
|
|
||||||
# Post/upload confirmed as successful.
|
|
||||||
$.event QR.el, 'QRPostSuccessful'
|
|
||||||
|
|
||||||
reply = QR.replies[0]
|
reply = QR.replies[0]
|
||||||
|
|
||||||
persona = $.get 'QR.persona', {}
|
persona = $.get 'QR.persona', {}
|
||||||
@ -1667,18 +1663,25 @@ QR =
|
|||||||
sub: if Conf['Remember Subject'] then reply.sub else null
|
sub: if Conf['Remember Subject'] then reply.sub else null
|
||||||
$.set 'QR.persona', persona
|
$.set 'QR.persona', persona
|
||||||
|
|
||||||
[_, thread, postNumber] = msg.lastChild.textContent.match /thread:(\d+),no:(\d+)/
|
[_, threadID, postID] = msg.lastChild.textContent.match /thread:(\d+),no:(\d+)/
|
||||||
if thread is '0' # new thread
|
|
||||||
|
# Post/upload confirmed as successful.
|
||||||
|
$.event QR.el, new CustomEvent 'QRPostSuccessful',
|
||||||
|
detail:
|
||||||
|
threadID: threadID
|
||||||
|
postID: postID
|
||||||
|
|
||||||
|
if threadID is '0' # new thread
|
||||||
if Conf['Thread Watcher'] and Conf['Auto Watch']
|
if Conf['Thread Watcher'] and Conf['Auto Watch']
|
||||||
$.set 'autoWatch', postNumber
|
$.set 'autoWatch', postID
|
||||||
# auto-noko
|
# auto-noko
|
||||||
location.pathname = "/#{g.BOARD}/res/#{postNumber}"
|
location.pathname = "/#{g.BOARD}/res/#{postID}"
|
||||||
else
|
else
|
||||||
# Enable auto-posting if we have stuff to post, disable it otherwise.
|
# Enable auto-posting if we have stuff to post, disable it otherwise.
|
||||||
QR.cooldown.auto = QR.replies.length > 1
|
QR.cooldown.auto = QR.replies.length > 1
|
||||||
QR.cooldown.set if /sage/i.test reply.email then 60 else 30
|
QR.cooldown.set if /sage/i.test reply.email then 60 else 30
|
||||||
if Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto
|
if Conf['Open Reply in New Tab'] && !g.REPLY && !QR.cooldown.auto
|
||||||
$.open "//boards.4chan.org/#{g.BOARD}/res/#{thread}##{postNumber}"
|
$.open "//boards.4chan.org/#{g.BOARD}/res/#{threadID}#p#{postID}"
|
||||||
|
|
||||||
if Conf['Persistent QR'] or QR.cooldown.auto
|
if Conf['Persistent QR'] or QR.cooldown.auto
|
||||||
reply.rm()
|
reply.rm()
|
||||||
@ -1686,7 +1689,7 @@ QR =
|
|||||||
QR.close()
|
QR.close()
|
||||||
|
|
||||||
if g.REPLY and (Conf['Unread Count'] or Conf['Unread Favicon'])
|
if g.REPLY and (Conf['Unread Count'] or Conf['Unread Favicon'])
|
||||||
Unread.foresee.push postNumber
|
Unread.foresee.push postID
|
||||||
if g.REPLY and Conf['Thread Updater'] and Conf['Auto Update This']
|
if g.REPLY and Conf['Thread Updater'] and Conf['Auto Update This']
|
||||||
Updater.update()
|
Updater.update()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user