|
|
@ -8,7 +8,7 @@ class ThreadWatcher { |
|
|
|
this.clearButton.addEventListener('click', this.clear, false) |
|
|
|
this.clearButton.addEventListener('click', this.clear, false) |
|
|
|
this.createListHtml(); |
|
|
|
this.createListHtml(); |
|
|
|
this.refreshInterval = setInterval(this.refresh, 60 * 1000); |
|
|
|
this.refreshInterval = setInterval(this.refresh, 60 * 1000); |
|
|
|
this.refresh(); |
|
|
|
this.refresh(); //store last refresh in ls? do a setTimeout until then, run once, then start the interval inside the timeout callback
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
refresh() { |
|
|
|
refresh() { |
|
|
@ -57,26 +57,24 @@ class ThreadWatcher { |
|
|
|
const watchListItemHtml = watchedthread({ watchedthread: { board, postId, subject } }); |
|
|
|
const watchListItemHtml = watchedthread({ watchedthread: { board, postId, subject } }); |
|
|
|
this.threadWatcher.insertAdjacentHTML('beforeend', watchListItemHtml); |
|
|
|
this.threadWatcher.insertAdjacentHTML('beforeend', watchListItemHtml); |
|
|
|
const watchedThreadElem = this.threadWatcher.lastChild; |
|
|
|
const watchedThreadElem = this.threadWatcher.lastChild; |
|
|
|
const lastClose = watchedThreadElem.querySelector('.close'); |
|
|
|
const closeButton = watchedThreadElem.querySelector('.close'); |
|
|
|
lastClose.addEventListener('click', () => { |
|
|
|
closeButton.addEventListener('click', e => this.remove(e, key)); |
|
|
|
watchedThreadElem.remove(); |
|
|
|
|
|
|
|
this.remove(key); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.updateSettingsList(); |
|
|
|
this.updateSettingsList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
remove(key) { |
|
|
|
remove(e, key) { |
|
|
|
console.log('removing', key, 'from watchlist'); |
|
|
|
console.log('removing', key, 'from watchlist'); |
|
|
|
|
|
|
|
e.target.parentElement.remove(); |
|
|
|
this.watchListMap.delete(key); |
|
|
|
this.watchListMap.delete(key); |
|
|
|
this.updateSettingsList(); |
|
|
|
this.updateSettingsList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
clear() { |
|
|
|
clear() { |
|
|
|
|
|
|
|
console.log('clearing watchlist'); |
|
|
|
this.watchListMap = new Map(); |
|
|
|
this.watchListMap = new Map(); |
|
|
|
Array.from(this.threadWatcher.children) |
|
|
|
Array.from(this.threadWatcher.children) |
|
|
|
.forEach((c, i) => i > 0 && c.remove()); //remove all except first child (the draghandle)
|
|
|
|
.forEach((c, i) => i > 0 && c.remove()); //remove all except first child (the draghandle)
|
|
|
|
setLocalStorage('watchlist', '[]'); |
|
|
|
setLocalStorage('watchlist', '[]'); |
|
|
|
console.log('cleared watchlist'); |
|
|
|
|
|
|
|
this.updateSettingsList(); |
|
|
|
this.updateSettingsList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|