mirror of https://gitgud.io/fatchan/jschan.git
jschan
parent
3559e46aef
commit
5402f856d4
7 changed files with 56 additions and 30 deletions
@ -1,68 +1,86 @@ |
|||||||
class ThreadWatcher { |
class ThreadWatcher { |
||||||
|
|
||||||
constructor() { |
init() { |
||||||
this.watchListSet = new Set(JSON.parse(localStorage.getItem('watchlist'))); |
this.watchListMap = new Map(JSON.parse(localStorage.getItem('watchlist'))); |
||||||
this.settingsInput = document.getElementById('watchlist-setting'); |
this.settingsInput = document.getElementById('watchlist-setting'); |
||||||
this.settingsInput.value = [...this.watchListSet]; |
|
||||||
this.clearButton = document.getElementById('watchlist-clear'); |
this.clearButton = document.getElementById('watchlist-clear'); |
||||||
this.clearButton.addEventListener('click', this.clear, false); |
this.clear = this.clear.bind(this); |
||||||
|
this.clearButton.addEventListener('click', this.clear, false) |
||||||
this.createListHtml(); |
this.createListHtml(); |
||||||
this.threadWatcher = document.getElementById('threadwatcher'); |
|
||||||
//show this time in draghandle? could also add .spin (same as captcha refresh) when updating
|
|
||||||
this.refreshInterval = setInterval(this.refresh, 60 * 1000); |
this.refreshInterval = setInterval(this.refresh, 60 * 1000); |
||||||
this.refresh(); |
this.refresh(); |
||||||
|
|
||||||
this.add() |
|
||||||
} |
} |
||||||
|
|
||||||
refresh() { |
refresh() { |
||||||
console.log('refreshing thread watcher'); |
console.log('refreshing thread watcher'); |
||||||
//
|
|
||||||
} |
} |
||||||
|
|
||||||
//pause() { }
|
//pause() { }
|
||||||
|
|
||||||
//resume() { }
|
//resume() { }
|
||||||
|
|
||||||
|
updateSettingsList() { |
||||||
|
const mapSpread = [...this.watchListMap]; |
||||||
|
setLocalStorage('watchlist', JSON.stringify(mapSpread)); |
||||||
|
this.settingsInput.value = mapSpread; |
||||||
|
} |
||||||
|
|
||||||
createListHtml() { |
createListHtml() { |
||||||
const threadWatcherHtml = threadwatcher(); |
const threadWatcherHtml = threadwatcher(); |
||||||
const footer = document.getElementById('bottom'); |
const footer = document.getElementById('bottom'); |
||||||
footer.insertAdjacentHTML('afterend', threadWatcherHtml); |
footer.insertAdjacentHTML('afterend', threadWatcherHtml); |
||||||
|
this.threadWatcher = document.getElementById('threadwatcher'); |
||||||
new Dragable('#threadwatcher-dragHandle', '#threadwatcher'); |
new Dragable('#threadwatcher-dragHandle', '#threadwatcher'); |
||||||
//todo: add() all ones saved in storage
|
for (let t of this.watchListMap.entries()) { |
||||||
|
console.log(t) |
||||||
|
const [board, postId] = t[0].split('-'); |
||||||
|
const subject = t[1]; |
||||||
|
this.add(board, postId, subject, true); |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
//fetchThread() {}
|
fetchThread() { |
||||||
|
//todo: if 404, remove()
|
||||||
|
} |
||||||
|
|
||||||
add(board, thread) { |
add(board, postId, subject, insertOnly=false) { |
||||||
console.log('add'); |
const key = `${board}-${postId}`; |
||||||
|
if (!insertOnly) { |
||||||
|
if (this.watchListMap.has(key)) { |
||||||
|
return; //already watching
|
||||||
|
} |
||||||
|
console.log('adding', key, 'to watchlist'); |
||||||
|
this.watchListMap.set(key, subject); |
||||||
|
} |
||||||
//todo: = fetchThread();
|
//todo: = fetchThread();
|
||||||
//todo: dedup/prevent dup
|
|
||||||
//todo: push to watchListSet
|
|
||||||
//todo: modify watchListItemHtml to highlight/bold, if already in selected thread
|
//todo: modify watchListItemHtml to highlight/bold, if already in selected thread
|
||||||
const watchListItemHtml = watchedthread({ watchedthread: { board: 'test', subject: 'testing 123', postId: 1 } }); |
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 lastClose = watchedThreadElem.querySelector('.close'); |
||||||
lastClose.addEventListener('click', () => { |
lastClose.addEventListener('click', () => { |
||||||
watchedThreadElem.remove(); |
watchedThreadElem.remove(); |
||||||
this.remove(board, thread); |
this.remove(key); |
||||||
}); |
}); |
||||||
|
this.updateSettingsList(); |
||||||
} |
} |
||||||
|
|
||||||
remove(board, thread) { |
remove(key) { |
||||||
console.log('remove'); |
console.log('removing', key, 'from watchlist'); |
||||||
//
|
this.watchListMap.delete(key); |
||||||
|
this.updateSettingsList(); |
||||||
} |
} |
||||||
|
|
||||||
clear() { |
clear() { |
||||||
console.log('clear'); |
this.watchListMap = new Map(); |
||||||
watchList = new Set(); |
Array.from(this.threadWatcher.children) |
||||||
watchListInput.value = ''; |
.forEach((c, i) => i > 0 && c.remove()); //remove all except first child (the draghandle)
|
||||||
setLocalStorage('watchlist', '[]'); |
setLocalStorage('watchlist', '[]'); |
||||||
console.log('cleared watchlist'); |
console.log('cleared watchlist'); |
||||||
|
this.updateSettingsList(); |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
window.addEventListener('settingsReady', () => new ThreadWatcher()); |
const threadWatcher = new ThreadWatcher(); |
||||||
|
window.addEventListener('settingsReady', () => threadWatcher.init()); |
||||||
|
@ -1,6 +1,7 @@ |
|||||||
mixin watchedthread(thread) |
mixin watchedthread(thread) |
||||||
.row.watched-thread |
.row.watched-thread(data-id=`${thread.board}-${thread.postId}`) |
||||||
a.close X |
a.close X |
||||||
- const watchedThreadLink = `/${thread.board}/thread/${thread.postId}.html`; |
- const watchedThreadLink = `/${thread.board}/thread/${thread.postId}.html`; |
||||||
a(href=watchedThreadLink) /#{thread.board}/ - #{thread.subject} |
a(href=watchedThreadLink) /#{thread.board}/ - #{thread.subject || 'No subject'} |
||||||
a(href=`${watchedThreadLink}#bottom`) [▼] |
a(href=`${watchedThreadLink}#bottom`) [▼] |
||||||
|
//-notification count |
||||||
|
Loading…
Reference in new issue