Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P2028
Quick and dirty Phriction template bookmarklet
Active
Public
Actions
Authored by
rfreebern
on Dec 22 2016, 2:28 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
Phriction
Subscribers
None
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
);
}
};
})();
Event Timeline
rfreebern
created this paste.
Dec 22 2016, 2:28 PM
2016-12-22 14:28:54 (UTC+0)
rfreebern
mentioned this in
T3963: Templates in Phriction
.
Dec 22 2016, 2:33 PM
2016-12-22 14:33:15 (UTC+0)
Log In to Comment