9

How can I copy only a section of text from a hyper link?

As in, if there is a link like below, how can I copy only a part of the text that is linked?

Call me Ishmael. Some years ago—never mind how long precisely—having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation.

I want to copy only the "nothing particular" words from the above text.

How could I do that?

On Chrome I had an extension that let me select links like normal text by holding shift.

I hope there is a similar way for me to select the text of a link in Safari.

4 Answers 4

2

In Safari this is not directly possible and I do not know a special extension for that.

A workaround:

start selecting the text behind "circulation",
stop at "nothing", (that selects as plain text and starts your selection at the relevant bit)
now cmd+c

paste where you like

jump to beginning of paragraph jump two words forward
delete the rest (quick way for that, just not on SE: ctrl+k or cmdshift+arrows)

0
1

I made the extension.

enter image description here

Because I don't want to pay $100 a year for Apple's Developer program, this extension has to be reloaded each time Safari is restarted.

I never quit Safari though so I am safe ;)


To install and use it:

  1. Make sure 'Show Develop menu in menu bar' is enabled in Safari preferences.

enter image description here

  1. Clone my extension from GitHub

    git clone https://github.com/theonlygusti/shift-to-select.git
    open -a Finder shift-to-select
    

enter image description here

  1. Open the Extension Builder, Develop > Show Extension Builder.

enter image description here

  1. Add an extension.

enter image description here

  1. Choose the one you cloned from GitHub

enter image description here

1
  • Lmfao why is this downvoted Mar 29, 2018 at 22:50
0

I started using Tampermonkey so ported my tiny extension to a user script:

// ==UserScript==
// @name         Shift to select link text
// @namespace    http://theonlygusti.github.io/
// @version      1.0
// @description  Hold down the shift key to select text from within hyperlinks
// @author       theonlygusti
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  function bindNewAnchor(element) {
    element.addEventListener("mouseenter", function(event) {
      if (element.innerText) {
        if (event.shiftKey) setContenteditable(this);
        currentElement = this;
      }
    });
    element.addEventListener('keydown', function (event) {
      if (event.keyCode == 67 && event.metaKey) {
        document.execCommand('copy');
      }
    });
    element.addEventListener("mouseleave", function(event) {
      this.removeAttribute("contenteditable");
      currentElement = null;
    });
    element.addEventListener("keypress", blockEvent);
    element.addEventListener("paste", blockEvent);
    element.addEventListener("cut", blockEvent);
    allNodes.push(element);
  }

  function blockEvent(event) {
    event.preventDefault();
  }

  function setContenteditable(element) {
    element.setAttribute("contenteditable", "true");
    if (window.getComputedStyle(element, null).outlineWidth == "0px") {
      element.style.outlineWidth = "0px";
    }
  }

  var currentElement = null, allNodes = [];

  addEventListener("DOMNodeInserted", function(event) {
    if (allNodes.indexOf(event.target) == -1 && event.target instanceof HTMLAnchorElement) {
      bindNewAnchor(event.target);
    }
    if (event.target.querySelectorAll) {
      var element = event.target.querySelectorAll("a");
      for (var i = 0; i < element.length; i++) {
        if (0 > allNodes.indexOf(element[i])) bindNewAnchor(element[i]);
      }
    }
  });

  for (var elements = document.querySelectorAll("a"), i = 0; i < elements.length; i++) bindNewAnchor(elements[i]);

  window.addEventListener("keydown", function(event) {
    if (currentElement && event.keyCode == 16) {
      setContenteditable(currentElement);
    }
  });
})();

Hold shift and drag over links to select them.

1
  • If you used the Option ⌥ instead this would bring it up to par with Chrome and Firefox (and Alt on Windows, Super+Alt on Linux). Sep 12, 2018 at 14:15
-1

Easiest way is to just copy the whole thing, paste it into a TextEdit document, convert to plain text, and then copy out exactly what you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .