Created
March 29, 2019 15:32
-
-
Save HaiNguyen007/fb7bc81891f841852f14d5bad6d281b3 to your computer and use it in GitHub Desktop.
Clip To WorkFlowy Bookmarklet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Version 2.6 | |
(function () { | |
function eOPML(str) { | |
return str | |
.replace(/&/g, '&') | |
.replace(/</g, '&lt;') | |
.replace(/>/g, '&gt;') | |
.replace(/"/g, '"') | |
.replace(/(\n)/g, ' '); | |
} | |
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 ? '<i>See: "' + eOPML(selectOnActivePage(".selected").getName()[0].textContent) + '"</i>' : eOPML(document.title); | |
var selected = eOPML(window.getSelection().toString()); | |
var link = eOPML(location.href); | |
var note = selected ? '..' + link + ' ' + 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