Just something I started working on for use in my own scripts. I figured someone else could find it useful as well. This is not yet complete, I'll probably add some more events over time. Anyone is also welcome to suggest any events they may need.
FimFic Events is a script that adds events for other scripts to hook into parts of the site. It essentially works by intercepting the site's ajax calls and inserts a proxy that injects callbacks both before and after an ajax result is handled.
Latest Version: 2.2
Current events: pagechange - occurs when a page of comments is loaded. addcomment - occurs when the user posts a comment. editcomment - occurs when the user edits a comment. previewcomment - when you preview a comment in the posting area. editmodule - when you open a module for editing on your userpage. savemodule - Like edit module, but occurs the user saves his changes. composepm - occurs when the user opens the dialogue to type a new PM. hovercard - occurs when the hover card is triggered for a link to a user's page. note_markread - occurs when the user clicks the 'mark all read' on their notifications. pm_markread - occurs when the users clicks the 'mark all read' on their PMs. listnotes - occurs when the dropdown for a user's notifications is loaded listpms - likewise for the PMs dropdown loadfeed - occurs when feed items load on the feed page listemoticons - occurs when the emoticons popup is loaded toolbar - occurs when the user loads his blogs/stories list on the main site toolbar.
All events have two variants, Before and After. Before occurs before the pages handler is called, and after occurs once everything the page needs to do is complete. In the case of the pagechange event the comments will have been loaded into the page and can be manipulated.
Registering to the events is exactly the same as in JQuery. You can add an event using 'on' and remove them using 'off'. You can also specify multiple event name in one call. Example for registering an event:
//Registers a handler for both the afterpagechange and after editcomment events. FimFicEvents.on('afterpagechange aftereditcomment', function() { alert('the page has changed!'); }); //Removes all handlers for just the afterpagechange event. FimFicEvents.off('afterpagechange');
Every event receives two parameters. The first one can be ignored, that's part of Jquery's event thing. The one that's important is the second parameter. The information it contains can vary between different event but the following are always provided:
eventName - (string) name of the event result - (object) data returned from the ajax call. Could be a string containing HTML/XML data, or a document object. url - (string) Path of the ajax request that triggered this event data - (object) Any information provided by the site to the ajax call
To use this in a Greasemonkey/Tampermonkey script simply add the following to the script's header:
3624235 Ooh, I'll be looking forward to seeing this added to some of the existing scripts! I bet a lot of those 'doesn't work if you refresh the comments page' disclaimers could be removed!
Greasy Fork is the successor to Userscripts.org but, for user safety, they enforce a whitelist on what hosted scripts may @require. (Trustworthy, moderated CDNs like Google's and stuff hosted on Greasy Fork itself.)
Would you be willing to add this to Greasy Fork as a userscript of type "library"? They do support linking an entry to a git repository for easy updates.
(However, if you push a change which fails Greasy Fork's static analysis check, it will render the Greasy Fork entry unavailable until you correct it, so you want to check that after updating.)
3683759 I don't know what happened. I must have forgotten to reply to this, but FimFic Events is on greasy fork as a library. I think I added it along with all my other libraries some time after you posted that.
Edit: The only exception being Extra Emoticions because greasyfork has something against loading secondary scripts.
5067724 I figured as much. Unfortunately there's no way around it without me having to merge FimFic Events into Extra Emoticons, and I really don't want to get into that mess.
Wait... the external script being referenced is FimFic Events?
Greasy Fork allows your script to @require other scripts on their whitelist and Greasy Fork itself is on the list. The important thing is ensuring that external script loading can't be used to circumvent their static analysis and manual removal policies.
(In other words, Extra Emoticons should be able to @require the Greasy Fork-hosted copy of FimFic Events without any trouble. It even gives an example of a valid @require line in the "this script is a library" message at the top of the listing.)
5067763 Yeah, but the problem is that there is no way for one library to load another.
Extra Emoticons is only ever loaded via an @require line in content packs. I could add events as another @require for content packs but it would an extra level of complexity for other people that might want to make a content pack, and would mean everyone would have to reinstall those as well when events updates.
Just something I started working on for use in my own scripts. I figured someone else could find it useful as well. This is not yet complete, I'll probably add some more events over time. Anyone is also welcome to suggest any events they may need.
FimFic Events is a script that adds events for other scripts to hook into parts of the site. It essentially works by intercepting the site's ajax calls and inserts a proxy that injects callbacks both before and after an ajax result is handled.
Latest Version: 2.2
Current events:
pagechange - occurs when a page of comments is loaded.
addcomment - occurs when the user posts a comment.
editcomment - occurs when the user edits a comment.
previewcomment - when you preview a comment in the posting area.
editmodule - when you open a module for editing on your userpage.
savemodule - Like edit module, but occurs the user saves his changes.
composepm - occurs when the user opens the dialogue to type a new PM.
hovercard - occurs when the hover card is triggered for a link to a user's page.
note_markread - occurs when the user clicks the 'mark all read' on their notifications.
pm_markread - occurs when the users clicks the 'mark all read' on their PMs.
listnotes - occurs when the dropdown for a user's notifications is loaded
listpms - likewise for the PMs dropdown
loadfeed - occurs when feed items load on the feed page
listemoticons - occurs when the emoticons popup is loaded
toolbar - occurs when the user loads his blogs/stories list on the main site toolbar.
All events have two variants, Before and After. Before occurs before the pages handler is called, and after occurs once everything the page needs to do is complete. In the case of the pagechange event the comments will have been loaded into the page and can be manipulated.
Registering to the events is exactly the same as in JQuery. You can add an event using 'on' and remove them using 'off'. You can also specify multiple event name in one call.
Example for registering an event:
Every event receives two parameters. The first one can be ignored, that's part of Jquery's event thing. The one that's important is the second parameter. The information it contains can vary between different event but the following are always provided:
eventName - (string) name of the event
result - (object) data returned from the ajax call. Could be a string containing HTML/XML data, or a document object.
url - (string) Path of the ajax request that triggered this event
data - (object) Any information provided by the site to the ajax call
To use this in a Greasemonkey/Tampermonkey script simply add the following to the script's header:
3624235
Add to.... which script's header?
3624235
Ooh, I'll be looking forward to seeing this added to some of the existing scripts!
I bet a lot of those 'doesn't work if you refresh the comments page' disclaimers could be removed!
3651906
You add it to the header of the script you want to use these events in. This is mostly for developers to use.
3651941
Eeyup.
--Sollace
Greasy Fork is the successor to Userscripts.org but, for user safety, they enforce a whitelist on what hosted scripts may @require. (Trustworthy, moderated CDNs like Google's and stuff hosted on Greasy Fork itself.)
Would you be willing to add this to Greasy Fork as a userscript of type "library"? They do support linking an entry to a git repository for easy updates.
(However, if you push a change which fails Greasy Fork's static analysis check, it will render the Greasy Fork entry unavailable until you correct it, so you want to check that after updating.)
Update to work with a change knighty made. He now uses some weird custom object for requests as well as the default jquery ajax function.
3683759
I don't know what happened. I must have forgotten to reply to this, but FimFic Events is on greasy fork as a library. I think I added it along with all my other libraries some time after you posted that.
Edit: The only exception being Extra Emoticions because greasyfork has something against loading secondary scripts.
5067654
It's used in the wild as a way to sneak malicious code into installed copies of scripts after technically-skilled users have checked them over.
5067724
I figured as much. Unfortunately there's no way around it without me having to merge FimFic Events into Extra Emoticons, and I really don't want to get into that mess.
5067753
Wait... the external script being referenced is FimFic Events?
Greasy Fork allows your script to @require other scripts on their whitelist and Greasy Fork itself is on the list. The important thing is ensuring that external script loading can't be used to circumvent their static analysis and manual removal policies.
(In other words, Extra Emoticons should be able to @require the Greasy Fork-hosted copy of FimFic Events without any trouble. It even gives an example of a valid @require line in the "this script is a library" message at the top of the listing.)
5067763
Yeah, but the problem is that there is no way for one library to load another.
Extra Emoticons is only ever loaded via an @require line in content packs. I could add events as another @require for content packs but it would an extra level of complexity for other people that might want to make a content pack, and would mean everyone would have to reinstall those as well when events updates.
5067792
Ahh. That makes sense.