Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2220336
Quick and dirty Phriction template bookmarklet
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
rfreebern
Dec 22 2016, 2:28 PM
2016-12-22 14:28:54 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
Quick and dirty Phriction template bookmarklet
View Options
javascript:(function () {
var phabricatorURL = 'http://your.phabricator.url';
var templateSlug = encodeURIComponent('"slug/for/template/"');
var tokenURL = phabricatorURL + '/login/refresh/';
var tokenXhr = new XMLHttpRequest();
tokenXhr.onreadystatechange = function () { xhrHandler(tokenXhr, function (rText) {
var json = rText.substr(9); // Get rid of for(;;);
try {
var response = JSON.parse(json);
} catch (e) {
console.log('Failed to parse JSON: ' + e.message);
console.log(json);
return;
}
if (response.hasOwnProperty('payload') && response.payload.hasOwnProperty('token')) {
var csrf = response.payload.token;
var conduitURL = phabricatorURL + '/api/phriction.info';
var templateXhr = new XMLHttpRequest();
templateXhr.onreadystatechange = function () { xhrHandler(templateXhr, function (json) {
try {
var response = JSON.parse(json);
} catch (e) {
console.log('Failed to parse JSON: ' + e.message);
console.log(json);
return;
}
if (response.hasOwnProperty('result') && response.result.hasOwnProperty('content')) {
var textArea = document.getElementById('document-textarea');
if (textArea === null) {
console.log("Can't find a textarea to paste into.");
return;
}
textArea.value = response.result.content;
}
})};
templateXhr.open('POST', conduitURL, true);
templateXhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
templateXhr.setRequestHeader('X-Phabricator-Csrf', csrf);
templateXhr.send('output=json¶ms[slug]=' + templateSlug);
} else {
console.log('Token response: ' + rText);
return;
}
})};
tokenXhr.open('GET', tokenURL, true);
tokenXhr.send();
function xhrHandler (xhr, callback) {
if (xhr.readyState < 4 || xhr.status !== 200) {
return;
}
if (xhr.readyState === 4) {
callback(xhr.responseText);
}
};
})();
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
385138
Default Alt Text
Quick and dirty Phriction template bookmarklet (2 KB)
Attached To
Mode
P2028 Quick and dirty Phriction template bookmarklet
Attached
Detach File
Event Timeline
Log In to Comment