]*>/g, '');
+ element.innerHTML = element.innerHTML.replace(/<\/font>/g, '');
+ element.innerHTML = element.innerHTML.replace(/<\/div>/g, '');
+ finalText = element.innerText;
+ finalText = finalText.replace(/
/g, '\n');
+ finalText = finalText.replace(/\[img=([^\]]*)\]http:\/\/images\.proboards\.com\/v5\/images\/smiley\/.*?\[\/img\]/g, '$1');
+ finalText = finalText.replace(/\[img=([^\]]*)\]http:\/\/images\.proboards\.com\/v5\/smiley\/.*?\[\/img\]/g, '$1');
+ attachmentIndex = finalText.indexOf('\n\n[b]Attachments:[/b]\n\n');
+ if (attachmentIndex > -1) {
+ finalText = finalText.substring(0, attachmentIndex);
+ }
+ return finalText;
+ };
+
+ findBoards = function() {
+ var boardDescriptionList, boardDescriptions, boardInfo, boardLinks, boardTitles, boards, i;
+ boards = document.querySelectorAll('tr.board.item td:nth-child(2) > span > a');
+ boardTitles = Array.prototype.map.call(boards, function(e) {
+ return e.textContent;
+ });
+ boardLinks = Array.prototype.map.call(boards, function(e) {
+ return e.href;
+ });
+ boardDescriptions = document.querySelectorAll('tr.board.item td:nth-child(2) > p.description');
+ boardDescriptionList = Array.prototype.map.call(boardDescriptions, function(e) {
+ return e.textContent;
+ });
+ boardInfo = [];
+ i = 0;
+ while (i < boardTitles.length) {
+ boardInfo.push({
+ title: boardTitles[i],
+ description: boardDescriptionList[i],
+ link: boardLinks[i]
+ });
+ i++;
+ }
+ return boardInfo;
+ };
+
+ findPages = function() {
+ var lastPage, maxPage, pageBase, pageInfo, pageNr, pages, shownPages;
+ shownPages = document.querySelectorAll('ul.ui-pagination > li.ui-pagination-page.ui-pagination-slot > a[href]');
+ lastPage = shownPages[shownPages.length - 1];
+ pageInfo = /(.*\?page=)(\d*)/.exec(lastPage);
+ pageBase = pageInfo[1];
+ maxPage = pageInfo[2];
+ return pages = (function() {
+ var j, ref, results;
+ results = [];
+ for (pageNr = j = 1, ref = maxPage; 1 <= ref ? j <= ref : j >= ref; pageNr = 1 <= ref ? ++j : --j) {
+ results.push("" + pageBase + pageNr);
+ }
+ return results;
+ })();
+ };
+
+ findThreads = function() {
+ var i, threadIds, threadInfo, threadLinks, threadTitles, threads;
+ threads = document.querySelectorAll('tr.item.thread > td:nth-child(3) a.thread-link');
+ threadTitles = Array.prototype.map.call(threads, function(e) {
+ return e.textContent;
+ });
+ threadLinks = Array.prototype.map.call(threads, function(e) {
+ return e.href;
+ });
+ threadIds = Array.prototype.map.call(threads, function(e) {
+ return /.*\/thread\/(\d*)\/.*/.exec(e.href)[1];
+ });
+ threadInfo = [];
+ i = 0;
+ while (i < threadTitles.length) {
+ threadInfo.push({
+ id: threadIds[i],
+ title: threadTitles[i],
+ link: threadLinks[i]
+ });
+ i++;
+ }
+ return threadInfo;
+ };
+
+ findPosts = function(replaceHtml) {
+ var postInfo;
+ postInfo = Array.prototype.map.call(document.querySelectorAll('tr.item.post'), function(e) {
+ var attachmentName, attachmentNode, attachmentNodes, attachments, dateNode, id, j, len, linkSplit, message, messageNode, timestamp, user, userNode;
+ messageNode = e.querySelector('td.content div.message');
+ attachmentNodes = messageNode.querySelectorAll('div.post_attachments blockquote a');
+ dateNode = e.querySelector('td.content span.date > abbr.time');
+ userNode = e.querySelector('td.left-panel a.user-link,td.left-panel > div.mini-profile.guest-mini-profile');
+ id = /post-(\d*)/.exec(e.id)[1];
+ message = replaceHtml(messageNode);
+ attachments = [];
+ for (j = 0, len = attachmentNodes.length; j < len; j++) {
+ attachmentNode = attachmentNodes[j];
+ attachmentName = attachmentNode.text;
+ if (attachmentNode.childElementCount > 0) {
+ attachmentName = attachmentNode.children[0].alt;
+ }
+ attachments.push({
+ name: attachmentName,
+ url: attachmentNode.href
+ });
+ }
+ timestamp = parseInt(dateNode.attributes['data-timestamp'].value, 10) / 1000;
+ user = {};
+ if (userNode.href) {
+ linkSplit = userNode.href.split('/');
+ user = {
+ link: linkSplit[linkSplit.length - 1],
+ name: userNode.textContent
+ };
+ } else {
+ user = {
+ link: '',
+ name: userNode.firstChild.data.replace('\n\t', '')
+ };
+ }
+ return {
+ id: id,
+ message: message,
+ attachments: attachments,
+ timestamp: timestamp,
+ user: user
+ };
+ });
+ return postInfo;
+ };
+
+ findUserLinks = function() {
+ return Array.prototype.map.call(document.querySelectorAll('div.container.members a.user-link'), function(e) {
+ return e.href;
+ });
+ };
+
+ getUser = function(replaceHtml) {
+ var signatureNode, statusNode, user;
+ user = {};
+ user.name = document.querySelectorAll('span.big_username')[0].textContent;
+ signatureNode = document.querySelector('td#center-column > div.content-box:last-child');
+ user.signature = '';
+ if (signatureNode) {
+ user.signature = replaceHtml(signatureNode);
+ if (!/Signature\n/.test(user.signature)) {
+ user.signature = '';
+ }
+ user.signature = user.signature.replace('Signature\n', '');
+ }
+ statusNode = document.querySelectorAll('form.form_user_status div.content-box tr span.personal-text');
+ user.status = statusNode.length > 0 ? statusNode[0].textContent : '';
+ user.registered = parseInt(document.querySelectorAll('td#center-column > div.content-box abbr.time')[0].attributes['data-timestamp'].value, 10) / 1000;
+ return user;
+ };
+
+ missingArgumentError = function(argument) {
+ console.log("missing the " + argument + " argument");
+ return casper.exit();
+ };
+
+ if (casper.cli.options['board-nr']) {
+ proboardNr = casper.cli.options['board-nr'];
+ } else {
+ missingArgumentError('board-nr');
+ }
+
+ if (casper.cli.options['board-name']) {
+ proboardName = casper.cli.options['board-name'];
+ } else {
+ missingArgumentError('board-name');
+ }
+
+ if (casper.cli.options['user']) {
+ user = casper.cli.options['user'];
+ } else {
+ missingArgumentError('user');
+ }
+
+ if (casper.cli.options['password']) {
+ password = casper.cli.options['password'];
+ } else {
+ missingArgumentError('password');
+ }
+
+ proboardUrl = "http://" + proboardName + ".proboards.com/";
+
+ proboardUserUrl = proboardUrl + "members";
+
+ casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0');
+
+ casper.start(proboardUrl, function() {});
+
+ casper.thenOpen('https://login.proboards.com/forum_submit/login', {
+ method: 'post',
+ data: {
+ forum: proboardNr,
+ email: user,
+ password: password,
+ "continue": 'Continue'
+ }
+ }, function() {});
+
+ readBoard = function(board) {
+ return casper.thenOpen(board.link, function() {
+ board.boards = this.evaluate(findBoards);
+ this.each(board.boards, function(casper, subboard) {
+ return readBoard(subboard);
+ });
+ return this.thenOpen(board.link, function() {
+ var boardPages;
+ this.echo("getting threads for board '" + board.title + "'...");
+ board.threads = [];
+ boardPages = this.evaluate(findPages);
+ this.each(boardPages, function(casper, boardPage) {
+ return this.thenOpen(boardPage, function() {
+ return board.threads = board.threads.concat(this.evaluate(findThreads));
+ });
+ });
+ return this.then(function() {
+ return this.each(board.threads, function(casper, thread) {
+ thread.posts = [];
+ return this.thenOpen(thread.link, function() {
+ var linkParts, pollName, threadPages;
+ this.echo("\tgetting posts for thread '" + thread.title + "'...");
+ pollName = null;
+ if (this.exists('div.poll.show.ui-poll')) {
+ console.log('\t\tsaving poll...');
+ linkParts = thread.link.split('/');
+ pollName = linkParts[linkParts.length - 1] + ".png";
+ this.captureSelector("data/images/polls/" + pollName, 'div.poll.show.ui-poll');
+ }
+ thread.poll = pollName;
+ threadPages = this.evaluate(findPages);
+ this.each(threadPages, function(casper, threadPage) {
+ return this.thenOpen(threadPage, function() {
+ var posts;
+ posts = this.evaluate(findPosts, replaceHtml);
+ this.each(posts, function(casper, post) {
+ var attachment, j, len, ref, results;
+ post.message = loadImages(post.message);
+ ref = post.attachments;
+ results = [];
+ for (j = 0, len = ref.length; j < len; j++) {
+ attachment = ref[j];
+ casper.download(attachment.url, "data/attachments/" + attachment.name);
+ results.push(attachment.url = "{{baseurl}}/attachments/" + attachment.name);
+ }
+ return results;
+ });
+ return thread.posts = thread.posts.concat(posts);
+ });
+ });
+ return this.then(function() {
+ if (thread.poll && thread.posts[0]) {
+ thread.posts[0].message = "[img]{{baseurl}}/images/polls/" + thread.poll + "[/img]\n\n" + thread.posts[0].message;
+ }
+ if (thread.poll && !thread.posts[0]) {
+ return console.log("how the fuck did you manage that?");
+ }
+ });
+ });
+ });
+ });
+ });
+ });
+ };
+
+ proboard = {};
+
+ casper.thenOpen(proboardUrl, function() {
+ proboard.boards = this.evaluate(findBoards);
+ return this.each(proboard.boards, function(casper, board) {
+ return readBoard(board);
+ });
+ });
+
+ casper.thenOpen(proboardUserUrl, function() {
+ var userPages;
+ proboard.users = [];
+ userPages = this.evaluate(findPages);
+ return this.each(userPages, function(casper, userPage) {
+ return this.thenOpen(userPage, function() {
+ var userlinks;
+ userlinks = this.evaluate(findUserLinks);
+ return this.each(userlinks, function(casper, userlink) {
+ return this.thenOpen(userlink, function() {
+ this.echo("getting userinfo for '" + userlink + "'...");
+ user = this.evaluate(getUser, replaceHtml);
+ user.signature = loadImages(user.signature);
+ return proboard.users = proboard.users.concat(user);
+ });
+ });
+ });
+ });
+ });
+
+ casper.then(function() {
+ var json;
+ json = JSON.stringify(proboard, null, '\t');
+ return fs.write("data/" + proboardName + ".json", json, 'w');
+ });
+
+ casper.run();
+
+}).call(this);