mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
Refactor assets bundler and split Javascript files
This commit is contained in:
parent
e1c56b2e53
commit
53deb0b8cd
49 changed files with 2837 additions and 2000 deletions
33
ui/static/js/unread_counter_handler.js
Normal file
33
ui/static/js/unread_counter_handler.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
class UnreadCounterHandler {
|
||||
static decrement(n) {
|
||||
this.updateValue((current) => {
|
||||
return current - n;
|
||||
});
|
||||
}
|
||||
|
||||
static increment(n) {
|
||||
this.updateValue((current) => {
|
||||
return current + n;
|
||||
});
|
||||
}
|
||||
|
||||
static updateValue(callback) {
|
||||
let counterElements = document.querySelectorAll("span.unread-counter");
|
||||
counterElements.forEach((element) => {
|
||||
let oldValue = parseInt(element.textContent, 10);
|
||||
element.innerHTML = callback(oldValue);
|
||||
});
|
||||
|
||||
if (window.location.href.endsWith('/unread')) {
|
||||
let oldValue = parseInt(document.title.split('(')[1], 10);
|
||||
let newValue = callback(oldValue);
|
||||
|
||||
document.title = document.title.replace(
|
||||
/(.*?)\(\d+\)(.*?)/,
|
||||
function (match, prefix, suffix, offset, string) {
|
||||
return prefix + '(' + newValue + ')' + suffix;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue