mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-23 03:15:48 +02:00
Redesign reply-account plugin configuration and add WIP last account setting
This commit is contained in:
parent
3371c31e63
commit
e48a068e9d
Resources/Plugins/reply-account
@ -4,41 +4,69 @@ enabled(){
|
||||
window.TDPF_loadConfigurationFile(this, "configuration.js", "configuration.default.js", obj => configuration = obj);
|
||||
|
||||
this.uiInlineComposeTweetEvent = function(e, data){
|
||||
var account = null;
|
||||
var query;
|
||||
|
||||
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;
|
||||
if (configuration.useAdvancedSelector){
|
||||
if (configuration.customSelector){
|
||||
var column = TD.controller.columnManager.get(data.element.closest("section.column").attr("data-column"));
|
||||
query = configuration.customSelector(column);
|
||||
}
|
||||
else{
|
||||
identifier = obj[0].privateState.key;
|
||||
$TD.alert("warning", "Plugin reply-account has invalid configuration: useAdvancedSelector is true, but customSelector function is missing");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else{
|
||||
query = configuration.defaultAccount;
|
||||
}
|
||||
|
||||
if (typeof query === "undefined"){
|
||||
query = "#preferred";
|
||||
}
|
||||
|
||||
if (typeof query !== "string"){
|
||||
return;
|
||||
}
|
||||
else if (query.length === 0){
|
||||
$TD.alert("warning", "Plugin reply-account has invalid configuration: the requested account is empty");
|
||||
return;
|
||||
}
|
||||
else if (query[0] !== '@' && query[0] !== '&'){
|
||||
$TD.alert("warning", "Plugin reply-account has invalid configuration: the requested account does not begin with @ or #: "+query);
|
||||
return;
|
||||
}
|
||||
|
||||
var identifier = null;
|
||||
|
||||
switch(query){
|
||||
case "#preferred":
|
||||
identifier = TD.storage.clientController.client.getDefaultAccount();
|
||||
break;
|
||||
|
||||
case "#last":
|
||||
// TODO
|
||||
break;
|
||||
|
||||
case "#default":
|
||||
return;
|
||||
|
||||
default:
|
||||
if (query[0] === '@'){
|
||||
var obj = TD.storage.accountController.getAccountFromUsername(query.substring(1));
|
||||
|
||||
if (obj.length === 0){
|
||||
$TD.alert("warning", "Plugin reply-account has invalid configuration: requested account not found: "+query);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
identifier = obj[0].privateState.key;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$TD.alert("warning", "Plugin reply-account has invalid configuration: unknown requested account query: "+query);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
data.singleFrom = data.from = [ identifier ];
|
||||
};
|
||||
|
@ -13,13 +13,14 @@
|
||||
*
|
||||
* Set value of 'defaultAccount' to one of the following values:
|
||||
*
|
||||
* "" to use your preferred TweetDeck account for all replies (default)
|
||||
* "#preferred" to use your preferred TweetDeck account (the one used to log into TweetDeck)
|
||||
* "#last" to specify the account that was selected last time
|
||||
* "#default" to fall back to default TweetDeck behavior; useful for advanced configuration below, otherwise disable the plugin instead
|
||||
* "@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: "",
|
||||
defaultAccount: "#preferred",
|
||||
|
||||
/*
|
||||
* Advanced way of configuring the plugin
|
||||
@ -30,8 +31,8 @@
|
||||
* 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 'customSelector' function should return a string in one of the formats supported by 'defaultAccount'.
|
||||
* If it returns anything else (for example, false or undefined), 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:
|
||||
|
Loading…
Reference in New Issue
Block a user