aboutsummaryrefslogtreecommitdiff
path: root/p/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'p/scripts')
-rw-r--r--p/scripts/main.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js
index c9627b606..be1f7c924 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -1018,7 +1018,7 @@ function init_stream(stream) {
return true;
}
- el = ev.target.closest('.item.share > a[data-type="print"]');
+ el = ev.target.closest('.item.share > button[data-type="print"]');
if (el) { // Print
const tmp_window = window.open();
for (let i = 0; i < document.styleSheets.length; i++) {
@@ -1032,9 +1032,19 @@ function init_stream(stream) {
return false;
}
- el = ev.target.closest('.item.share > a[data-type="clipboard"]');
+ el = ev.target.closest('.item.share > button[data-type="clipboard"]');
if (el && navigator.clipboard) { // Clipboard
- navigator.clipboard.writeText(el.href);
+ navigator.clipboard.writeText(el.dataset.url);
+ return false;
+ }
+
+ el = ev.target.closest('.item.share > button[data-type="web-sharing-api"]');
+ if (el && navigator.share) { // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
+ const shareData = {
+ url: el.dataset.url,
+ title: decodeURI(el.dataset.title),
+ };
+ navigator.share(shareData);
return false;
}
@@ -1068,6 +1078,15 @@ function init_stream(stream) {
}
};
+ if (!navigator.share) {
+ // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
+ // do not show the menu entry if browser does not support navigator.share
+ document.styleSheets[0].insertRule(
+ 'button.as-link[data-type="web-sharing-api"] {display: none !important;}',
+ document.styleSheets[0].cssRules.length
+ );
+ }
+
stream.onmouseup = function (ev) { // Mouseup enables us to catch middle click, and control+click in IE/Edge
if (ev.altKey || ev.metaKey || ev.shiftKey) {
return;