1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-06 14:34:05 +02:00

Reformat plugin code

This commit is contained in:
chylex 2022-01-17 22:32:01 +01:00
parent 24f5075116
commit 8149ed50e1
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
9 changed files with 2088 additions and 2063 deletions
Resources/Plugins
.debug
clear-columns
edit-design
emoji-keyboard
reply-account
templates
timeline-polls

View File

@ -7,12 +7,12 @@ enabled(){
// F4 key - toggle debug mode
// ==========================
if (e.keyCode === 115){
if (e.keyCode === 115) {
this.isDebugging = !this.isDebugging;
$(".nav-user-info").first().css("background-color", this.isDebugging ? "#5A6B75" : "#292F33");
$(".nav-user-info").first().css("background-color", this.isDebugging ? "#5a6b75" : "#292f33");
}
else if (this.isDebugging){
else if (this.isDebugging) {
e.preventDefault();
// ===================================
@ -20,7 +20,7 @@ enabled(){
// S key - simulate sound notification
// ===================================
if (e.keyCode === 78 || e.keyCode === 83){
if (e.keyCode === 78 || e.keyCode === 83) {
let col = TD.controller.columnManager.getAllOrdered()[0];
let model = col.model;
@ -30,14 +30,14 @@ enabled(){
model.setHasNotification(e.keyCode === 78);
model.setHasSound(e.keyCode === 83);
$.publish("/notifications/new", [{
$.publish("/notifications/new", [ {
column: col,
items: [
col.updateArray[Math.floor(Math.random()*col.updateArray.length)]
col.updateArray[Math.floor(Math.random() * col.updateArray.length)]
]
}]);
} ]);
setTimeout(function(){
setTimeout(function() {
model.setHasNotification(prevPopup);
model.setHasSound(prevSound);
}, 1);
@ -47,7 +47,7 @@ enabled(){
// D key - trigger debugger
// ========================
else if (e.keyCode === 68){
else if (e.keyCode === 68) {
debugger;
}
}

View File

@ -17,13 +17,13 @@ enabled(){
let wasShiftPressed = false;
const updateShiftState = (pressed) => {
if (pressed != wasShiftPressed){
if (pressed != wasShiftPressed) {
wasShiftPressed = pressed;
if (pressed){
if (pressed) {
$(document).on("mousemove", this.eventKeyUp);
}
else{
else {
$(document).off("mousemove", this.eventKeyUp);
}
@ -33,8 +33,8 @@ enabled(){
// event handlers
this.eventClickOneCapture = function(e){
if (e.target.getAttribute("data-action") === "td-clearcolumns-dosingle"){
this.eventClickOneCapture = function(e) {
if (e.target.getAttribute("data-action") === "td-clearcolumns-dosingle") {
let name = $(e.target).closest(".js-column").attr("data-column");
e.shiftKey ? resetColumn(name) : clearColumn(name);
@ -44,25 +44,25 @@ enabled(){
}
};
this.eventClickAll = function(e){
this.eventClickAll = function(e) {
forEachColumn(e.shiftKey ? resetColumn : clearColumn);
};
this.eventKeyDown = function(e){
this.eventKeyDown = function(e) {
if (!(document.activeElement === null || document.activeElement === document.body)) {
return;
}
updateShiftState(e.shiftKey);
if (e.keyCode === 46){ // 46 = delete
if (e.altKey){
if (e.keyCode === 46) { // 46 = delete
if (e.altKey) {
forEachColumn(e.shiftKey ? resetColumn : clearColumn);
}
else{
else {
let focusedColumn = $(".js-column.is-focused");
if (focusedColumn.length){
if (focusedColumn.length) {
let name = focusedColumn.attr("data-column");
e.shiftKey ? resetColumn(name) : clearColumn(name);
}
@ -70,13 +70,13 @@ enabled(){
}
};
this.eventKeyUp = function(e){
if (!e.shiftKey){
this.eventKeyUp = function(e) {
if (!e.shiftKey) {
updateShiftState(false);
}
};
this.eventKeyboardShortcuts = function(e){
this.eventKeyboardShortcuts = function(e) {
$(".keyboard-shortcut-list").first().append(`
<dd class="keyboard-shortcut-definition" style="white-space:nowrap">
<span class="text-like-keyboard-key">1</span> <span class="text-like-keyboard-key">9</span> + <span class="text-like-keyboard-key">Del</span> Clear column 19
@ -105,14 +105,14 @@ enabled(){
this.prevColumnHeaderMustache = TD.mustaches["column/column_header.mustache"];
window.TDPF_injectMustache("column/column_header.mustache", "prepend", "<a data-testid=\"optionsToggle\"", this.btnClearOneHTML);
if (TD.ready){
if (TD.ready) {
$(".js-header-add-column").after(this.btnClearAllHTML);
$("a[data-testid='optionsToggle']", ".js-column-header").before(this.btnClearOneHTML);
}
// styles
if (!document.getElementById("td-clearcolumns-workaround")){
if (!document.getElementById("td-clearcolumns-workaround")) {
// TD started caching mustaches so disabling the plugin doesn't update the column headers properly...
let workaround = document.createElement("style");
workaround.id = "td-clearcolumns-workaround";
@ -149,7 +149,7 @@ ready(){
let tooltipEvents = $._data($(".js-header-action")[0], "events");
if (tooltipEvents.mouseover && tooltipEvents.mouseover.length && tooltipEvents.mouseout && tooltipEvents.mouseout.length){
if (tooltipEvents.mouseover && tooltipEvents.mouseover.length && tooltipEvents.mouseout && tooltipEvents.mouseout.length) {
$(".clear-columns-btn-all-parent").on({
mouseover: tooltipEvents.mouseover[0].handler,
mouseout: tooltipEvents.mouseout[0].handler

View File

@ -25,16 +25,28 @@ enabled(){
const prepareDefaultConfig = () => {
this.defaultConfig._theme = TD.settings.getTheme();
switch(TD.settings.getColumnWidth()){
case "wide": this.defaultConfig.columnWidth = "350px"; break;
case "narrow": this.defaultConfig.columnWidth = "270px"; break;
switch (TD.settings.getColumnWidth()) {
case "wide":
this.defaultConfig.columnWidth = "350px";
break;
case "narrow":
this.defaultConfig.columnWidth = "270px";
break;
}
switch(TD.settings.getFontSize()){
case "small": this.defaultConfig.fontSize = "13px"; break;
case "medium": this.defaultConfig.fontSize = "14px"; break;
case "large": this.defaultConfig.fontSize = "15px"; break;
case "largest": this.defaultConfig.fontSize = "16px"; break;
switch (TD.settings.getFontSize()) {
case "small":
this.defaultConfig.fontSize = "13px";
break;
case "medium":
this.defaultConfig.fontSize = "14px";
break;
case "large":
this.defaultConfig.fontSize = "15px";
break;
case "largest":
this.defaultConfig.fontSize = "16px";
break;
}
};
@ -49,10 +61,10 @@ enabled(){
this.currentStage = 0;
this.onStageReady = () => {
if (this.currentStage === 0){
if (this.currentStage === 0) {
this.currentStage = 1;
}
else if (this.tmpConfig !== null){
else if (this.tmpConfig !== null) {
let needsResave = !("_theme" in this.tmpConfig);
prepareDefaultConfig();
@ -60,7 +72,7 @@ enabled(){
this.tmpConfig = null;
this.reinjectAll();
if (this.firstTimeLoad || needsResave){
if (this.firstTimeLoad || needsResave) {
$TDP.writeFile(this.$token, configFile, JSON.stringify(this.config));
}
}
@ -73,34 +85,34 @@ enabled(){
this.onStageReady();
};
if (TD.ready){
if (TD.ready) {
this.onStageReady();
}
else{
else {
$(document).one("dataSettingsValues", () => this.onStageReady());
}
$TDP.checkFileExists(this.$token, configFile).then(exists => {
if (!exists){
if (!exists) {
loadConfigObject(null);
}
else{
else {
$TDP.readFile(this.$token, configFile, true).then(contents => {
try{
try {
loadConfigObject(JSON.parse(contents));
}catch(err){
} catch (err) {
loadConfigObject(null);
}
}).catch(err => {
loadConfigObject(null);
$TD.alert("error", "Problem loading configuration for the design edit plugin: "+err.message);
$TD.alert("error", "Problem loading configuration for the design edit plugin: " + err.message);
});
}
});
this.saveConfig = () => {
$TDP.writeFile(this.$token, configFile, JSON.stringify(this.config)).catch(err => {
$TD.alert("error", "Problem saving configuration for the design edit plugin: "+err.message);
$TD.alert("error", "Problem saving configuration for the design edit plugin: " + err.message);
});
};
@ -121,34 +133,34 @@ enabled(){
return;
}
if (!itemTD.prev().hasClass("drp-h-divider")){
itemTD.before('<li class="drp-h-divider"></li>');
if (!itemTD.prev().hasClass("drp-h-divider")) {
itemTD.before("<li class=\"drp-h-divider\"></li>");
}
let itemEditDesign = $('<li class="is-selectable"><a href="#" data-action>Edit layout &amp; design</a></li>');
let itemEditDesign = $("<li class=\"is-selectable\"><a href=\"#\" data-action>Edit layout &amp; design</a></li>");
itemEditDesign.insertAfter(itemTD);
itemEditDesign.on("click", "a", this.configure.bind(this));
itemEditDesign.hover(function(){
itemEditDesign.hover(function() {
$(this).addClass("is-selected");
}, function(){
}, function() {
$(this).removeClass("is-selected");
});
}, 2);
};
// modal dialog setup
const updateKey = function(key, value){
const updateKey = function(key, value) {
me.config[key] = value;
setTimeout(function(){
setTimeout(function() {
me.saveConfig();
me.reinjectAll();
}, 1); // delays the slight lag caused by saving and reinjection
};
this.customDesignModal = TD.components.BaseModal.extend(function(){
this.customDesignModal = TD.components.BaseModal.extend(function() {
let modal = $("#td-design-plugin-modal");
this.setAndShowContainer(modal, false);
@ -157,39 +169,39 @@ enabled(){
modal.find("[data-td-reload]").click(() => this.reloadPage = true);
// UI EVENTS
let getTextForCustom = function(key){
return "Custom ("+me.config[key]+")";
let getTextForCustom = function(key) {
return "Custom (" + me.config[key] + ")";
};
modal.find("[data-td-key]").each(function(){
modal.find("[data-td-key]").each(function() {
let item = $(this);
let tag = item.prop("tagName");
let key = item.attr("data-td-key");
// INPUTS
if (tag === "INPUT"){
if (tag === "INPUT") {
let type = item.attr("type");
if (type === "checkbox"){
if (type === "checkbox") {
item.prop("checked", me.config[key]);
item.change(function(){
item.change(function() {
updateKey(key, item.prop("checked"));
});
}
}
// SELECTS
else if (tag === "SELECT"){
else if (tag === "SELECT") {
let optionCustom = item.find("option[value^='custom']");
let optionCustomNew = item.find("option[value^='change-custom']");
let resetMyValue = () => {
if (!item.val(me.config[key]).val() && optionCustom.length === 1){
if (!item.val(me.config[key]).val() && optionCustom.length === 1) {
item.val(optionCustom.attr("value"));
optionCustom.text(getTextForCustom(key));
optionCustomNew.show();
}
else{
else {
optionCustom.text("Custom");
optionCustomNew.hide();
}
@ -197,26 +209,26 @@ enabled(){
resetMyValue();
item.change(function(){
item.change(function() {
let val = item.val();
if (val.endsWith("custom-px")){
if (val.endsWith("custom-px")) {
val = (prompt("Enter custom value (px):") || "").trim();
if (val){
if (val.endsWith("px")){
if (val) {
if (val.endsWith("px")) {
val = val.slice(0, -2).trim();
}
if (/^[0-9]+$/.test(val)){
updateKey(key, val+"px");
if (/^[0-9]+$/.test(val)) {
updateKey(key, val + "px");
}
else{
else {
alert("Invalid value, only px values are supported.");
}
}
}
else{
else {
updateKey(key, item.val());
}
@ -224,15 +236,15 @@ enabled(){
});
}
// CUSTOM ELEMENTS
else{
else {
let value = item.attr("data-td-value");
if (value == me.config[key]){
if (value == me.config[key]) {
item.addClass("selected");
}
item.click(function(){
modal.find("[data-td-key='"+key+"']").removeClass("selected");
item.click(function() {
modal.find("[data-td-key='" + key + "']").removeClass("selected");
item.addClass("selected");
updateKey(key, value);
});
@ -242,26 +254,26 @@ enabled(){
// THEMES
let selectedTheme = TD.settings.getTheme();
if (selectedTheme === "dark" && me.config.themeOverride === "black"){
if (selectedTheme === "dark" && me.config.themeOverride === "black") {
selectedTheme = me.config.themeOverride;
}
modal.find("[data-td-theme='"+selectedTheme+"']").prop("checked", true);
modal.find("[data-td-theme='" + selectedTheme + "']").prop("checked", true);
modal.find("[data-td-theme]").change(function(){
modal.find("[data-td-theme]").change(function() {
let theme = $(this).attr("data-td-theme");
me.config._theme = theme;
if (theme === "black"){
if (theme === "black") {
me.config.themeOverride = theme;
theme = "dark";
}
else{
else {
me.config.themeOverride = false;
}
setTimeout(function(){
if (theme != TD.settings.getTheme()){
setTimeout(function() {
if (theme != TD.settings.getTheme()) {
TD.settings.setTheme(theme);
}
@ -270,11 +282,11 @@ enabled(){
}, 1);
});
}).methods({
_render: function(){
_render: function() {
return $(me.htmlModal);
},
destroy: function(){
if (this.reloadPage){
destroy: function() {
if (this.reloadPage) {
window.TDPF_requestReload();
return;
}
@ -291,14 +303,14 @@ enabled(){
this.optimizationTimer = null;
let clearOptimizationTimer = () => {
if (this.optimizationTimer){
if (this.optimizationTimer) {
window.clearTimeout(this.optimizationTimer);
this.optimizationTimer = null;
}
};
let runOptimizationTimer = timeout => {
if (!this.optimizationTimer){
if (!this.optimizationTimer) {
this.optimizationTimer = window.setTimeout(optimizationTimerFunc, timeout);
}
};
@ -306,13 +318,13 @@ enabled(){
let optimizationTimerFunc = () => {
this.optimizationTimer = null;
if (this.config.optimizeAnimations){
if (this.config.optimizeAnimations) {
$TD.getIdleSeconds().then(s => {
if (s >= 16){
if (s >= 16) {
disableOptimizations();
runOptimizationTimer(2500);
}
else{
else {
injectOptimizations();
}
});
@ -320,7 +332,7 @@ enabled(){
};
let injectOptimizations = force => {
if (!this.optimizations && (force || document.hasFocus())){
if (!this.optimizations && (force || document.hasFocus())) {
this.optimizations = window.TDPF_createCustomStyle(this);
this.optimizations.insert(".app-content { will-change: transform }");
this.optimizations.insert(".column-holder { will-change: transform }");
@ -331,20 +343,20 @@ enabled(){
};
let disableOptimizations = () => {
if (this.optimizations){
if (this.optimizations) {
this.optimizations.remove();
this.optimizations = null;
}
};
this.onWindowFocusEvent = () => {
if (this.config && this.config.optimizeAnimations){
if (this.config && this.config.optimizeAnimations) {
injectOptimizations(true);
}
};
this.onWindowBlurEvent = () => {
if (this.config && this.config.optimizeAnimations){
if (this.config && this.config.optimizeAnimations) {
disableOptimizations();
clearOptimizationTimer();
}
@ -352,21 +364,21 @@ enabled(){
// css and layout injection
this.resetDesign = () => {
if (this.css){
if (this.css) {
this.css.remove();
}
this.css = window.TDPF_createCustomStyle(this);
if (this.theme){
if (this.theme) {
this.theme.remove();
}
if (this.config.themeOverride){
if (this.config.themeOverride) {
this.theme = window.TDPF_createCustomStyle(this);
}
if (this.icons){
if (this.icons) {
document.head.removeChild(this.icons);
this.icons = null;
}
@ -377,10 +389,10 @@ enabled(){
clearOptimizationTimer();
if (this.config.optimizeAnimations){
if (this.config.optimizeAnimations) {
injectOptimizations();
}
else{
else {
disableOptimizations();
}
@ -390,7 +402,7 @@ enabled(){
this.css.insert(`html[data-td-font] { font-size: ${this.config.fontSize} !important }`);
this.css.insert(`.avatar { border-radius: ${this.config.avatarRadius}% !important }`);
if (this.config.composerWidth !== "default"){
if (this.config.composerWidth !== "default") {
const width = this.config.composerWidth;
this.css.insert(`.js-app-content.is-open { margin-right: ${width} !important; transform: translateX(${width}) !important }`);
this.css.insert(`#tduck .js-app-content.tduck-is-opening { margin-right: 0 !important }`);
@ -399,14 +411,14 @@ enabled(){
let currentTheme = TD.settings.getTheme();
if (currentTheme === "dark" && this.config.themeOverride){
if (currentTheme === "dark" && this.config.themeOverride) {
currentTheme = this.config.themeOverride;
}
let notificationScrollbarColor = null;
if (this.config.themeColorTweaks){
switch(currentTheme){
if (this.config.themeColorTweaks) {
switch (currentTheme) {
case "black":
this.css.insert(".app-content, .app-columns-container { background-color: #444448 !important }");
this.css.insert(".column-header-temp { background-color: transparent !important }");
@ -429,36 +441,36 @@ enabled(){
}
}
if (this.config.showCharacterCount){
if (this.config.showCharacterCount) {
this.css.insert("#tduck .js-character-count.is-hidden { display: inline !important }");
}
if (this.config.hideTweetActions){
if (this.config.hideTweetActions) {
this.css.insert(".tweet-action { opacity: 0; }");
this.css.insert(".tweet-actions.is-visible .tweet-action { opacity: 0.5 }");
this.css.insert(".is-favorite .tweet-action, .is-retweet .tweet-action { opacity: 0.5; visibility: visible !important }");
this.css.insert(".tweet:hover .tweet-action, .tweet-action.is-selected, .is-favorite .tweet-action[rel='favorite'], .is-retweet .tweet-action[rel='retweet'] { opacity: 1 !important; visibility: visible !important }");
}
if (this.config.moveTweetActionsToRight){
if (this.config.moveTweetActionsToRight) {
this.css.insert("#tduck .tweet-actions { float: right !important; width: auto !important }");
this.css.insert("#tduck .tweet-actions > li:nth-child(4) { margin-right: 2px !important }");
}
if (this.config.forceArialFont){
if (this.config.forceArialFont) {
this.css.insert("#tduck { font-family: Arial, sans-serif; font-weight: 400 }");
this.css.insert("#tduck input, #tduck label, #tduck select, #tduck textarea { font-family: Arial }")
this.css.insert("#tduck input, #tduck label, #tduck select, #tduck textarea { font-family: Arial }");
}
if (this.config.increaseQuoteTextSize){
if (this.config.increaseQuoteTextSize) {
this.css.insert(".quoted-tweet { font-size: 1em !important }");
}
if (this.config.smallComposeTextSize){
if (this.config.smallComposeTextSize) {
this.css.insert("#tduck .compose-text { font-size: 12px !important; height: 120px !important }");
}
if (this.config.revertIcons){
if (this.config.revertIcons) {
let iconData = [
[ "twitter-bird", "00" ],
[ "mention", "01" ],
@ -571,26 +583,26 @@ ${iconData.map(entry => `#tduck .icon-${entry[0]}:before{content:\"\\f0${entry[1
document.head.appendChild(this.icons);
}
if (currentTheme === "black"){
if (currentTheme === "black") {
$TDP.readFileRoot(this.$token, "theme.black.css").then(contents => {
if (this.theme){
if (this.theme) {
this.theme.element.innerHTML = contents;
TD.settings.setTheme("dark"); // forces refresh of notification head tag
}
});
}
if (this.config.columnWidth[0] === '/'){
if (this.config.columnWidth[0] === "/") {
let cols = this.config.columnWidth.slice(1);
this.css.insert(".column { width: calc((100vw - 205px) / "+cols+" - 6px) !important; min-width: 160px }");
this.css.insert(".is-condensed .column { width: calc((100vw - 65px) / "+cols+" - 6px) !important }");
this.css.insert(".column { width: calc((100vw - 205px) / " + cols + " - 6px) !important; min-width: 160px }");
this.css.insert(".is-condensed .column { width: calc((100vw - 65px) / " + cols + " - 6px) !important }");
}
else{
this.css.insert(".column { width: "+this.config.columnWidth+" !important }");
else {
this.css.insert(".column { width: " + this.config.columnWidth + " !important }");
}
switch(this.config.columnWidth){
switch (this.config.columnWidth) {
case "/6":
TD.settings.setColumnWidth("narrow");
break;
@ -605,11 +617,19 @@ ${iconData.map(entry => `#tduck .icon-${entry[0]}:before{content:\"\\f0${entry[1
break;
}
switch(this.config.fontSize){
case "13px": TD.settings.setFontSize("small"); break;
case "14px": TD.settings.setFontSize("medium"); break;
case "15px": TD.settings.setFontSize("large"); break;
default: TD.settings.setFontSize(parseInt(this.config.fontSize, 10) >= 16 ? "largest" : "smallest"); break;
switch (this.config.fontSize) {
case "13px":
TD.settings.setFontSize("small");
break;
case "14px":
TD.settings.setFontSize("medium");
break;
case "15px":
TD.settings.setFontSize("large");
break;
default:
TD.settings.setFontSize(parseInt(this.config.fontSize, 10) >= 16 ? "largest" : "smallest");
break;
}
$TDP.injectIntoNotificationsBefore(this.$token, "css", "</head>", `
@ -648,7 +668,7 @@ ${notificationScrollbarColor ? `
};
this.uiShowActionsMenuEvent = () => {
if (this.config.moveTweetActionsToRight){
if (this.config.moveTweetActionsToRight) {
$(".js-dropdown.pos-r").toggleClass("pos-r pos-l");
}
};
@ -674,7 +694,7 @@ ready(){
// modal
$("[data-action='settings-menu']").on("click", this.onSettingsMenuClickedEvent);
$(".js-app").append('<div id="td-design-plugin-modal" class="js-modal settings-modal ovl scroll-v scroll-styled-v"></div>');
$(".js-app").append("<div id=\"td-design-plugin-modal\" class=\"js-modal settings-modal ovl scroll-v scroll-styled-v\"></div>");
// global settings override
const me = this;
@ -682,22 +702,21 @@ ready(){
this.prevFuncSettingsGetInfo = TD.components.GlobalSettings.prototype.getInfo;
this.prevFuncSettingsSwitchTab = TD.components.GlobalSettings.prototype.switchTab;
TD.components.GlobalSettings.prototype.getInfo = function(){
TD.components.GlobalSettings.prototype.getInfo = function() {
let data = me.prevFuncSettingsGetInfo.apply(this, arguments);
data.tabs.push({
title: "Layout & Design",
action: "tdp-edit-design"
title: "Layout & Design", action: "tdp-edit-design"
});
return data;
};
TD.components.GlobalSettings.prototype.switchTab = function(tab){
if (tab === "tdp-edit-design"){
TD.components.GlobalSettings.prototype.switchTab = function(tab) {
if (tab === "tdp-edit-design") {
me.configure();
}
else{
else {
return me.prevFuncSettingsSwitchTab.apply(this, arguments);
}
};
@ -708,28 +727,28 @@ configure(){
this.htmlModal = contents;
new this.customDesignModal();
}).catch(err => {
$TD.alert("error", "Error loading the configuration dialog: "+err.message);
$TD.alert("error", "Error loading the configuration dialog: " + err.message);
});
}
disabled(){
if (this.css){
if (this.css) {
this.css.remove();
}
if (this.theme){
if (this.theme) {
this.theme.remove();
}
if (this.icons){
if (this.icons) {
document.head.removeChild(this.icons);
}
if (this.optimizations){
if (this.optimizations) {
this.optimizations.remove();
}
if (this.optimizationTimer){
if (this.optimizationTimer) {
window.clearTimeout(this.optimizationTimer);
}

View File

@ -187,12 +187,12 @@
#edit-design-panel {
width: 693px;
height: 424px;
background-color: #FFF;
background-color: #fff;
box-shadow: 0 0 10px rgba(17, 17, 17, 0.5);
}
#edit-design-panel .mdl-header {
color: #8899A6;
color: #8899a6;
}
#edit-design-panel .mdl-inner {
@ -200,8 +200,8 @@
}
#edit-design-panel .mdl-content {
border: 1px solid #CCD6DD;
background: #EAEAEA;
border: 1px solid #ccd6dd;
background: #eaeaea;
}
#edit-design-panel-inner-cols {
@ -260,8 +260,8 @@
padding: 16px 14px 8px;
box-sizing: border-box;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.1);
border: 2px solid #F5F8FA;
background-color: #F5F8FA;
border: 2px solid #f5f8fa;
background-color: #f5f8fa;
}
.td-avatar-shape-item-outer:hover {
@ -279,6 +279,6 @@
.td-avatar-shape {
width: 48px;
height: 48px;
background-color: #71BAF2;
background-color: #71baf2;
}
</style>

View File

@ -13,12 +13,12 @@ enabled(){
];
this.skinToneData = [
[ "", "#FFDD67" ],
[ "1F3FB", "#FFE1BD" ],
[ "1F3FC", "#FED0AC" ],
[ "1F3FD", "#D6A57C" ],
[ "1F3FE", "#B47D56" ],
[ "1F3FF", "#8A6859" ],
[ "", "#ffdd67" ],
[ "1F3FB", "#ffe1bd" ],
[ "1F3FC", "#fed0ac" ],
[ "1F3FD", "#d6a57c" ],
[ "1F3FE", "#b47d56" ],
[ "1F3FF", "#8a6859" ],
];
this.emojiData1 = []; // no skin tones, prepended
@ -51,10 +51,10 @@ enabled(){
// layout
let buttonHTML = '<button class="needsclick btn btn-on-blue txt-left padding-v--6 padding-h--8 emoji-keyboard-popup-btn"><i class="icon icon-heart"></i></button>';
let buttonHTML = "<button class=\"needsclick btn btn-on-blue txt-left padding-v--6 padding-h--8 emoji-keyboard-popup-btn\"><i class=\"icon icon-heart\"></i></button>";
this.prevComposeMustache = TD.mustaches["compose/docked_compose.mustache"];
window.TDPF_injectMustache("compose/docked_compose.mustache", "append", '<div class="cf margin-t--12 margin-b--30">', buttonHTML);
window.TDPF_injectMustache("compose/docked_compose.mustache", "append", "<div class=\"cf margin-t--12 margin-b--30\">", buttonHTML);
this.getDrawerInput = () => {
return $(".js-compose-text", me.composeDrawer);
@ -85,10 +85,10 @@ enabled(){
$(".emoji-keyboard-popup-btn").removeClass("is-selected");
if (refocus){
if (refocus) {
this.getDrawerInput().focus();
if (lastEmojiKeyword && lastEmojiPosition === 0){
if (lastEmojiKeyword && lastEmojiPosition === 0) {
document.execCommand("insertText", false, lastEmojiKeyword);
}
}
@ -100,13 +100,13 @@ enabled(){
let index = 0;
let html = [ "<p style='font-size:13px;color:#444;margin:4px;text-align:center'>Please, note that some emoji may not show up correctly in the text box above, but they will display in the tweet.</p>" ];
for(let array of [ this.emojiData1, this.emojiData2[skinTone], this.emojiData3 ]){
for(let emoji of array){
if (emoji === "___"){
for (let array of [ this.emojiData1, this.emojiData2[skinTone], this.emojiData3 ]) {
for (let emoji of array) {
if (emoji === "___") {
html.push("<div class='separator'></div>");
}
else{
html.push(TD.util.cleanWithEmoji(emoji).replace(' class="emoji" draggable="false"', ''));
else {
html.push(TD.util.cleanWithEmoji(emoji).replace(" class=\"emoji\" draggable=\"false\"", ""));
index++;
}
}
@ -123,12 +123,12 @@ enabled(){
let info = container.children("p:first");
let separators = container.children("div");
if (keywords.length === 0){
if (keywords.length === 0) {
info.css("display", "block");
separators.css("display", "block");
emoji.css("display", "inline");
}
else{
else {
info.css("display", "none");
separators.css("display", "none");
@ -138,28 +138,28 @@ enabled(){
};
const selectSkinTone = skinTone => {
let selectedEle = this.currentKeyboard.children[2].querySelector("[data-tone='"+this.selectedSkinTone+"']");
let selectedEle = this.currentKeyboard.children[2].querySelector("[data-tone='" + this.selectedSkinTone + "']");
selectedEle && selectedEle.classList.remove("sel");
this.selectedSkinTone = skinTone;
this.currentKeyboard.children[1].innerHTML = generateEmojiHTML(skinTone);
this.currentKeyboard.children[2].querySelector("[data-tone='"+this.selectedSkinTone+"']").classList.add("sel");
this.currentKeyboard.children[2].querySelector("[data-tone='" + this.selectedSkinTone + "']").classList.add("sel");
updateFilters();
};
this.generateKeyboard = (left, top) => {
let outer = document.createElement("div");
outer.classList.add("emoji-keyboard");
outer.style.left = left+"px";
outer.style.top = top+"px";
outer.style.left = left + "px";
outer.style.top = top + "px";
let keyboard = document.createElement("div");
keyboard.classList.add("emoji-keyboard-list");
keyboard.addEventListener("click", function(e){
keyboard.addEventListener("click", function(e) {
let ele = e.target;
if (ele.tagName === "IMG"){
if (ele.tagName === "IMG") {
insertEmoji(ele.getAttribute("src"), ele.getAttribute("alt"));
}
@ -171,7 +171,7 @@ enabled(){
search.classList.add("emoji-keyboard-search");
let skintones = document.createElement("div");
skintones.innerHTML = me.skinToneData.map(entry => "<div data-tone='"+entry[0]+"' style='background-color:"+entry[1]+"'></div>").join("");
skintones.innerHTML = me.skinToneData.map(entry => "<div data-tone='" + entry[0] + "' style='background-color:" + entry[1] + "'></div>").join("");
skintones.classList.add("emoji-keyboard-skintones");
outer.appendChild(search);
@ -179,15 +179,15 @@ enabled(){
outer.appendChild(skintones);
$(".js-app").append(outer);
skintones.addEventListener("click", function(e){
if (e.target.hasAttribute("data-tone")){
skintones.addEventListener("click", function(e) {
if (e.target.hasAttribute("data-tone")) {
selectSkinTone(e.target.getAttribute("data-tone") || "");
}
e.stopPropagation();
});
search.addEventListener("click", function(e){
search.addEventListener("click", function(e) {
e.stopPropagation();
});
@ -196,7 +196,7 @@ enabled(){
wasSearchFocused = false;
searchInput.addEventListener("input", function(e){
searchInput.addEventListener("input", function(e) {
me.currentKeywords = e.target.value.split(" ").filter(kw => kw.length > 0).map(kw => kw.toLowerCase());
updateFilters();
@ -204,11 +204,11 @@ enabled(){
e.stopPropagation();
});
searchInput.addEventListener("keydown", function(e){
if (e.keyCode === 13 && $(this).val().length){ // enter
searchInput.addEventListener("keydown", function(e) {
if (e.keyCode === 13 && $(this).val().length) { // enter
let ele = $(".emoji-keyboard-list").children("img").filter(":visible").first();
if (ele.length > 0){
if (ele.length > 0) {
insertEmoji(ele[0].getAttribute("src"), ele[0].getAttribute("alt"));
}
@ -216,11 +216,11 @@ enabled(){
}
});
searchInput.addEventListener("click", function(){
searchInput.addEventListener("click", function() {
$(this).select();
});
searchInput.addEventListener("focus", function(){
searchInput.addEventListener("focus", function() {
wasSearchFocused = true;
});
@ -228,7 +228,7 @@ enabled(){
selectSkinTone(this.selectedSkinTone);
this.currentSpanner = document.createElement("div");
this.currentSpanner.style.height = ($(this.currentKeyboard).height()-10)+"px";
this.currentSpanner.style.height = ($(this.currentKeyboard).height() - 10) + "px";
$(".emoji-keyboard-popup-btn").parent().after(this.currentSpanner);
this.getDrawerScroller().trigger("scroll");
@ -246,30 +246,30 @@ enabled(){
let posStart = input[0].selectionStart;
let posEnd = input[0].selectionEnd;
input.val(val.slice(0, posStart)+alt+val.slice(posEnd));
input.val(val.slice(0, posStart) + alt + val.slice(posEnd));
input.trigger("change");
input[0].selectionStart = posStart+alt.length;
input[0].selectionEnd = posStart+alt.length;
input[0].selectionStart = posStart + alt.length;
input[0].selectionEnd = posStart + alt.length;
lastEmojiKeyword = null;
if (wasSearchFocused){
if (wasSearchFocused) {
$(".emoji-keyboard-search").children("input").focus();
}
else{
else {
input.focus();
}
};
// general event handlers
this.emojiKeyboardButtonClickEvent = function(e){
if (me.currentKeyboard){
this.emojiKeyboardButtonClickEvent = function(e) {
if (me.currentKeyboard) {
$(this).blur();
hideKeyboard(true);
}
else{
else {
me.generateKeyboard($(this).offset().left, getKeyboardTop());
$(this).addClass("is-selected");
}
@ -277,17 +277,17 @@ enabled(){
e.stopPropagation();
};
this.composerScrollEvent = function(e){
if (me.currentKeyboard){
me.currentKeyboard.style.marginTop = (-$(this).scrollTop())+"px";
this.composerScrollEvent = function(e) {
if (me.currentKeyboard) {
me.currentKeyboard.style.marginTop = (-$(this).scrollTop()) + "px";
}
};
this.composeInputKeyDownEvent = function(e){
if (lastEmojiKeyword && (e.keyCode === 8 || e.keyCode === 27)){ // backspace, escape
this.composeInputKeyDownEvent = function(e) {
if (lastEmojiKeyword && (e.keyCode === 8 || e.keyCode === 27)) { // backspace, escape
let ele = $(this)[0];
if (ele.selectionStart === lastEmojiPosition){
if (ele.selectionStart === lastEmojiPosition) {
ele.selectionStart -= lastEmojiLength; // selects the emoji
document.execCommand("insertText", false, lastEmojiKeyword);
@ -299,17 +299,17 @@ enabled(){
}
};
this.composeInputKeyPressEvent = function(e){
if (String.fromCharCode(e.which) === ':'){
this.composeInputKeyPressEvent = function(e) {
if (String.fromCharCode(e.which) === ":") {
let ele = $(this);
let val = ele.val();
let firstColon = val.lastIndexOf(':', ele[0].selectionStart);
let firstColon = val.lastIndexOf(":", ele[0].selectionStart);
if (firstColon === -1) {
return;
}
let search = val.substring(firstColon+1, ele[0].selectionStart).toLowerCase();
let search = val.substring(firstColon + 1, ele[0].selectionStart).toLowerCase();
if (!/^[a-z_]+$/.test(search)) {
return;
}
@ -321,51 +321,51 @@ enabled(){
let foundNames = me.emojiNames.filter(name => keywords.every(kw => name.includes(kw)));
if (foundNames.length === 0){
if (foundNames.length === 0) {
return;
}
else if (foundNames.length > 1 && foundNames.includes(search)){
else if (foundNames.length > 1 && foundNames.includes(search)) {
foundNames = [ search ];
}
lastEmojiKeyword = `:${search}:`;
lastEmojiPosition = lastEmojiLength = 0;
if (foundNames.length === 1){
if (foundNames.length === 1) {
let foundIndex = me.emojiNames.indexOf(foundNames[0]);
let foundEmoji;
for(let array of [ me.emojiData1, me.emojiData2[me.selectedSkinTone], me.emojiData3 ]){
for (let array of [ me.emojiData1, me.emojiData2[me.selectedSkinTone], me.emojiData3 ]) {
let realArray = array.filter(ele => ele !== "___");
if (foundIndex >= realArray.length){
if (foundIndex >= realArray.length) {
foundIndex -= realArray.length;
}
else{
else {
foundEmoji = realArray[foundIndex];
break;
}
}
if (foundEmoji){
if (foundEmoji) {
e.preventDefault();
ele.val(val.substring(0, firstColon)+foundEmoji+val.substring(ele[0].selectionStart));
ele[0].selectionEnd = ele[0].selectionStart = firstColon+foundEmoji.length;
ele.val(val.substring(0, firstColon) + foundEmoji + val.substring(ele[0].selectionStart));
ele[0].selectionEnd = ele[0].selectionStart = firstColon + foundEmoji.length;
ele.trigger("change");
ele.focus();
lastEmojiPosition = firstColon+foundEmoji.length;
lastEmojiPosition = firstColon + foundEmoji.length;
lastEmojiLength = foundEmoji.length;
}
}
else if (foundNames.length > 1 && $(".js-app-content").is(".is-open")){
else if (foundNames.length > 1 && $(".js-app-content").is(".is-open")) {
e.preventDefault();
ele.val(val.substring(0, firstColon)+val.substring(ele[0].selectionStart));
ele.val(val.substring(0, firstColon) + val.substring(ele[0].selectionStart));
ele[0].selectionEnd = ele[0].selectionStart = firstColon;
ele.trigger("change");
if (!me.currentKeyboard){
if (!me.currentKeyboard) {
$(".emoji-keyboard-popup-btn").click();
}
@ -373,40 +373,40 @@ enabled(){
document.execCommand("insertText", false, keywords.join(" "));
}
}
else{
else {
lastEmojiKeyword = null;
}
};
this.composeInputFocusEvent = function(e){
this.composeInputFocusEvent = function(e) {
wasSearchFocused = false;
};
this.composerSendingEvent = function(e){
this.composerSendingEvent = function(e) {
hideKeyboard();
};
this.composerActiveEvent = function(e){
this.composerActiveEvent = function(e) {
$(".emoji-keyboard-popup-btn", me.composeDrawer).on("click", me.emojiKeyboardButtonClickEvent);
$(".js-docked-compose .js-compose-scroller > .scroll-v", me.composeDrawer).on("scroll", me.composerScrollEvent);
};
this.documentClickEvent = function(e){
if (me.currentKeyboard && $(e.target).closest(".compose-text-container").length === 0){
this.documentClickEvent = function(e) {
if (me.currentKeyboard && $(e.target).closest(".compose-text-container").length === 0) {
hideKeyboard();
}
};
this.documentKeyEvent = function(e){
if (me.currentKeyboard && e.keyCode === 27){ // escape
this.documentKeyEvent = function(e) {
if (me.currentKeyboard && e.keyCode === 27) { // escape
hideKeyboard(true);
e.stopPropagation();
}
};
this.uploadFilesEvent = function(e){
if (me.currentKeyboard){
me.currentKeyboard.style.top = getKeyboardTop()+"px";
this.uploadFilesEvent = function(e) {
if (me.currentKeyboard) {
me.currentKeyboard.style.top = getKeyboardTop() + "px";
}
};
@ -414,7 +414,7 @@ enabled(){
let maybeDockedComposePanel = $(".js-docked-compose");
if (maybeDockedComposePanel.length){
if (maybeDockedComposePanel.length) {
maybeDockedComposePanel.find(".cf.margin-t--12.margin-b--30").first().append(buttonHTML);
this.composerActiveEvent();
}
@ -437,18 +437,18 @@ ready(){
// HTML generation
const convUnicode = function(codePt){
if (codePt > 0xFFFF){
const convUnicode = function(codePt) {
if (codePt > 0xFFFF) {
codePt -= 0x10000;
return String.fromCharCode(0xD800+(codePt>>10), 0xDC00+(codePt&0x3FF));
return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
}
else{
else {
return String.fromCharCode(codePt);
}
};
$TDP.readFileRoot(this.$token, "emoji-ordering.txt").then(contents => {
for(let skinTone of this.skinToneList){
for (let skinTone of this.skinToneList) {
this.emojiData2[skinTone] = [];
}
@ -463,12 +463,12 @@ ready(){
let addDeclaration2 = (tone, decl) => {
let gen = decl.split(" ").map(mapUnicode).join("");
if (tone === null){
for(let skinTone of this.skinToneList){
if (tone === null) {
for (let skinTone of this.skinToneList) {
this.emojiData2[skinTone].push(gen);
}
}
else{
else {
this.emojiData2[tone].push(gen);
}
};
@ -481,70 +481,76 @@ ready(){
let skinToneState = 0;
for(let line of contents.split("\n")){
if (line[0] === '@'){
switch(skinToneState){
case 0: this.emojiData1.push("___"); break;
case 1: this.skinToneList.forEach(skinTone => this.emojiData2[skinTone].push("___")); break;
case 2: this.emojiData3.push("___"); break;
for (let line of contents.split("\n")) {
if (line[0] === "@") {
switch (skinToneState) {
case 0:
this.emojiData1.push("___");
break;
case 1:
this.skinToneList.forEach(skinTone => this.emojiData2[skinTone].push("___"));
break;
case 2:
this.emojiData3.push("___");
break;
}
continue;
}
else if (line[0] === '#'){
if (line[1] === '1'){
else if (line[0] === "#") {
if (line[1] === "1") {
skinToneState = 1;
}
else if (line[1] === '2'){
else if (line[1] === "2") {
skinToneState = 2;
}
continue;
}
let semicolon = line.indexOf(';');
let semicolon = line.indexOf(";");
let decl = line.slice(0, semicolon);
let desc = line.slice(semicolon+1).toLowerCase();
let desc = line.slice(semicolon + 1).toLowerCase();
if (skinToneState === 1){
let skinIndex = decl.indexOf('$');
if (skinToneState === 1) {
let skinIndex = decl.indexOf("$");
if (skinIndex !== -1){
if (skinIndex !== -1) {
let declPre = decl.slice(0, skinIndex);
let declPost = decl.slice(skinIndex+1);
let declPost = decl.slice(skinIndex + 1);
for(let skinTone of this.skinToneNonDefaultList){
for (let skinTone of this.skinToneNonDefaultList) {
this.emojiData2[skinTone].pop();
addDeclaration2(skinTone, declPre+skinTone+declPost);
addDeclaration2(skinTone, declPre + skinTone + declPost);
}
}
else{
else {
addDeclaration2(null, decl);
this.emojiNames.push(desc);
}
}
else if (skinToneState === 2){
else if (skinToneState === 2) {
addDeclaration3(decl);
this.emojiNames.push(desc);
}
else if (skinToneState === 0){
else if (skinToneState === 0) {
addDeclaration1(decl);
this.emojiNames.push(desc);
}
}
}).catch(err => {
$TD.alert("error", "Problem loading emoji keyboard: "+err.message);
$TD.alert("error", "Problem loading emoji keyboard: " + err.message);
});
}
disabled(){
this.css.remove();
if (this.currentKeyboard){
if (this.currentKeyboard) {
$(this.currentKeyboard).remove();
}
if (this.currentSpanner){
if (this.currentSpanner) {
$(this.currentSpanner).remove();
}

View File

@ -12,15 +12,15 @@ enabled(){
let query;
if (configuration.useAdvancedSelector){
if (configuration.customSelector){
if (configuration.useAdvancedSelector) {
if (configuration.customSelector) {
let customSelectorDef = configuration.customSelector.toString();
if (customSelectorDef.startsWith("function (column){")){
if (customSelectorDef.startsWith("function (column){")) {
$TD.alert("warning", "Plugin reply-account has invalid configuration: customSelector needs to be updated due to TweetDeck changes, please read the default configuration file for the updated guide");
return;
}
else if (customSelectorDef.startsWith("function (type,")){
else if (customSelectorDef.startsWith("function (type,")) {
$TD.alert("warning", "Plugin reply-account has invalid configuration: the type parameter is no longer present due to TweetDeck changes, please read the default configuration file for the updated guide");
return;
}
@ -31,18 +31,18 @@ enabled(){
let feeds = column.getFeeds();
let accountText = "";
if (feeds.length === 1){
if (feeds.length === 1) {
let metadata = feeds[0].getMetadata();
let id = metadata.ownerId || metadata.id;
if (id){
if (id) {
accountText = TD.cache.names.getScreenName(id);
}
else{
else {
let account = TD.storage.accountController.get(feeds[0].getAccountKey());
if (account){
accountText = "@"+account.getUsername();
if (account) {
accountText = "@" + account.getUsername();
}
}
}
@ -51,48 +51,48 @@ enabled(){
let title = header.children(".column-heading");
let titleText = title.length ? title.text() : header.children(".column-title-edit-box").val();
try{
try {
query = configuration.customSelector(titleText, accountText, column, section.hasClass("column-temp"));
}catch(e){
$TD.alert("warning", "Plugin reply-account has invalid configuration: customSelector threw an error: "+e.message);
} catch (e) {
$TD.alert("warning", "Plugin reply-account has invalid configuration: customSelector threw an error: " + e.message);
return;
}
}
else{
else {
$TD.alert("warning", "Plugin reply-account has invalid configuration: useAdvancedSelector is true, but customSelector function is missing");
return;
}
}
else{
else {
query = configuration.defaultAccount;
if (query === ""){
if (query === "") {
query = "#preferred";
}
else if (typeof query !== "string"){
else if (typeof query !== "string") {
query = "#default";
}
}
if (typeof query === "undefined"){
if (typeof query === "undefined") {
query = "#preferred";
}
if (typeof query !== "string"){
if (typeof query !== "string") {
return;
}
else if (query.length === 0){
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);
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;
}
let identifier = null;
switch(query){
switch (query) {
case "#preferred":
identifier = TD.storage.clientController.client.getDefaultAccount();
break;
@ -109,19 +109,19 @@ enabled(){
return;
default:
if (query[0] === '@'){
if (query[0] === "@") {
let 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);
if (obj.length === 0) {
$TD.alert("warning", "Plugin reply-account has invalid configuration: requested account not found: " + query);
return;
}
else{
else {
identifier = obj[0].privateState.key;
}
}
else{
$TD.alert("warning", "Plugin reply-account has invalid configuration: unknown requested account query: "+query);
else {
$TD.alert("warning", "Plugin reply-account has invalid configuration: unknown requested account query: " + query);
return;
}
}
@ -136,7 +136,7 @@ enabled(){
}
ready(){
for(let event of [ "uiInlineComposeTweet", "uiDockedComposeTweet" ]){
for (let event of [ "uiInlineComposeTweet", "uiDockedComposeTweet" ]) {
$(document).on(event, this.uiComposeTweetEvent);
window.TDPF_prioritizeNewestEvent(document, event);
}

View File

@ -10,25 +10,25 @@ enabled(){
const configFile = "config.json";
$TDP.checkFileExists(this.$token, configFile).then(exists => {
if (!exists){
if (!exists) {
$TDP.writeFile(this.$token, configFile, JSON.stringify(this.config));
}
else{
else {
$TDP.readFile(this.$token, configFile, true).then(contents => {
try{
try {
$.extend(true, this.config, JSON.parse(contents));
}catch(err){
} catch (err) {
// why :(
}
}).catch(err => {
$TD.alert("error", "Problem loading configuration for the template plugin: "+err.message);
$TD.alert("error", "Problem loading configuration for the template plugin: " + err.message);
});
}
});
this.saveConfig = () => {
$TDP.writeFile(this.$token, configFile, JSON.stringify(this.config)).catch(err => {
$TD.alert("error", "Problem saving configuration for the template plugin: "+err.message);
$TD.alert("error", "Problem saving configuration for the template plugin: " + err.message);
});
};
@ -39,19 +39,19 @@ enabled(){
$TDP.readFileRoot(this.$token, "modal.html").then(contents => {
this.htmlModal = contents;
}).catch(err => {
$TD.alert("error", "Problem loading data for the template plugin: "+err.message);
$TD.alert("error", "Problem loading data for the template plugin: " + err.message);
});
// button
let buttonHTML = '<button class="manage-templates-btn needsclick btn btn-on-blue full-width txt-left margin-b--12 padding-v--6 padding-h--12"><i class="icon icon-bookmark"></i><span class="label padding-ls">Manage templates</span></button>';
let buttonHTML = "<button class=\"manage-templates-btn needsclick btn btn-on-blue full-width txt-left margin-b--12 padding-v--6 padding-h--12\"><i class=\"icon icon-bookmark\"></i><span class=\"label padding-ls\">Manage templates</span></button>";
this.prevComposeMustache = TD.mustaches["compose/docked_compose.mustache"];
window.TDPF_injectMustache("compose/docked_compose.mustache", "prepend", '<div class="js-tweet-type-button">', buttonHTML);
window.TDPF_injectMustache("compose/docked_compose.mustache", "prepend", "<div class=\"js-tweet-type-button\">", buttonHTML);
let dockedComposePanel = $(".js-docked-compose");
if (dockedComposePanel.length){
if (dockedComposePanel.length) {
dockedComposePanel.find(".js-tweet-type-button").first().before(buttonHTML);
}
@ -64,61 +64,61 @@ enabled(){
let data = [];
let tokenNames = Object.keys(tokenData);
for(let currentIndex = 0; currentIndex < contents.length; currentIndex++){
if (contents[currentIndex] === '\\'){
contents = contents.substring(0, currentIndex)+contents.substring(currentIndex+1);
for (let currentIndex = 0; currentIndex < contents.length; currentIndex++) {
if (contents[currentIndex] === "\\") {
contents = contents.substring(0, currentIndex) + contents.substring(currentIndex + 1);
continue;
}
else if (contents[currentIndex] !== '{'){
else if (contents[currentIndex] !== "{") {
continue;
}
startIndex = currentIndex+1;
startIndex = currentIndex + 1;
for(; startIndex < contents.length; startIndex++){
if (!tokenNames.some(name => contents[startIndex] === name[startIndex-currentIndex-1])){
for (; startIndex < contents.length; startIndex++) {
if (!tokenNames.some(name => contents[startIndex] === name[startIndex - currentIndex - 1])) {
break;
}
}
endIndex = startIndex;
let token = contents.substring(currentIndex+1, startIndex);
let token = contents.substring(currentIndex + 1, startIndex);
let replacement = tokenData[token] || "";
let entry = [ token, currentIndex ];
if (contents[endIndex] === '#'){
if (contents[endIndex] === "#") {
++endIndex;
let bracketCount = 1;
for(; endIndex < contents.length; endIndex++){
if (contents[endIndex] === '{'){
for (; endIndex < contents.length; endIndex++) {
if (contents[endIndex] === "{") {
++bracketCount;
}
else if (contents[endIndex] === '}'){
if (--bracketCount === 0){
entry.push(contents.substring(startIndex+1, endIndex));
else if (contents[endIndex] === "}") {
if (--bracketCount === 0) {
entry.push(contents.substring(startIndex + 1, endIndex));
break;
}
}
else if (contents[endIndex] === '#'){
entry.push(contents.substring(startIndex+1, endIndex));
else if (contents[endIndex] === "#") {
entry.push(contents.substring(startIndex + 1, endIndex));
startIndex = endIndex;
}
else if (contents[endIndex] === '\\'){
contents = contents.substring(0, endIndex)+contents.substring(endIndex+1);
else if (contents[endIndex] === "\\") {
contents = contents.substring(0, endIndex) + contents.substring(endIndex + 1);
}
}
}
else if (contents[endIndex] !== '}'){
else if (contents[endIndex] !== "}") {
continue;
}
data.push(entry);
contents = contents.substring(0, currentIndex)+replacement+contents.substring(endIndex+1);
contents = contents.substring(0, currentIndex) + replacement + contents.substring(endIndex + 1);
currentIndex += replacement.length;
}
@ -127,21 +127,21 @@ enabled(){
const doAjaxRequest = (index, url, evaluator) => {
return new Promise((resolve, reject) => {
if (!url){
if (!url) {
resolve([ index, "{ajax}" ]);
return;
}
$TD.makeGetRequest(url, function(data){
if (evaluator){
resolve([ index, eval(evaluator.replace(/\$/g, "'"+data.replace(/(["'\\\n\r\u2028\u2029])/g, "\\$1")+"'"))]);
$TD.makeGetRequest(url, function(data) {
if (evaluator) {
resolve([ index, eval(evaluator.replace(/\$/g, "'" + data.replace(/(["'\\\n\r\u2028\u2029])/g, "\\$1") + "'")) ]);
}
else{
else {
resolve([ index, data ]);
}
}, function(err){
}, function(err) {
resolve([ index, "" ]);
$TD.alert("error", "Error executing AJAX request: "+err);
$TD.alert("error", "Error executing AJAX request: " + err);
});
});
};
@ -152,12 +152,12 @@ enabled(){
return;
}
let value = append ? ele.val()+contents : contents;
let value = append ? ele.val() + contents : contents;
let prevLength = value.length;
let tokens = null;
[value, tokens] = readTemplateTokens(value, {
[ value, tokens ] = readTemplateTokens(value, {
"cursor": "",
"ajax": "(...)"
});
@ -171,18 +171,18 @@ enabled(){
let promises = [];
let indexOffset = 0;
for(let token of tokens){
switch(token[0]){
for (let token of tokens) {
switch (token[0]) {
case "cursor":
let [, index1, length ] = token;
let [ , index1, length ] = token;
ele[0].selectionStart = index1;
ele[0].selectionEnd = index1+(length | 0 || 0);
ele[0].selectionEnd = index1 + (length | 0 || 0);
break;
case "ajax":
let [, index2, evaluator, url ] = token;
let [ , index2, evaluator, url ] = token;
if (!url){
if (!url) {
url = evaluator;
evaluator = null;
}
@ -192,7 +192,7 @@ enabled(){
}
}
if (promises.length > 0){
if (promises.length > 0) {
let selStart = ele[0].selectionStart;
let selEnd = ele[0].selectionEnd;
@ -202,12 +202,12 @@ enabled(){
const placeholderLen = 5; // "(...)".length
let indexOffset = 0;
for(let value of values){
let diff = value[1].length-placeholderLen;
let realIndex = indexOffset+value[0];
for (let value of values) {
let diff = value[1].length - placeholderLen;
let realIndex = indexOffset + value[0];
let val = ele.val();
ele.val(val.substring(0, realIndex)+value[1]+val.substring(realIndex+placeholderLen));
ele.val(val.substring(0, realIndex) + value[1] + val.substring(realIndex + placeholderLen));
indexOffset += diff;
}
@ -216,12 +216,12 @@ enabled(){
ele.trigger("change");
ele.focus();
ele[0].selectionStart = selStart+indexOffset;
ele[0].selectionEnd = selEnd+indexOffset;
ele[0].selectionStart = selStart + indexOffset;
ele[0].selectionEnd = selEnd + indexOffset;
});
}
if (!append){
if (!append) {
hideTemplateModal();
}
};
@ -246,19 +246,19 @@ enabled(){
let ele = $("#templates-modal-wrap").first();
ele.on("click", "li[data-template]", function(e){
ele.on("click", "li[data-template]", function(e) {
let template = me.config.templates[$(this).attr("data-template")];
useTemplate(template.contents, e.shiftKey);
});
ele.on("click", "li[data-template] i[data-action]", function(e){
ele.on("click", "li[data-template] i[data-action]", function(e) {
let identifier = $(this).closest("li").attr("data-template");
switch($(this).attr("data-action")){
switch ($(this).attr("data-action")) {
case "edit-template":
let editor = $("#template-editor");
if (editor.hasClass("invisible")){
if (editor.hasClass("invisible")) {
toggleEditor();
}
@ -273,7 +273,7 @@ enabled(){
delete me.config.templates[identifier];
onTemplatesUpdated(true);
if (me.editingTemplate === identifier){
if (me.editingTemplate === identifier) {
me.editingTemplate = null;
}
@ -283,13 +283,13 @@ enabled(){
e.stopPropagation();
});
ele.on("click", ".template-editor-tips-button", function(e){
ele.on("click", ".template-editor-tips-button", function(e) {
$(this).children(".icon").toggleClass("icon-arrow-d icon-arrow-u");
ele.find(".template-editor-tips").toggle();
});
ele.on("click", "button", function(e){
switch($(this).attr("data-action")){
ele.on("click", "button", function(e) {
switch ($(this).attr("data-action")) {
case "new-template":
case "editor-cancel":
toggleEditor();
@ -298,14 +298,14 @@ enabled(){
case "editor-confirm":
let editor = $("#template-editor");
if (me.editingTemplate !== null){
if (me.editingTemplate !== null) {
delete me.config.templates[me.editingTemplate];
}
let name = $("[name='template-name']", editor).val();
let identifier = name.toLowerCase().replace(/[^a-z0-9]/g, "")+"-"+(Math.random().toString(36).substring(2, 7));
let identifier = name.toLowerCase().replace(/[^a-z0-9]/g, "") + "-" + (Math.random().toString(36).substring(2, 7));
if (name.trim().length === 0){
if (name.trim().length === 0) {
alert("Please, include a name for your template.");
$("[name='template-name']", editor).focus();
return;
@ -339,7 +339,7 @@ enabled(){
let editor = $("#template-editor");
$("[name]", editor).val("");
if ($("button[data-action='new-template']", "#template-list").add(editor).toggleClass("invisible").hasClass("invisible")){
if ($("button[data-action='new-template']", "#template-list").add(editor).toggleClass("invisible").hasClass("invisible")) {
me.editingTemplate = null;
}
};
@ -347,39 +347,39 @@ enabled(){
const onTemplatesUpdated = (save) => {
let eles = [];
for(let identifier of Object.keys(this.config.templates)){
for (let identifier of Object.keys(this.config.templates)) {
eles.push(`<li data-template="${identifier}">
<span class="template-name">${this.config.templates[identifier].name}</span>
<span class="template-actions"><i class="icon icon-edit" data-action="edit-template"></i><i class="icon icon-close" data-action="delete-template"></i></span>
</li>`);
}
if (eles.length === 0){
if (eles.length === 0) {
eles.push("<li>No templates available</li>");
}
$("#template-list").children("ul").html(eles.join(""));
if (save){
if (save) {
this.saveConfig();
}
};
// event handlers
this.manageTemplatesButtonClickEvent = function(e){
if ($("#templates-modal-wrap").length){
this.manageTemplatesButtonClickEvent = function(e) {
if ($("#templates-modal-wrap").length) {
hideTemplateModal();
}
else{
else {
showTemplateModal();
}
$(this).blur();
};
this.drawerToggleEvent = function(e, data){
if (typeof data === "undefined" || data.activeDrawer !== "compose"){
this.drawerToggleEvent = function(e, data) {
if (typeof data === "undefined" || data.activeDrawer !== "compose") {
hideTemplateModal();
}
};

View File

@ -6,32 +6,32 @@ enabled(){
// utility functions
const hasPoll = function(tweet){
const hasPoll = function(tweet) {
return tweet.hasPoll && tweet.hasPoll();
};
const renderTweetPoll = function(tweet){
const renderTweetPoll = function(tweet) {
return `<div class='td-timeline-poll'>${TD.ui.template.render("status/poll", $.extend({}, tweet, {
chirp: tweet
}))}</div>`;
};
const renderPollHook = function(tweet, html){
const renderPollHook = function(tweet, html) {
let ele = null;
if (hasPoll(tweet)){
if (hasPoll(tweet)) {
(ele || (ele = $(html))).find(".js-tweet-body").first().children("div").last().after(renderTweetPoll(tweet));
}
if (tweet.quotedTweet && hasPoll(tweet.quotedTweet)){
if (tweet.quotedTweet && hasPoll(tweet.quotedTweet)) {
(ele || (ele = $(html))).find(".js-quoted-tweet-text").first().after(renderTweetPoll(tweet.quotedTweet));
}
if (ele){
if (ele) {
ele.find(".js-card-container").css("display", "none");
return ele.prop("outerHTML");
}
else{
else {
return html;
}
};
@ -44,18 +44,18 @@ enabled(){
TweetDetailView: TD.components.TweetDetailView.prototype._renderChirp
};
TD.services.TwitterStatus.prototype.render = function(e){
TD.services.TwitterStatus.prototype.render = function(e) {
return renderPollHook(this, funcs.TwitterStatus.apply(this, arguments));
};
TD.services.TwitterActionOnTweet.prototype.render = function(e){
TD.services.TwitterActionOnTweet.prototype.render = function(e) {
return renderPollHook(this.targetTweet, funcs.TwitterActionOnTweet.apply(this, arguments));
};
TD.components.TweetDetailView.prototype._renderChirp = function(){
TD.components.TweetDetailView.prototype._renderChirp = function() {
let result = funcs.TweetDetailView.apply(this, arguments);
if (this.mainChirp.quotedTweet && hasPoll(this.mainChirp.quotedTweet)){
if (this.mainChirp.quotedTweet && hasPoll(this.mainChirp.quotedTweet)) {
$(this.$tweetDetail).find(".js-quoted-tweet-text").first().after(renderTweetPoll(this.mainChirp.quotedTweet));
}