Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clip To WorkFlowy Bookmarklet
//Version 2.6
(function () {
function eOPML(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '&amp;lt;')
.replace(/>/g, '&amp;gt;')
.replace(/"/g, '&quot;')
.replace(/(\n)/g, '&#10;');
}
function copyMe(str) {
var t = document.createElement('textarea');
t.value = str;
document.body.appendChild(t);
t.select();
document.execCommand('copy');
document.body.removeChild(t);
}
function toastMsg(msg, msecs, err) {
if ($("#dropdownMessages").css("position") !== "fixed") {
$("#dropdownMessages").css("position", "fixed");
}
void 0 === msecs && (msecs = 2000);
void 0 === err && (err = !1);
var r = $("#message");
r.removeClass(), err && r.addClass("errorMessage"), r
.find(".messageContent")
.html(
"<b>" + msg + "</b>"
), r.is(":visible") || (r
.children(".close")
.hide(), r.slideDown("normal", function () {
$(this).find(".close").show();
}));
setTimeout(function () {
r
.children(".close")
.hide(), r.find(".messageContent").html(""), r.slideUp();
}, msecs);
}
var isWF = location.href.indexOf('https://workflowy.com/') === 0;
if (isWF && item_select.getSelectedItems().length > 0) {
item_select.clearItemSelection();
}
var bullet = isWF ? '&lt;i&gt;See: &quot;' + eOPML(selectOnActivePage(".selected").getName()[0].textContent) + '&quot;&lt;/i&gt;' : eOPML(document.title);
var selected = eOPML(window.getSelection().toString());
var link = eOPML(location.href);
var note = selected ? '..' + link + '&#10;&#10;' + selected : link;
copyMe('<opml><body><outline text="' + bullet + '" _note="' + note + '" /></body></opml>');
if (isWF) {
toastMsg('WorkFlowy link is ready to paste.');
}
})();
@rawbytz

This comment has been minimized.

Show comment
Hide comment
@rawbytz

rawbytz Nov 4, 2017

Go here for install link.

Owner

rawbytz commented Nov 4, 2017

Go here for install link.

@Nosen

This comment has been minimized.

Show comment
Hide comment
@Nosen

Nosen Jan 26, 2018

On firefox this throws the following error "Firefox - document.execCommand(‘cut’/‘copy’) was denied because it was not called from inside a short running user-generated event handler"

Work around was to change the bookmarklet to add the event listener when clicked.

javascript: (function C2W2_5() {
  const isWF = location.href.indexOf("https://workflowy.com/#") === 0;

  if (isWF) {
    document
      .querySelector(".selected")
      .addEventListener("dblclick", clip2Flowy);
  } else {
    document.querySelector("html").addEventListener("dblclick", clip2Flowy);
  }

  function eOPML(str) {
    return str
      .replace(/&/g, "&amp;amp;")
      .replace(/</g, "&amp;lt;")
      .replace(/>/g, "&amp;gt;")
      .replace(/"/g, "&quot;")
      .replace(/(\n)/g, "&#10;");
  }
  function copy2(str) {
    var t = document.createElement("textarea");
    t.value = str;
    document.body.appendChild(t);
    t.select();
    document.execCommand("copy");
    document.body.removeChild(t);
  }
  function clip2Flowy() {
    {
      if (isWF && item_select.getSelectedItems().length > 0) {
        item_select.clearItemSelection();
      }
      var bullet = isWF
        ? `&lt;i&gt;Ref: ${eOPML(
            selectOnActivePage(".selected").getName()[0].textContent
          )}&lt;/i&gt;`
        : eOPML(document.title);
      var link = eOPML(location.href);
      copy2(
        `<opml><body><outline text="${bullet}" _note="${link}"/></body></opml>`
      );
      if (isWF) {
        showMessage("WorkFlowy link is ready to paste.");
        setTimeout(function() {
          hideMessage();
        }, 1500);
        document
          .querySelector(".selected")
          .removeEventListener("dblclick", clip2Flowy);
      } else {
        document
          .querySelector("html")
          .removeEventListener("dblclick", clip2Flowy);
      }
    }
  }
})();

For Workflowy
If you click the bookmarklet then double click the title of a zoomed in bullet the copy will work.

For Non-Workflowy
Click the bookmarklet, then double click somewhere non-linky on the page.

  • Because I'm listening for the double click event on the workflowy bullet I removed the inclusion of the selection in the note because it was the same as the bullet title.
  • Wasn't sure what element to target for the listener on non-flowy sites. Adding it to the html feels lame but it works for now.

Nosen commented Jan 26, 2018

On firefox this throws the following error "Firefox - document.execCommand(‘cut’/‘copy’) was denied because it was not called from inside a short running user-generated event handler"

Work around was to change the bookmarklet to add the event listener when clicked.

javascript: (function C2W2_5() {
  const isWF = location.href.indexOf("https://workflowy.com/#") === 0;

  if (isWF) {
    document
      .querySelector(".selected")
      .addEventListener("dblclick", clip2Flowy);
  } else {
    document.querySelector("html").addEventListener("dblclick", clip2Flowy);
  }

  function eOPML(str) {
    return str
      .replace(/&/g, "&amp;amp;")
      .replace(/</g, "&amp;lt;")
      .replace(/>/g, "&amp;gt;")
      .replace(/"/g, "&quot;")
      .replace(/(\n)/g, "&#10;");
  }
  function copy2(str) {
    var t = document.createElement("textarea");
    t.value = str;
    document.body.appendChild(t);
    t.select();
    document.execCommand("copy");
    document.body.removeChild(t);
  }
  function clip2Flowy() {
    {
      if (isWF && item_select.getSelectedItems().length > 0) {
        item_select.clearItemSelection();
      }
      var bullet = isWF
        ? `&lt;i&gt;Ref: ${eOPML(
            selectOnActivePage(".selected").getName()[0].textContent
          )}&lt;/i&gt;`
        : eOPML(document.title);
      var link = eOPML(location.href);
      copy2(
        `<opml><body><outline text="${bullet}" _note="${link}"/></body></opml>`
      );
      if (isWF) {
        showMessage("WorkFlowy link is ready to paste.");
        setTimeout(function() {
          hideMessage();
        }, 1500);
        document
          .querySelector(".selected")
          .removeEventListener("dblclick", clip2Flowy);
      } else {
        document
          .querySelector("html")
          .removeEventListener("dblclick", clip2Flowy);
      }
    }
  }
})();

For Workflowy
If you click the bookmarklet then double click the title of a zoomed in bullet the copy will work.

For Non-Workflowy
Click the bookmarklet, then double click somewhere non-linky on the page.

  • Because I'm listening for the double click event on the workflowy bullet I removed the inclusion of the selection in the note because it was the same as the bullet title.
  • Wasn't sure what element to target for the listener on non-flowy sites. Adding it to the html feels lame but it works for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment