diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-07-08 21:36:20 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-07-08 21:36:20 +0100 |
| commit | 1155220fd5c94fa9769c55597575437581170c16 (patch) | |
| tree | e179c12d2a2611a968bc54a98a5fec0d471f7fb5 | |
| parent | ef36a72e7d0735cb299fdf69e63614c48a855bfa (diff) | |
Create bookmarklet for browers
| -rw-r--r-- | make_bookmarklet/index.php | 36 | ||||
| -rw-r--r-- | public/bookmarks/add/index.php | 1 |
2 files changed, 36 insertions, 1 deletions
diff --git a/make_bookmarklet/index.php b/make_bookmarklet/index.php new file mode 100644 index 0000000..f964003 --- /dev/null +++ b/make_bookmarklet/index.php @@ -0,0 +1,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; diff --git a/public/bookmarks/add/index.php b/public/bookmarks/add/index.php index 835fa64..f387bc6 100644 --- a/public/bookmarks/add/index.php +++ b/public/bookmarks/add/index.php @@ -2,7 +2,6 @@ error_reporting(E_ALL); - require_once(__DIR__.'/../../../includes/functions.php'); $config = require_once(__DIR__.'/../../../config.php'); |
