Skip to content

Instantly share code, notes, and snippets.

@fairwood136
Forked from grobux/pledgebox-get-tracking.user.js
Last active September 14, 2020 22:30
Show Gist options
  • Save fairwood136/c9bf96deac0b97d780604beef9808ac1 to your computer and use it in GitHub Desktop.
Save fairwood136/c9bf96deac0b97d780604beef9808ac1 to your computer and use it in GitHub Desktop.
An userscript to display your tracking code on PledgeBox.
// ==UserScript==
// @name PledgeBox details
// @version 0.1
// @description Add tracking infos on PledgeBox interface.
// @author Romain
// @match https://survey.pledgebox.com/projects/detail/*
// @grant none
// @downloadURL https://gist.githubusercontent.com/grobux/48eeebdc5d9b746e298d23dc90ecf531/raw/pledgebox-get-tracking.user.js
// @updateURL https://gist.githubusercontent.com/grobux/48eeebdc5d9b746e298d23dc90ecf531/raw/pledgebox-get-tracking.user.js
// ==/UserScript==
(function() {
'use strict';
window.addEventListener('load', function() {
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 content = document.querySelector('.summary .content-box:first-child .title');
if(json.data.tracking_code) {
var link = document.createElement('a');
link.textContent = 'Tracking: ' + json.data.tracking_code;
link.setAttribute('href', json.data.tracking_url + '#nums=' + json.data.tracking_code);
link.setAttribute('target', '_blank');
link.setAttribute('style', 'color:#34a853; font-weight:bold;');
content.appendChild(link);
} else {
var span = document.createElement('span');
span.textContent = 'No tracking found';
span.setAttribute('style', 'color:#ea4335; font-weight:bold;');
content.appendChild(span);
}
}
};
var token = location.href.split('/')[5];
httpRequest.send(JSON.stringify({token: token}));
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment