-
Notifications
You must be signed in to change notification settings - Fork 40
TBUtils function calls
TBUtils is one of the core blocks on which toolbox is build. It contains most of functions used to interact with reddit. This page will attempt to explain what each function calls does and how it can be used.
Important: This page is just a quick overview and will not always be entirely up to date, always make sure to check the live code.
The public variables defined are mostly used to determine certain states like what page you are on, what version of toolbox this is or if a certain mode is on. The variable names are pretty self explanatory.
Feed this thing a javascript epoch and it will return minutes.
Feed this thing an UNIX timestamp (reddit provides those in the api) and it will return the time and date in ISO format.
Feed this thing a UNIX timestamp and it will return a human readable (assuming you use commie EURO time) time.
Converts day INT to x days, x weeks and x months.
This handy little function will make a text suitable for usage in urls. It is used to construct urls like you see them on reddit.
Handy little template function. Example:
TBUtils.template('/r/{{subreddit}}/comments/{{link_id}}/{{title}}/', {
'subreddit': 'toolbox',
'title': title_to_url('this is a title we pulled from a post'),
'link_id': '2kwx2o'
});
Or more likely
var template = '<a href="/r/{{subreddit}}/comments/{{link_id}}/{{title}}/">link</a>';
var url = TBUtils.template(template , {
'subreddit': 'toolbox',
'title': title_to_url('this is a title we pulled from a post'),
'link_id': '2kwx2o'
});
Some sort of sorting
Because normal .sort() is case sensitive.
Ascending sane sort
Replace single bracket tokens based on context.
Prevent page lock while parsing things. (stolen from RES)
Reddit has the habit of presenting the same information in a myriad of ways in the DOM. Posts and comments all used to have a class thing
which explains the name of this function.
Give this function a thing
jquery object and it will scrape as much information out of it as possible regardless of the variation.
reddit HTML encodes all of their JSON responses, we need to HTMLdecode them before parsing.
Gets the subreddits the current user moderates.
Depreciated