1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-29 11:34:13 +02:00

Add column resetting to clear-columns plugin

This commit is contained in:
chylex 2016-09-25 15:31:18 +02:00
parent 3e9c397494
commit c46aafdab6
2 changed files with 55 additions and 15 deletions
Resources/Plugins/clear-columns

View File

@ -3,12 +3,13 @@ Clear columns
[description] [description]
- Adds buttons and keyboard shortcuts to quickly clear columns - Adds buttons and keyboard shortcuts to quickly clear columns
- Hold Shift when clicking or using a keyboard shortcut to reset the column instead
[author] [author]
chylex chylex
[version] [version]
1.0 1.1
[website] [website]
https://tweetduck.chylex.com https://tweetduck.chylex.com

View File

@ -11,38 +11,75 @@ enabled(){
TD.controller.stats.columnActionClick("clear"); TD.controller.stats.columnActionClick("clear");
}; };
var clearAllColumns = () => { var resetColumn = (columnName) => {
Object.keys(TD.controller.columnManager.getAll()).forEach(key => clearColumn(key)); var col = TD.controller.columnManager.get(columnName);
col.model.setClearedTimestamp(0);
col.reloadTweets();
};
var forEachColumn = (func) => {
Object.keys(TD.controller.columnManager.getAll()).forEach(func);
}; };
var replaceMustache = (key, search, replace) => { var replaceMustache = (key, search, replace) => {
TD.mustaches[key] = TD.mustaches[key].replace(search, replace); TD.mustaches[key] = TD.mustaches[key].replace(search, replace);
}; };
var wasShiftPressed = false;
var updateShiftState = (pressed) => {
if (pressed != wasShiftPressed){
wasShiftPressed = pressed;
if (pressed){
$(document).on("mousemove", this.eventKeyUp);
}
else{
$(document).off("mousemove", this.eventKeyUp);
}
$("#clear-columns-btn-all").text(pressed ? "Reset all" : "Clear all");
}
};
// prepare event handlers // prepare event handlers
this.eventClearSingle = function(){ this.eventClickSingle = function(e){
clearColumn($(this).closest(".js-column").attr("data-column")); var name = $(this).closest(".js-column").attr("data-column");
e.shiftKey ? resetColumn(name) : clearColumn(name);
}; };
this.eventClearAll = function(){ this.eventClickAll = function(e){
clearAllColumns(); forEachColumn(e.shiftKey ? resetColumn : clearColumn);
}; };
this.eventKeys = function(e){ this.eventKeyDown = function(e){
if (e.keyCode === 46 && (document.activeElement === null || document.activeElement === document.body)){ // 46 = delete if (!(document.activeElement === null || document.activeElement === document.body)){
return;
}
updateShiftState(e.shiftKey);
if (e.keyCode === 46){ // 46 = delete
if (e.altKey){ if (e.altKey){
clearAllColumns(); forEachColumn(e.shiftKey ? resetColumn : clearColumn);
} }
else{ else{
var focusedColumn = $(".js-column.is-focused"); var focusedColumn = $(".js-column.is-focused");
if (focusedColumn.length){ if (focusedColumn.length){
clearColumn(focusedColumn.attr("data-column")); var name = focusedColumn.attr("data-column");
e.shiftKey ? resetColumn(name) : clearColumn(name);
} }
} }
} }
}; };
this.eventKeyUp = function(e){
if (!e.shiftKey){
updateShiftState(false);
}
};
// add column buttons and keyboard shortcut info to UI // add column buttons and keyboard shortcut info to UI
replaceMustache("column/column_header.mustache", "</header>", [ replaceMustache("column/column_header.mustache", "</header>", [
'{{^isTemporary}}', '{{^isTemporary}}',
@ -67,19 +104,21 @@ enabled(){
css.insert(".column-type-message .column-title { margin-right: 115px !important; }"); css.insert(".column-type-message .column-title { margin-right: 115px !important; }");
css.insert(".mark-all-read-link { right: 59px !important; }"); css.insert(".mark-all-read-link { right: 59px !important; }");
css.insert(".open-compose-dm-link { right: 90px !important; }"); css.insert(".open-compose-dm-link { right: 90px !important; }");
css.insert(".btn-options-tray button[data-action='clear'] { display: none !important; }");
} }
ready(){ ready(){
// setup events // setup events
$(document).on("click", "[data-action='td-clearcolumns-dosingle']", this.eventClearSingle); $(document).on("click", "[data-action='td-clearcolumns-dosingle']", this.eventClickSingle);
$(document).on("click", "[data-action='td-clearcolumns-doall']", this.eventClearAll); $(document).on("click", "[data-action='td-clearcolumns-doall']", this.eventClickAll);
$(document).on("keydown", this.eventKeys); $(document).on("keydown", this.eventKeyDown);
$(document).on("keyup", this.eventKeyUp);
// add clear all button // add clear all button
$("nav.app-navigator").first().append([ $("nav.app-navigator").first().append([
'<a class="link-clean cf app-nav-link padding-hl" data-title="Clear all" data-action="td-clearcolumns-doall">', '<a class="link-clean cf app-nav-link padding-hl" data-title="Clear all" data-action="td-clearcolumns-doall">',
'<div class="obj-left"><i class="icon icon-large icon-clear-timeline"></i></div>', '<div class="obj-left"><i class="icon icon-large icon-clear-timeline"></i></div>',
'<div class="nbfc padding-ts hide-condensed">Clear all</div>', '<div id="clear-columns-btn-all" class="nbfc padding-ts hide-condensed">Clear all</div>',
'</a></nav>' '</a></nav>'
].join("")); ].join(""));
} }