Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Plugins꞉ 2. Global functions

Daniel Chýlek edited this page Feb 15, 2020 · 12 revisions

Plugins have access to the following functions which are defined globally in the window object. Please note that not all functions are available in both browser.js and notification.js.

Some functions have a pluginObject parameter which requires you to pass the plugin object itself into the function - you can do that by passing this, but don't forget that this will have different meaning based on the context:

enabled(){
    let obj = this; // 'this' is the plugin object
    
    let f = () => {
        // arrow function does not change the context, 'this' is the plugin object
    };
    
    let h = function(){
        // normal function changes the context, 'this' is not the plugin object!
    };
}

loadConfigurationFile

Signature void TDPF_loadConfigurationFile(pluginObject, pathConfigFile, pathConfigDefault, onSuccess, onFailure)
Available browser.js notification.js
Since 1.3.3

Reads a JavaScript object from a file, usually used to read user configuration. Note that onSuccess may be called before or after ready(), do not execute any code that relies on the configuration until you receive the result.

Parameters

  • pathConfigFile - path to the created config file, should be same as [configfile]
  • pathConfigDefault - path to the default config file, should be same as [configdefault]
  • onSuccess - function that takes the read JavaScript object
  • onFailure (optional) - function that takes an exception object or a string with an error message if the process failed; should return true to prevent default error handling, which displays an alert window to the user

Example

enabled(){
  this.configuration = { columnWidth: "310px" };
  window.TDPF_loadConfigurationFile(this, "configuration.js", "configuration.default.js", obj => this.configuration = obj);
}

createCustomStyle

Signature object TDPF_createCustomStyle(pluginObject)
Available browser.js notification.js
Since 1.4.1

Creates a new <style> element on the page, and returns an object with the following properties:

  • insert(rule) - function that takes a single CSS rule and inserts it into the style element
  • remove() - function that removes the style element, don't forget to call this in disabled()
  • element - property containing the HTMLElement object

Example

enabled(){
  this.css = window.TDPF_createCustomStyle(this);
  this.css.insert(".avatar { border-radius: 0 !important }");
  this.css.insert(".column { width: 500px !important }");
}

disabled(){
  this.css.remove();
}

getColumnName

Signature void TDPF_getColumnName(column)
Available browser.js
Since 1.13.5

Retrieves the column name, such as Home, Notifications, or Search.

Parameters

  • column - the column object; see TD.controller.columnManager methods that let you retrieve all or individual column objects

injectMustache

Signature void TDPF_injectMustache(mustache, operation, search, html)
Available browser.js
Since 1.14

Performs one of available operations on a mustache template. All declared mustaches are in the TD.mustaches object.

Parameters

  • mustache - name of the mustache
  • operation - one of replace, prepend, append
  • search - the searched substring inside the mustache
  • html - the string which, based on the operation, will either replace the searched substring, or be inserted before or after it

Example

enabled(){
  this.prevThumbnailMustache = window.TDGF_injectMustache("status/media_thumb.mustache", "append", "is-gif", " is-paused");
}

disabled(){
  TD.mustaches["status/media_thumb.mustache"] = this.prevThumbnailMustache;
}

playVideo

Signature void TDPF_playVideo(url, username)
Available browser.js
Since 1.10.3
Signature void TDPF_playVideo(object)
Available browser.js
Since 1.18.3

Plays a video file from URL using the integrated video player.

Parameters (old)

  • url is the direct link to a video file
  • username is an optional username which will be used in the file name if the user saves the video

Parameters (new)

  • object is an object with the following properties:
{
  videoUrl: <string>, // direct link to a video file
  tweetUrl: <string>, // optional link to the original tweet; opens in the browser if the video cannot be played
  username: <string> // optional username; used in the file name if the user saves the video
}

prioritizeNewestEvent

Signature void TDPF_prioritizeNewestEvent(element, event)
Available browser.js
Since 1.11

Event handlers are normally executed in the same order they were added. This function reprioritizes the most recently added event handler to run first instead, to allow stopping its propagation before it hits events added by TweetDeck. The event must be added using jQuery, i.e. using on(), delegate(), or a shortcut function such as click().

  • element is the target element object (the element must not be wrapped in a jQuery object)
  • event is the name of the event

reloadColumns

Signature void TDPF_reloadColumns()
Available browser.js
Since 1.11.1

Convenience function to re-render tweets in all columns.


alert/confirm/prompt

Signature void alert(text)
Signature bool confirm(text)
Signature string prompt(text)
Available browser.js notification.js
Since 1.9

These 3 functions are from vanilla JavaScript. They display a message, optionally with Yes/No buttons (confirm) or a text input (prompt). Use \n for new lines. You can add an icon to the message by prefixing the text:

  • info|your message
  • question|your message
  • warning|your message
  • error|your message