Skip to content

Instantly share code, notes, and snippets.

@HaiNguyen007
Created March 29, 2019 15:32
Show Gist options
  • Save HaiNguyen007/fb7bc81891f841852f14d5bad6d281b3 to your computer and use it in GitHub Desktop.
Save HaiNguyen007/fb7bc81891f841852f14d5bad6d281b3 to your computer and use it in GitHub Desktop.
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.');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment