Skip to content

Instantly share code, notes, and snippets.

@unarist
Last active November 24, 2017 13:18
Show Gist options
  • Save unarist/9711146754500e801d20c4ca28b870f8 to your computer and use it in GitHub Desktop.
Save unarist/9711146754500e801d20c4ca28b870f8 to your computer and use it in GitHub Desktop.
Mastodon - 内部実装と同様のaxiosインスタンスを生やす
// ==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