diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a032da5c..d1ad99845 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ - **New feature**: `Archive selection` - Select which archive you want for specific boards and redirection type. - Access it in the `Archives` tab of the Settings window. +- The list of archived boards will now update automatically, separately from 4chan X updates. + - If you're an archiver and want [data](https://github.com/MayhemYDG/4chan-x/blob/v3/json/archives.json) about your archive to be updated, added or removed: send a PR or open an issue. - Fix quote previews getting 'stuck' in Opera. ### 3.3.1 - *2013-05-04* diff --git a/src/Archive/Redirect.coffee b/src/Archive/Redirect.coffee index 284cda71f..de882bd74 100644 --- a/src/Archive/Redirect.coffee +++ b/src/Archive/Redirect.coffee @@ -5,16 +5,18 @@ Redirect = file: {} init: -> + Redirect.update() + for boardID, data of Conf['selectedArchives'] for type, uid of data - for archive in Redirect.archives + for archive in Conf['archives'] continue if archive.uid isnt uid or type is 'post' and archive.software isnt 'foolfuuka' arr = if type is 'file' archive.files else archive.boards Redirect[type][boardID] = archive if boardID in arr - for archive in Redirect.archives + for archive in Conf['archives'] for boardID in archive.boards unless boardID of Redirect.thread Redirect.thread[boardID] = archive @@ -24,6 +26,23 @@ Redirect = Redirect.file[boardID] = archive return + update: -> + items = + lastarchivecheck: 0 + lastupdate: 0 + $.get items, (items) -> + now = Date.now() + # Update the list of archives every 4 days. + # The list is also update when 4chan X gets updated. + if items.lastupdate > now - 4 * $.DAY or items.lastarchivecheck > now - 4 * $.DAY + return + $.ajax '<%= meta.page %>json/archives.json', onload: -> + return unless @status is 200 + Conf['archives'] = JSON.parse @response + $.set + lastarchivecheck: now + archives: Conf['archives'] + to: (dest, data) -> archive = (if dest is 'search' then Redirect.thread else Redirect[dest])[data.boardID] return '' unless archive diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 35b4363bc..d91d27326 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -15,6 +15,7 @@ Main = for db in DataBoards Conf[db] = boards: {} Conf['selectedArchives'] = {} + Conf['archives'] = Redirect.archives $.get Conf, Main.initFeatures $.on d, '4chanMainInit', Main.initStyle diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index 87edb431a..93f9f14e7 100644 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -32,8 +32,13 @@ Settings = new Notification 'info', el, 30 else $.on d, '4chanXInitFinished', Settings.open + # The archive list will always be updated with 4chan X updates. + Conf['archives'] = Redirect.archives + now = Date.now() $.set - lastupdate: Date.now() + archives: Conf['archives'] + lastarchivecheck: now + lastupdate: now previousversion: g.VERSION Settings.addSection 'Main', Settings.main @@ -393,7 +398,7 @@ Settings = """ boards = {} - for archive in Redirect.archives + for archive in Conf['archives'] for boardID in archive.boards data = boards[boardID] or= { thread: []