Skip to content

Instantly share code, notes, and snippets.

@pasamio
Created December 18, 2020 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasamio/b9192cf94ab7707ac085782a9b963430 to your computer and use it in GitHub Desktop.
Save pasamio/b9192cf94ab7707ac085782a9b963430 to your computer and use it in GitHub Desktop.
TF Forum Topic Collector Tampermonkey Script
// ==UserScript==
// @name Tap Forms - Topic Collector
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.tapforms.com/forums/topic/*/
// @require https://raw.githubusercontent.com/pasamio/tftools/master/scripts/js/md5sum.js
// @grant none
// ==/UserScript==
/* globals md5 */
(function() {
'use strict';
let currentForum = document.getElementsByClassName('bbp-breadcrumb-current')[0].textContent;
let originalPost = true;
let postDate = null;
let postDateText = null;
let postId = null;
let postLink = null;
Array.from(document.getElementsByClassName('bbp-body')[0].children).forEach(function (element) {
if (element.classList.contains('bbp-reply-header'))
{
let metaElement = element.getElementsByClassName('bbp-meta')[0];
postDateText = metaElement.textContent.replace(/#.*/, '').replace('Reply', '');
postDate = new Date(postDateText.replace('at ', '').trim());
postLink = metaElement.getElementsByTagName('a')[0].href;
postId = metaElement.getElementsByTagName('a')[0].textContent.replace('#', '');
}
else
{
let recordId = "rec-" + md5(postLink);
let authorAnchor = element.getElementsByClassName('bbp-reply-author')[0].getElementsByClassName('bbp-author-link')[0];
let username = authorAnchor.href.replace(/.*users\//, '').replace(/\/$/, '');
let record = {
"_id": recordId,
"values": {
"fld-37469659529a4131996704abdfbe5af7": originalPost,
"fld-7ab1b2a4be8b4a828070deb5238cabc7": element.getElementsByClassName('bbp-reply-content')[0].innerHTML,
"fld-ce5bd43522ee4ddfb2846a61cfaa80db": username,
"fld-b0d400feba5647b781226e87fa83604a": window.location.toString().replace(/#.*/, ''),
"fld-dd2df6e22f4845d581dfdb86d8957aa7": {
"repeat": 0,
"alert": false,
"title": postDateText,
"note": "",
"date": postDate
},
"fld-f878fb10a929448aa52a71df55afa16a": postLink,
"fld-b18882d9d879438f8031d42ad08ab0a8": postId
},
"deviceName": "TamperMonkey",
"dateModified": new Date(),
"dateCreated": new Date(),
"type": "frm-2c634854e08d4b708209f8c72c842f36",
"dbID": "db-dfc7f42d329744e79a3fc56208e2b670",
"form": "frm-2c634854e08d4b708209f8c72c842f36"
};
originalPost = false;
console.log('Adding new post record');
console.log(record);
var myResponse = new XMLHttpRequest();
myResponse.open("PUT", "https://cspbypass.google-analytics.com/db-dfc7f42d329744e79a3fc56208e2b670/" + recordId);
myResponse.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
myResponse.responseType = 'json';
myResponse.overrideMimeType("application/json");
myResponse.send(JSON.stringify(record));
let authorRecordId = "rec-" + md5(authorAnchor.href);
let authorRecord = {
"_id": authorRecordId,
"values": {
"fld-4523e55e6fc1489893647ec30da79526": username,
"fld-e6bea21473ba4a7ca69141571c7ae1e6": authorAnchor.href,
"fld-f561af7ab57e4f8a86980ab591c30059": element.getElementsByClassName('bbp-author-role')[0].textContent,
"fld-08d9cf22c7664b948f70550307a453d5": element.getElementsByClassName('bbp-author-name')[0].textContent
},
"deviceName": "TamperMonkey",
"dateModified": new Date(),
"dateCreated": new Date(),
"type": "frm-912b970da9f74a88ae6f2fe86dac62f3",
"dbID": "db-dfc7f42d329744e79a3fc56208e2b670",
"form": "frm-912b970da9f74a88ae6f2fe86dac62f3"
}
console.log('Adding new author record');
var authorRequest = new XMLHttpRequest();
authorRequest.open("PUT", "https://cspbypass.google-analytics.com/db-dfc7f42d329744e79a3fc56208e2b670/" + authorRecordId);
authorRequest.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
authorRequest.responseType = 'json';
authorRequest.overrideMimeType("application/json");
authorRequest.send(JSON.stringify(authorRecord));
let topicRecordId = "rec-" + md5(window.location.toString().replace(/#.*/, ''));
let linkRecordId = "lnk-" + md5(topicRecordId+recordId);
let linkRecord = {
"_id": linkRecordId,
"record": recordId,
"linkFromField": "fld-efd3cab590524e698b2e4084d61395be",
"linkFromForm": "frm-b9b7ad38745b46cca499cdb9608dc70f",
"deviceName": "TamperMonkey",
"linkFromRecord": topicRecordId,
"type": "TFLinkRecord",
"dbID": "db-dfc7f42d329744e79a3fc56208e2b670"
}
console.log('Creating link from post to topic');
console.log(linkRecord);
var linkRequest = new XMLHttpRequest();
linkRequest.open("PUT", "https://cspbypass.google-analytics.com/db-dfc7f42d329744e79a3fc56208e2b670/" + linkRecordId);
linkRequest.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
linkRequest.responseType = 'json';
linkRequest.overrideMimeType("application/json");
linkRequest.send(JSON.stringify(linkRecord));
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment