Skip to content

Instantly share code, notes, and snippets.

@genkio
Last active January 7, 2026 02:07
Show Gist options
  • Select an option

  • Save genkio/1ce9dee5dbf43a5d04e2a03b8205c666 to your computer and use it in GitHub Desktop.

Select an option

Save genkio/1ce9dee5dbf43a5d04e2a03b8205c666 to your computer and use it in GitHub Desktop.
share.user.js
// ==UserScript==
// @name Auto share on selection end (no double-trigger)
// @namespace wblock
// @version 1.1.6
// @match https://*/*
// @run-at document-end
// ==/UserScript==
(() => {
"use strict";
const WHITELIST = [
"https://ankiuser.net/study",
"https://jp.inoreader.com/folder/Nippon"
];
if (!WHITELIST.some(p => location.href.startsWith(p))) return;
const getText = () => (window.getSelection?.().toString() || "").trim();
let lastSharedText = "";
// When selection is cleared, allow sharing again
document.addEventListener("selectionchange", () => {
if (!getText()) lastSharedText = "";
}, { passive: true });
async function tryShare() {
const text = getText();
if (!text) return;
if (!navigator.share) return;
// Prevent re-trigger when user taps elsewhere to unselect
if (text === lastSharedText) return;
lastSharedText = text;
try {
await navigator.share({ text, title: text });
} catch (_) {}
}
document.addEventListener("touchend", tryShare, { passive: true });
document.addEventListener("mouseup", tryShare, { passive: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment