mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-09 14:34:05 +02:00
Add a reply-account plugin with config
This commit is contained in:
parent
36473c2df9
commit
fb3d9e6d6b
@ -119,6 +119,7 @@ private UserConfig(string file){
|
||||
PluginsWindow = new WindowState();
|
||||
|
||||
Plugins.DisableOfficialFromConfig("clear-columns");
|
||||
Plugins.DisableOfficialFromConfig("reply-account");
|
||||
}
|
||||
|
||||
private void UpgradeFile(){
|
||||
@ -160,6 +161,7 @@ private void UpgradeFile(){
|
||||
|
||||
if (fileVersion == 4){
|
||||
Plugins.DisableOfficialFromConfig("clear-columns");
|
||||
Plugins.DisableOfficialFromConfig("reply-account");
|
||||
++fileVersion;
|
||||
}
|
||||
|
||||
|
17
Resources/Plugins/reply-account/.meta
Normal file
17
Resources/Plugins/reply-account/.meta
Normal file
@ -0,0 +1,17 @@
|
||||
[name]
|
||||
Custom reply account
|
||||
|
||||
[description]
|
||||
- Allows customizing the automatically selected reply account per column
|
||||
|
||||
[author]
|
||||
chylex
|
||||
|
||||
[version]
|
||||
1.0
|
||||
|
||||
[website]
|
||||
https://tweetduck.chylex.com
|
||||
|
||||
[requires]
|
||||
1.3.3
|
53
Resources/Plugins/reply-account/browser.js
Normal file
53
Resources/Plugins/reply-account/browser.js
Normal file
@ -0,0 +1,53 @@
|
||||
enabled(){
|
||||
var configuration = {};
|
||||
|
||||
window.TDPF_loadConfigurationFile(this, "user.configuration.js", obj => configuration = obj);
|
||||
|
||||
this.uiInlineComposeTweetEvent = function(e, data){
|
||||
var account = null;
|
||||
|
||||
if (configuration.useAdvancedSelector && configuration.customSelector){
|
||||
var column = TD.controller.columnManager.get(data.element.closest("section.column").attr("data-column"));
|
||||
var result = configuration.customSelector(column);
|
||||
|
||||
if (typeof result === "string" && result[0] === '@'){
|
||||
account = result.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (account === null){
|
||||
if (configuration.defaultAccount === false){
|
||||
return;
|
||||
}
|
||||
else if (configuration.defaultAccount !== "" && configuration.defaultAccount[0] === '@'){
|
||||
account = configuration.defaultAccount.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
var identifier;
|
||||
|
||||
if (account === null){
|
||||
identifier = TD.storage.clientController.client.getDefaultAccount();
|
||||
}
|
||||
else{
|
||||
var obj = TD.storage.accountController.getAccountFromUsername(account);
|
||||
|
||||
if (obj.length === 0){
|
||||
return;
|
||||
}
|
||||
else{
|
||||
identifier = obj[0].privateState.key;
|
||||
}
|
||||
}
|
||||
|
||||
data.singleFrom = data.from = [ identifier ];
|
||||
};
|
||||
}
|
||||
|
||||
ready(){
|
||||
$(document).on("uiInlineComposeTweet", this.uiInlineComposeTweetEvent);
|
||||
}
|
||||
|
||||
disabled(){
|
||||
$(document).off("uiInlineComposeTweet", this.uiInlineComposeTweetEvent);
|
||||
}
|
71
Resources/Plugins/reply-account/user.configuration.js
Normal file
71
Resources/Plugins/reply-account/user.configuration.js
Normal file
@ -0,0 +1,71 @@
|
||||
{
|
||||
/*
|
||||
* Simple way of configuring the plugin
|
||||
* ------------------------------------
|
||||
*
|
||||
* Set value of 'defaultAccount' to one of the following values:
|
||||
*
|
||||
* "" to use your preferred TweetDeck account for all replies (default)
|
||||
* "@myAccount" to specify an account name to use; has to be one of your registered account names
|
||||
* false to fall back to default TweetDeck behavior; useful for advanced configuration below, otherwise disable the plugin instead
|
||||
*
|
||||
*/
|
||||
|
||||
defaultAccount: "",
|
||||
|
||||
/*
|
||||
* Advanced way of configuring the plugin
|
||||
* --------------------------------------
|
||||
*
|
||||
* This assumes a basic knowledge of JavaScript and jQuery.
|
||||
*
|
||||
* 1. Set value of 'useAdvancedSelector' to true
|
||||
* 2. Uncomment the 'customSelector' function, and replace the example code with your desired behavior
|
||||
*
|
||||
* If 'customSelector' returns a string containing a full name of one of the registered accounts (including @), that account is used.
|
||||
* If it returns anything else (for example false, undefined, or an account name that is not registered), it falls back to 'defaultAccount' behavior.
|
||||
*
|
||||
* The 'column' parameter is a TweetDeck column object. If you want to see all properties of the object, open your browser, nagivate to TweetDeck,
|
||||
* log in, and run the following code in your browser console, which will return an object containing all of the column objects mapped to their IDs:
|
||||
* TD.controller.columnManager.getAll()
|
||||
*
|
||||
* The example below shows how to extract the column type, title, and account from the object.
|
||||
* Column type is prefixed with col_, and may be one of the following:
|
||||
*
|
||||
* col_timeline, col_interactions, col_mentions, col_followers, col_search, col_list,
|
||||
* col_customtimeline, col_messages, col_usertweets, col_favorites, col_activity,
|
||||
* col_dataminr, col_home, col_me, col_inbox, col_scheduled, col_unknown
|
||||
*
|
||||
* Some of these appear to be unused (for example, Home columns are 'col_timeline' instead of 'col_home').
|
||||
*
|
||||
* If you want to see your column types, run this in your browser console:
|
||||
* Object.values(TD.controller.columnManager.getAll()).forEach(obj => console.log(obj.getColumnType()));
|
||||
*
|
||||
* You can also get the jQuery column object using: $("section.column[data-column='"+column.ui.state.columnKey+"']")
|
||||
*
|
||||
*/
|
||||
|
||||
useAdvancedSelector: false,
|
||||
|
||||
/*customSelector: function(column){
|
||||
var titleObj = $(column.getTitleHTML());
|
||||
|
||||
var columnType = column.getColumnType(); // col_timeline
|
||||
var columnTitle = titleObj.siblings(".column-head-title").text(); // Home
|
||||
var columnAccount = titleObj.siblings(".attribution").text(); // @chylexmc
|
||||
|
||||
if (columnType === "col_search" && columnTitle === "TweetDuck"){
|
||||
// This is a search column that looks for 'TweetDuck' in the tweets,
|
||||
// search columns are normally linked to the preferred account
|
||||
// so this forces the @TryTweetDuck account to be used instead.
|
||||
return "@TryTweetDuck";
|
||||
}
|
||||
else if (columnType === "col_timeline" && columnAccount === "@chylexcz"){
|
||||
// This is a Home column of my test account @chylexcz,
|
||||
// but I want to reply to tweets from my official account.
|
||||
return "@chylexmc";
|
||||
}
|
||||
|
||||
// otherwise returns 'undefined' which falls back to 'defaultAccount' behavior
|
||||
}*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user