-
Notifications
You must be signed in to change notification settings - Fork 135
4chan X API
4chan X fires and listens for a number of CustomEvents to communicate with other scripts.
Fired by 4chan X on the document after it has finished its initial processing of all posts and threads in the original page.
Fired by 4chan X after inserting or detecting the insertion of one or more posts or clones of posts into the document. The target is a common ancestor of the inserted posts. Note that this may be fired multiple times on the same post in cases where it is removed and re-inserted, and may be fired before the page finished loading and before 4chanXInitFinished
.
Fired by 4chan X on the document after inserting one or more posts into the index for the first time. It also fires ones on the non-JSON index after all posts are processed.
Fire this event on the document to open the settings dialog. Pass a string containing the section name as the detail
to open a specific section.
Fire this event on the document to close any open 4chan X menus.
Fire this event on the document to create a 4chan X notification. Pass an object with the following fields as the detail
:
field | description |
---|---|
type | CSS class of the notification, indicating the message type ('info' , 'success' , 'warning' , or 'error' ). |
content | Message to display, as a string. |
lifetime | (Optional) Time for the notification to be displayed, in seconds. If absent or falsy, notification is displayed until closed by user. |
Fired by 4chan X on the Quick Reply when it is inserted into the document. Note that the Quick Reply is hidden when it is closed rather than removed from the document. This event is also fired by loadletter's fork.
Fire this event on the document to request a QRFile
event containing the currently selected file in the Quick Reply.
Fired by 4chan X on the document in response to a QRGetFile
event. The detail
is the currently selected file in the Quick Reply as a File
or Blob
, or undefined
if no file is selected.
Fire this event on the document to set the currently selected file in the Quick Reply. Pass an object with the following fields as the detail
:
field | description |
---|---|
file | A File or Blob object containing the file to be submitted. |
name | The name of the file. |
Fired by 4chan X on the document when a post is made through the Quick Reply. Contains an object with the following fields as the detail
:
field | description |
---|---|
boardID | Board name posted to, as a string. |
threadID | Thread number posted or posted to, as an integer. |
postID | Post number posted, as an integer. Equal to threadID for OPs. |
This event is also fired by loadletter's fork. Note that as of v2.40.42, loadletter's fork passes threadID
and postID
as strings.
Fire this event on the document to add a solved captcha to 4chan X's cache. Pass an object with the following fields as the detail
:
field | description |
---|---|
challenge | Value of recaptcha_challenge_field for Recaptcha v1. Omit this field for Recaptcha v2. |
response | Value of recaptcha_response_field for Recaptcha v1, or of g-recaptcha-response for Recaptcha v2. |
timeout | Time at which captcha expires, measured in milliseconds since 01 Jan 1970 UTC. |
Fired by 4chan X on the document when the thread is updated or dies.
The following fields are passed via the detail
object when the thread is updated:
field | description |
---|---|
404 | false |
threadID | Full ID of the thread. |
newPosts | Array of full IDs of new posts. |
deletedPosts | Array of full IDs of posts deleted in this update. |
deletedFiles | Array of full IDs of posts with their files deleted in this update. |
postCount | Number of posts in the thread, including the OP, as an integer. |
fileCount | Number of posts with images or other attached files in the thread, including the OP, as an integer. |
ipCount | Number of unique IP addresses that have posted to the thread, as an integer. |
The following fields are passed via the detail
object when the thread dies, either by being deleted or being closed and archived:
field | description |
---|---|
404 | true |
threadID | Full ID of the thread. |
A "full ID" means a string containing the board name and thread/post number separated by a period. For example, 'g.39894014'
would the the full ID of the thread https://boards.4chan.org/g/thread/39894014.
When a thread is closed and archived, an update event (detail[404] === false
) is first fired containing any new posts, followed by a thread death event (detail[404] === true
).
document.addEventListener('QRPostSuccessful', function(e) {
alert(
'You posted\nhttps://boards.4chan.org/' + e.detail.boardID +
'/thread/' + e.detail.threadID +
'#p' + e.detail.postID
);
}, false);
var detail = {type: 'info', content: 'Hello world!'};
if (typeof cloneInto === 'function') {
detail = cloneInto(detail, document.defaultView);
}
var event = new CustomEvent('CreateNotification', {bubbles: true, detail: detail});
document.dispatchEvent(event);
The cloneInto
function is necessary when passing an object as the event detail
from a Greasemonkey script which has been given extra privileges with @grant
. For more information, see: