mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Adds keyboard shortcut for refreshing all feeds
- Binds the 'R' key to trigger a refresh in the background for all feeds. - Updates the locale, using the same description as the link in the feeds page. Co-authored-by: Vitor Pellegrino <pellegrino@linux.com>
This commit is contained in:
parent
7e5157f218
commit
7fb0bdc9a5
17 changed files with 61 additions and 16 deletions
|
@ -38,6 +38,7 @@ isModifierKeyDown(event){return event.getModifierState("Control")||event.getModi
|
|||
getKey(event){const mapping={'Esc':'Escape','Up':'ArrowUp','Down':'ArrowDown','Left':'ArrowLeft','Right':'ArrowRight'};for(let key in mapping){if(mapping.hasOwnProperty(key)&&key===event.key){return mapping[key];}}
|
||||
return event.key;}}
|
||||
class RequestBuilder{constructor(url){this.callback=null;this.url=url;this.options={method:"POST",cache:"no-cache",credentials:"include",body:null,headers:new Headers({"Content-Type":"application/json","X-Csrf-Token":this.getCsrfToken()})};}
|
||||
withHttpMethod(method){this.options.method=method;return this;}
|
||||
withBody(body){this.options.body=JSON.stringify(body);return this;}
|
||||
withCallback(callback){this.callback=callback;return this;}
|
||||
getCsrfToken(){let element=document.querySelector("meta[name=X-CSRF-Token]");if(element!==null){return element.getAttribute("value");}
|
||||
|
@ -63,6 +64,7 @@ function handleEntryStatus(element){let toasting=!element;let currentEntry=findE
|
|||
function toggleEntryStatus(element,toasting){let entryID=parseInt(element.dataset.id,10);let link=element.querySelector("a[data-toggle-status]");let currentStatus=link.dataset.value;let newStatus=currentStatus==="read"?"unread":"read";updateEntriesStatus([entryID],newStatus);if(currentStatus==="read"){link.innerHTML='<span class="icon-label">'+link.dataset.labelRead+'</span>';link.dataset.value="unread";if(toasting){toast(link.dataset.toastUnread);}}else{link.innerHTML='<span class="icon-label">'+link.dataset.labelUnread+'</span>';link.dataset.value="read";if(toasting){toast(link.dataset.toastRead);}}
|
||||
if(element.classList.contains("item-status-"+currentStatus)){element.classList.remove("item-status-"+currentStatus);element.classList.add("item-status-"+newStatus);}}
|
||||
function markEntryAsRead(element){if(element.classList.contains("item-status-unread")){element.classList.remove("item-status-unread");element.classList.add("item-status-read");let entryID=parseInt(element.dataset.id,10);updateEntriesStatus([entryID],"read");}}
|
||||
function handleRefreshAllFeeds(){let url=document.body.dataset.refreshAllFeedsUrl;let request=new RequestBuilder(url);request.withCallback(()=>{window.location.reload();});request.withHttpMethod("GET");request.execute();}
|
||||
function updateEntriesStatus(entryIDs,status,callback){let url=document.body.dataset.entriesStatusUrl;let request=new RequestBuilder(url);request.withBody({entry_ids:entryIDs,status:status});request.withCallback(callback);request.execute();if(status==="read"){decrementUnreadCounter(1);}else{incrementUnreadCounter(1);}}
|
||||
function handleSaveEntry(element){let toasting=!element;let currentEntry=findEntry(element);if(currentEntry){saveEntry(currentEntry.querySelector("a[data-save-entry]"),toasting);}}
|
||||
function saveEntry(element,toasting){if(!element){return;}
|
||||
|
@ -102,7 +104,7 @@ function isListView(){return document.querySelector(".items")!==null;}
|
|||
function findEntry(element){if(isListView()){if(element){return DomHelper.findParent(element,"item");}else{return document.querySelector(".current-item");}}else{return document.querySelector(".entry");}}
|
||||
function handleConfirmationMessage(linkElement,callback){linkElement.style.display="none";let containerElement=linkElement.parentNode;let questionElement=document.createElement("span");let yesElement=document.createElement("a");yesElement.href="#";yesElement.appendChild(document.createTextNode(linkElement.dataset.labelYes));yesElement.onclick=(event)=>{event.preventDefault();let loadingElement=document.createElement("span");loadingElement.className="loading";loadingElement.appendChild(document.createTextNode(linkElement.dataset.labelLoading));questionElement.remove();containerElement.appendChild(loadingElement);callback(linkElement.dataset.url,linkElement.dataset.redirectUrl);};let noElement=document.createElement("a");noElement.href="#";noElement.appendChild(document.createTextNode(linkElement.dataset.labelNo));noElement.onclick=(event)=>{event.preventDefault();linkElement.style.display="inline";questionElement.remove();};questionElement.className="confirm";questionElement.appendChild(document.createTextNode(linkElement.dataset.labelQuestion+" "));questionElement.appendChild(yesElement);questionElement.appendChild(document.createTextNode(", "));questionElement.appendChild(noElement);containerElement.appendChild(questionElement);}
|
||||
function toast(msg){if(!msg)return;document.querySelector('.toast-wrap .toast-msg').innerHTML=msg;let toastWrapper=document.querySelector('.toast-wrap');toastWrapper.classList.remove('toastAnimate');setTimeout(function(){toastWrapper.classList.add('toastAnimate');},100);}
|
||||
document.addEventListener("DOMContentLoaded",function(){handleSubmitButtons();if(!document.querySelector("body[data-disable-keyboard-shortcuts=true]")){let keyboardHandler=new KeyboardHandler();keyboardHandler.on("g u",()=>goToPage("unread"));keyboardHandler.on("g b",()=>goToPage("starred"));keyboardHandler.on("g h",()=>goToPage("history"));keyboardHandler.on("g f",()=>goToFeedOrFeeds());keyboardHandler.on("g c",()=>goToPage("categories"));keyboardHandler.on("g s",()=>goToPage("settings"));keyboardHandler.on("ArrowLeft",()=>goToPrevious());keyboardHandler.on("ArrowRight",()=>goToNext());keyboardHandler.on("k",()=>goToPrevious());keyboardHandler.on("p",()=>goToPrevious());keyboardHandler.on("j",()=>goToNext());keyboardHandler.on("n",()=>goToNext());keyboardHandler.on("h",()=>goToPage("previous"));keyboardHandler.on("l",()=>goToPage("next"));keyboardHandler.on("o",()=>openSelectedItem());keyboardHandler.on("v",()=>openOriginalLink());keyboardHandler.on("V",()=>openOriginalLink(true));keyboardHandler.on("c",()=>openCommentLink());keyboardHandler.on("C",()=>openCommentLink(true));keyboardHandler.on("m",()=>handleEntryStatus());keyboardHandler.on("A",()=>markPageAsRead());keyboardHandler.on("s",()=>handleSaveEntry());keyboardHandler.on("d",()=>handleFetchOriginalContent());keyboardHandler.on("f",()=>handleBookmark());keyboardHandler.on("?",()=>showKeyboardShortcuts());keyboardHandler.on("#",()=>unsubscribeFromFeed());keyboardHandler.on("/",(e)=>setFocusToSearchInput(e));keyboardHandler.on("Escape",()=>ModalHandler.close());keyboardHandler.listen();}
|
||||
document.addEventListener("DOMContentLoaded",function(){handleSubmitButtons();if(!document.querySelector("body[data-disable-keyboard-shortcuts=true]")){let keyboardHandler=new KeyboardHandler();keyboardHandler.on("g u",()=>goToPage("unread"));keyboardHandler.on("g b",()=>goToPage("starred"));keyboardHandler.on("g h",()=>goToPage("history"));keyboardHandler.on("g f",()=>goToFeedOrFeeds());keyboardHandler.on("g c",()=>goToPage("categories"));keyboardHandler.on("g s",()=>goToPage("settings"));keyboardHandler.on("ArrowLeft",()=>goToPrevious());keyboardHandler.on("ArrowRight",()=>goToNext());keyboardHandler.on("k",()=>goToPrevious());keyboardHandler.on("p",()=>goToPrevious());keyboardHandler.on("j",()=>goToNext());keyboardHandler.on("n",()=>goToNext());keyboardHandler.on("h",()=>goToPage("previous"));keyboardHandler.on("l",()=>goToPage("next"));keyboardHandler.on("o",()=>openSelectedItem());keyboardHandler.on("v",()=>openOriginalLink());keyboardHandler.on("V",()=>openOriginalLink(true));keyboardHandler.on("c",()=>openCommentLink());keyboardHandler.on("C",()=>openCommentLink(true));keyboardHandler.on("m",()=>handleEntryStatus());keyboardHandler.on("A",()=>markPageAsRead());keyboardHandler.on("s",()=>handleSaveEntry());keyboardHandler.on("d",()=>handleFetchOriginalContent());keyboardHandler.on("f",()=>handleBookmark());keyboardHandler.on("R",()=>handleRefreshAllFeeds());keyboardHandler.on("?",()=>showKeyboardShortcuts());keyboardHandler.on("#",()=>unsubscribeFromFeed());keyboardHandler.on("/",(e)=>setFocusToSearchInput(e));keyboardHandler.on("Escape",()=>ModalHandler.close());keyboardHandler.listen();}
|
||||
let touchHandler=new TouchHandler();touchHandler.listen();onClick("a[data-save-entry]",(event)=>handleSaveEntry(event.target));onClick("a[data-toggle-bookmark]",(event)=>handleBookmark(event.target));onClick("a[data-fetch-content-entry]",()=>handleFetchOriginalContent());onClick("a[data-action=search]",(event)=>setFocusToSearchInput(event));onClick("a[data-action=markPageAsRead]",()=>handleConfirmationMessage(event.target,()=>markPageAsRead()));onClick("a[data-toggle-status]",(event)=>handleEntryStatus(event.target));onClick("a[data-confirm]",(event)=>handleConfirmationMessage(event.target,(url,redirectURL)=>{let request=new RequestBuilder(url);request.withCallback(()=>{if(redirectURL){window.location.href=redirectURL;}else{window.location.reload();}});request.execute();}));if(document.documentElement.clientWidth<600){onClick(".logo",()=>toggleMainMenu());onClick(".header nav li",(event)=>onClickMainMenuListItem(event));}
|
||||
if("serviceWorker"in navigator){let scriptElement=document.getElementById("service-worker-script");if(scriptElement){navigator.serviceWorker.register(scriptElement.src);}}
|
||||
window.addEventListener('beforeinstallprompt',(e)=>{e.preventDefault();let deferredPrompt=e;const promptHomeScreen=document.getElementById('prompt-home-screen');if(promptHomeScreen){promptHomeScreen.style.display="block";const btnAddToHomeScreen=document.getElementById('btn-add-to-home-screen');if(btnAddToHomeScreen){btnAddToHomeScreen.addEventListener('click',(e)=>{e.preventDefault();deferredPrompt.prompt();deferredPrompt.userChoice.then(()=>{deferredPrompt=null;promptHomeScreen.style.display="none";});});}}});});})();`,
|
||||
|
@ -110,6 +112,6 @@ window.addEventListener('beforeinstallprompt',(e)=>{e.preventDefault();let defer
|
|||
}
|
||||
|
||||
var JavascriptsChecksums = map[string]string{
|
||||
"app": "e7f953dd231bd59b239ba4c801366d1bc5d59233f085e4b0801e27c94e416416",
|
||||
"app": "5b7b79ccbdaa1820052f5cf45f7dc92c58cb6362dffb01f8428db9bb82fa705b",
|
||||
"sw": "55fffa223919cc18572788fb9c62fccf92166c0eb5d3a1d6f91c31f24d020be9",
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue