diff --git a/Resources/Plugins/clear-columns/.meta b/Resources/Plugins/clear-columns/.meta index 806c1b36..26ca9fd2 100644 --- a/Resources/Plugins/clear-columns/.meta +++ b/Resources/Plugins/clear-columns/.meta @@ -3,12 +3,13 @@ Clear columns [description] - Adds buttons and keyboard shortcuts to quickly clear columns +- Hold Shift when clicking or using a keyboard shortcut to reset the column instead [author] chylex [version] -1.0 +1.1 [website] https://tweetduck.chylex.com diff --git a/Resources/Plugins/clear-columns/browser.js b/Resources/Plugins/clear-columns/browser.js index 500ee1b4..d2fb1afe 100644 --- a/Resources/Plugins/clear-columns/browser.js +++ b/Resources/Plugins/clear-columns/browser.js @@ -11,38 +11,75 @@ enabled(){ TD.controller.stats.columnActionClick("clear"); }; - var clearAllColumns = () => { - Object.keys(TD.controller.columnManager.getAll()).forEach(key => clearColumn(key)); + var resetColumn = (columnName) => { + 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) => { 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 - this.eventClearSingle = function(){ - clearColumn($(this).closest(".js-column").attr("data-column")); + this.eventClickSingle = function(e){ + var name = $(this).closest(".js-column").attr("data-column"); + e.shiftKey ? resetColumn(name) : clearColumn(name); }; - this.eventClearAll = function(){ - clearAllColumns(); + this.eventClickAll = function(e){ + forEachColumn(e.shiftKey ? resetColumn : clearColumn); }; - this.eventKeys = function(e){ - if (e.keyCode === 46 && (document.activeElement === null || document.activeElement === document.body)){ // 46 = delete + 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){ - clearAllColumns(); + forEachColumn(e.shiftKey ? resetColumn : clearColumn); } else{ var focusedColumn = $(".js-column.is-focused"); 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 replaceMustache("column/column_header.mustache", "</header>", [ '{{^isTemporary}}', @@ -67,19 +104,21 @@ enabled(){ css.insert(".column-type-message .column-title { margin-right: 115px !important; }"); css.insert(".mark-all-read-link { right: 59px !important; }"); css.insert(".open-compose-dm-link { right: 90px !important; }"); + css.insert(".btn-options-tray button[data-action='clear'] { display: none !important; }"); } ready(){ // setup events - $(document).on("click", "[data-action='td-clearcolumns-dosingle']", this.eventClearSingle); - $(document).on("click", "[data-action='td-clearcolumns-doall']", this.eventClearAll); - $(document).on("keydown", this.eventKeys); + $(document).on("click", "[data-action='td-clearcolumns-dosingle']", this.eventClickSingle); + $(document).on("click", "[data-action='td-clearcolumns-doall']", this.eventClickAll); + $(document).on("keydown", this.eventKeyDown); + $(document).on("keyup", this.eventKeyUp); // add clear all button $("nav.app-navigator").first().append([ '<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="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>' ].join("")); }