basic impl
This commit is contained in:
commit
876a5b5928
|
@ -0,0 +1,24 @@
|
|||
This is a Firefox Addon that allows to create a ["Text Fragment"](https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments#:%7E:text=Text%20fragments%20allow%20linking%20directly%20to%20a%20specific%20portion%20of%20text%20in%20a%20web%20document) link for the context menu.
|
||||
|
||||
|
||||
# installation
|
||||
|
||||
* git clone or export this repo
|
||||
* go to page "about:debugging#/runtime/this-firefox" (or "about:debugging" then click "This Firefox")
|
||||
* click on "Load Temporary Add-on…"
|
||||
* select "manifest.json" file
|
||||
|
||||
# usage
|
||||
|
||||
* select a text in a document,
|
||||
* right clic to have contextual menu,
|
||||
* choose "text fragment" entry
|
||||
* paste the link in an address bar or in a mail or in a chat
|
||||
|
||||
# limitation
|
||||
|
||||
* not packaged, only debug mode yet
|
||||
* on the plus side, the code is so simple that you can see it won't stab you in the back
|
||||
* tested only on Firefox
|
||||
* the other, most popular, web browser is on the evil side for a long time now
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
browser.contextMenus.create({
|
||||
id: "text-fragment",
|
||||
title: "Text Fragment",
|
||||
contexts: ["selection"]
|
||||
});
|
||||
|
||||
browser.contextMenus.onClicked.addListener((info) => {
|
||||
if (info.menuItemId === "text-fragment") {
|
||||
const selectedText = encodeURIComponent(info.selectionText);
|
||||
const pageUrl = info.pageUrl.split('#')[0]; // Remove existing fragment, if any
|
||||
const textToCopy = `${pageUrl}#:~:text=${selectedText}`;
|
||||
|
||||
navigator.clipboard.writeText(textToCopy).then(() => {
|
||||
console.log("Text copied to clipboard");
|
||||
}).catch(err => {
|
||||
console.error("Could not copy text: ", err);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 16 16" fill="#0a84ff" opacity="0.98">
|
||||
<g transform="rotate(90 8 8)">
|
||||
<rect x="7" y="3.286" width="2" height="9.429" rx="1" ry="1" transform="rotate(-45 8 8)"/>
|
||||
<path d="M2.354 4.522L4.485 2.39a.5.5 0 0 1 .711 0l3.19 3.19.014-.015a2 2 0 0 0 0-2.821L6.272.616a2 2 0 0 0-2.821 0L.616 3.451a2 2 0 0 0 0 2.821L2.744 8.4a1.993 1.993 0 0 0 2.8.02l-3.19-3.186a.5.5 0 0 1 0-.712z"/>
|
||||
<path d="M15.416 9.759L13.287 7.63a2 2 0 0 0-2.821 0l-.015.015 3.189 3.189a.5.5 0 0 1 0 .711l-2.132 2.132a.5.5 0 0 1-.711 0L7.61 10.49a1.993 1.993 0 0 0 .02 2.8l2.128 2.128a2 2 0 0 0 2.821 0l2.835-2.835a2 2 0 0 0 .002-2.824z"/>
|
||||
</g>
|
||||
<g stroke="#737373" stroke-width="4" transform="scale(0.5) translate(18 18)">
|
||||
<path transform="scale(0.667)" d="M10 19H12M12 19H14M12 19V5M12 5H6V6M12 5H18V6" stroke-linecap="round"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 929 B |
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Text Fragment Copier",
|
||||
"version": "1.0",
|
||||
"permissions": [
|
||||
"contextMenus",
|
||||
"clipboardWrite",
|
||||
"activeTab"
|
||||
],
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
"icons": {
|
||||
"32": "icon.svg",
|
||||
"48": "icon.svg",
|
||||
"64": "icon.svg",
|
||||
"96": "icon.svg",
|
||||
"128": "icon.svg"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue