summaryrefslogtreecommitdiff
path: root/make_bookmarklet/index.php
blob: f964003128266e0f85572f597db35060992c5e69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

error_reporting(E_ALL);

$config = require_once(__DIR__.'/../config.php');

$booklet = <<< EOF_JS
javascript: (() => {
    async function bookmarkPage(page) {
        const response = await fetch('{$config['site']}/bookmarks/add/', {
            method: 'POST', 
            mode: 'cors', 
            cache: 'no-cache', 
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Authorization': 'Bearer {$config['bearer_token']}',
            },
            redirect: 'follow',
            referrerPolicy: 'no-referrer',
            body: page
        });
        return response;
    }

    bookmarkPage(`url=\${encodeURIComponent(window.location.href)}`)
        .then(data => {
            if (data.status === 201) {
                alert('Page bookmarked');
            } else {
                alert(`Failed with status \${data.status} \${data.statusText}`);
            }
        });
})();
EOF_JS;

echo $booklet;