From 1155220fd5c94fa9769c55597575437581170c16 Mon Sep 17 00:00:00 2001 From: "David T. Sadler" Date: Thu, 8 Jul 2021 21:36:20 +0100 Subject: Create bookmarklet for browers --- make_bookmarklet/index.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 make_bookmarklet/index.php (limited to 'make_bookmarklet') 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 @@ + { + 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; -- cgit v1.2.3-13-gbd6f