GoogleChromeLabs / link-to-text-fragment

Browser extension that allows for linking to arbitrary text fragments.
https://chrome.google.com/webstore/detail/link-to-text-fragment/pbcodcjpfjdpcineamnnmbkkmkdpajjg
Apache License 2.0
412 stars 33 forks source link

Is it possible to generate a rich URL rather than the raw one created? #28

Closed zendude213 closed 3 years ago

zendude213 commented 3 years ago

(FYI--not a coder)

Hey Thomas -- this could probably be one of the most useful extensions I've found in Chrome as it basically makes Deep Linking in web pages possible. Kinda odd how researchers aren't scrambling to install this. Anyway, I use this app as part of my research / note-taking workflow and have to do a few extra steps to turn the links generated into readable text. I was wondering if there is a way (or maybe through a workaround) to have generated link instead copy the highlighted text for easy pasting. If this isn't possible through the app itself, any useful advice on workarounds to achieve this will be highly appreciated

Thanks!

tomayac commented 3 years ago

Not sure I follow.

  1. Is this about a feature request to copy the link as well as the selected text? So in a document like…

    Some [worthwhile thing] in a text.

    …the generated link would be https://example.com/#:~:text=worthwhile%20thing and what would be copied would be "worthwhile thing https://example.com/#:~:text=worthwhile%20thing"?

  2. Or is this about making the links shorter, for example, by running them through a URL shortener like bitly.com?

Option 2. is out-of-scope since it would require integrating with a third-party, and Option 1. is something we tried when building the feature into the browser, but dismissed it since most users did not like it.

bokand commented 3 years ago

In the "worthwhile thing https://example.com/#:~:text=worthwhile%20thing" case, the annoying thing was that it would be pasted like that into text-only contexts, where really you just want the URL (e.g. browser URL bar). Maybe what @zendude213 is getting at is that in rich-text/html contexts we could just paste a real link? I think that'd be pretty neat. i.e.:

  clipboardData.setData('text/plain', 'https://example.com#:~:text=foo%20bar');
  clipboardData.setData('text/html', '<a href="https://example.com#:~:text=foo%20bar">foo bar</a>');

That way if you're pasting into the browser URL bar you get just the URL but if you're pasting into (e.g.) a Google Doc you get a link to the URL but whose text is the copied text.

bokand commented 3 years ago

e.g. Here's an example if you wanna try it: https://output.jsbin.com/koyurej

tomayac commented 3 years ago

I'm implementing this as we're speaking :-)(

bokand commented 3 years ago

Awesome, thanks! I've brought it up in https://crbug.com/1137934 as well so hopefully the browser-native feature gets this too :)

tomayac commented 3 years ago

Version 1.2.1 of the extension that implements this has just been submitted to the Chrome Web Store. I had to move the copy logic over to the content script, since the background script doesn't let me interact with the clipboard as its document (the background page) isn't focused.

tomayac commented 3 years ago

Rich Text support in the Clipboard API is tracked in https://crbug.com/991970.

zendude213 commented 3 years ago

@tomayac @bokand Thanks both.

Just to clarify. What I meant is that when using the extension on

Some [worthwhile thing] in a text.

the generated link would would be "worthwhile thing"-- as mentioned, this should really make it easy to insert in contexts where you may want to use the link as a reference

bokand commented 3 years ago

Maybe I'm not following...so you select "worthwhile thing" on https://example.com, right-click and choose "copy link to text". Currently (prior to @tomayac's change), this would copy https://example.com#:~:text=worthwhile%20thing to the clipboard; when loaded, it highlights "worthwhile thing" on the page.

The change above means that now we'll also copy some additional data so clients that support HTML paste (e.g. Google Docs, Microsoft Word) will directly paste a link to https://example.com#:~:text=worthwhile%20thing but whose text is "worthwhile thing".

If that's not what you were asking for, could you elaborate? Maybe with an example?

zendude213 commented 3 years ago

Hi @bokand

Yes that's exactly it. Before browsing through @tomayac 's article, I originally thought this would not require anything additional. As you can see from this "copy cat" extension, Just as you can copy a page URL and then directly paste the link in an app (that accepts it) but with the text only showing the page URL's title, I thought this could also be done with links to text fragments.

dnknn commented 3 years ago

TabCopy https://chrome.google.com/webstore/detail/micdllihgoppmejpecmkilggmaagfdmb

zendude213 commented 3 years ago

TabCopy https://chrome.google.com/webstore/detail/micdllihgoppmejpecmkilggmaagfdmb

I'm sorry @dnknn I don't understand. How can I use this with with TabCopy

dnknn commented 3 years ago

I don't understand. How can I use this with with TabCopy

@zendude213 In fact, I don’t understand what this issue discusses.

As you can see from this "copy cat" extension, Just as you can copy a page URL and then directly paste the link in an app (that acc

I just accidentally saw that someone mentioned the extension of copying the URL of the page, so by the way, I would recommend similar extensions that personally feel better to you. Because the this extension copy function supports batch copy, that is, holding Ctrl/Shift on the browser tab-bar to selected multiple tabs. That's all it means ^_^...