Pleroma Backup

Go to https://YOUR_INSTANCE/main/friends, F12, type in console `backupPleroma()` (without the quotes), Enter.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Pleroma Backup
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Go to https://YOUR_INSTANCE/main/friends, F12, type in console `backupPleroma()` (without the quotes), Enter.
// @author       gudzpoz
// @match        https://*/main/*
// @grant        none
// @license      AGPL-3.0-or-later
// ==/UserScript==

(function() {
    'use strict';

    function download(url) {
        console.log(url)
    }

    window.backupPleroma = () => {
        var req = indexedDB.open('localforage')
        req.onsuccess = event => {
            var db = event.target.result
            var transaction = db.transaction(['keyvaluepairs'])
            var store = transaction.objectStore('keyvaluepairs')
            var request = store.get('vuex-lz')
            request.onsuccess = event => {
                var token = request.result.oauth.userToken
                fetch('/api/v1/pleroma/backups').then(res => res.json()).then(json => {
                    if (json.length === 0 || (Date.now() - new Date(json[json.length - 1].inserted_at)) / 1000 / 60 / 60 / 24 > 7) {
                        fetch('/api/v1/pleroma/backups', {
                            method: 'POST',
                            headers: {
                                'Authorization': `Bearer ${token}`,
                            },
                        }).then(res => res.json()).then(archive => {
                            download(archive[archive.length - 1].url)
                        })
                    } else {
                        download(json[json.length - 1].url)
                    }
                })
            }
        }
    }
})()