thread.patchFilenamesCallback = function(error, receivedData) { receivedData = JSON.parse(receivedData); if (receivedData.threadId !== api.threadId) { window.location.href = '/' + receivedData.boardUri + '/res/' + receivedData.threadId + '.html'; return; } var posts = receivedData.posts; if (posts && posts.length) { for (var i = 0; i < posts.length; i++) { var post = posts[i]; if (post.files && post.files.length) { var timestamp = new Date(post.creation) * 1000; var cell = document.getElementById(post.postId); for (var j = 0; j < post.files.length; j++) { var nameLink = cell.getElementsByClassName('nameLink')[0]; nameLink.setAttribute('download', (timestamp + j) + nameLink.href.substr(nameLink.href.lastIndexOf('.'))); } } } } } api.localRequest(thread.refreshURL, thread.patchFilenamesCallback);