Skip to content

Instantly share code, notes, and snippets.

@fairwood136
Created June 9, 2022 15:30
Show Gist options
  • Save fairwood136/91074ddd2723ff53f35ea34010df9493 to your computer and use it in GitHub Desktop.
Save fairwood136/91074ddd2723ff53f35ea34010df9493 to your computer and use it in GitHub Desktop.
Pledgebox - Structured, and JSON dump
// ==UserScript==
// @name Pledgebox
// @version 1
// @grant none
// ==/UserScript==
/*
* PledgeBox pledge manager
* Display some datas about your order on a project
* Run it on "thank you" page.
* URL scheme: https://survey.pledgebox.com/project/[PROJECT_ID]/[PROJECT_SLUG]/[TOKEN]/success
* Dates timezone: GMT-7
*/
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'https://survey.pledgebox.com/api/survey/order/info', true);
httpRequest.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
var json = JSON.parse(httpRequest.responseText);
var pledged_at = new Date(json.data.pledged_at * 1000).toLocaleString("en-US", {timeZone: "America/Chicago"});
pledged_at = new Date(pledged_at);
var nl = '\n';
alert(
'PBID: ' + json.data.id + nl +
'Backer: ' + json.data.sequence + nl +
'Pledged: ' + pledged_at.getFullYear() + '-' +
leadingZero(pledged_at.getMonth()) + '-' +
leadingZero(pledged_at.getDate()) + ' ' +
leadingZero(pledged_at.getHours()) + ':' +
leadingZero(pledged_at.getMinutes()) + ':' +
leadingZero(pledged_at.getSeconds()) + nl +
'Opened: ' + json.data.opened_at + nl +
'Paid: ' + json.data.paid_at + nl +
'Completed: ' + json.data.completed_at + nl +
'Shipped: ' + json.data.shipping_at + nl +
'Tracking Code: ' + json.tracking_code
);
alert('JSON: ' + JSON.stringify(json)
);
}
};
var token = location.href.split('/')[6];
httpRequest.send(JSON.stringify({token: token}));
function leadingZero(value) {
if(value < 10) {
value = '0' + value;
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment