Last active
November 24, 2017 13:18
-
-
Save unarist/9711146754500e801d20c4ca28b870f8 to your computer and use it in GitHub Desktop.
Mastodon - 内部実装と同様のaxiosインスタンスを生やす
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Mastodon - 内部実装と同様のaxiosインスタンスを生やす | |
// @namespace https://github.com/unarist/ | |
// @version 0.1 | |
// @author unarist | |
// @match https://*/web/* | |
// @downloadURL https://gist.github.com/unarist/9711146754500e801d20c4ca28b870f8/raw/mastodon-axios-instance.user.js | |
// @require https://unpkg.com/axios/dist/axios.min.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
if (!document.querySelector('.app-holder[data-react-class="Mastodon"], #mastodon')) return; | |
window.api = window.api || axios.create({ | |
headers: { Authorization: `Bearer ${JSON.parse(document.getElementById('initial-state').textContent).meta.access_token}` }, | |
transformResponse: [function (data) { | |
try { | |
return JSON.parse(data); | |
} catch(Exception) { | |
return data; | |
} | |
}] | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment