Handy alert with copy/paste-able yaml front matter of current page and text selection.
See it here.
- Created with bookmarkleter by @chriszarate
- Code uses jquery.selection by @madapaja
Handy alert with copy/paste-able yaml front matter of current page and text selection.
<p>Drag the | |
<a href="javascript:void%20function(e){var%20t=function(e){(function(e,t,n){var%20r=function(e){var%20r={text:%22%22,start:0,end:0};if(!e.value)return%20r;try{if(t.getSelection)r.start=e.selectionStart,r.end=e.selectionEnd,r.text=e.value.slice(r.start,r.end);else%20if(n.selection){e.focus();var%20a=n.selection.createRange(),s=n.body.createTextRange();r.text=a.text;try{s.moveToElementText(e),s.setEndPoint(%22StartToStart%22,a)}catch(o){s=e.createTextRange(),s.setEndPoint(%22StartToStart%22,a)}r.start=e.value.length-s.text.length,r.end=r.start+a.text.length}}catch(o){}return%20r},a={getPos:function(e){var%20t=r(e);return{start:t.start,end:t.end}},setPos:function(e,n,r){r=this._caretMode(r),%22start%22===r%3Fn.end=n.start:%22end%22===r%26%26(n.start=n.end),e.focus();try{if(e.createTextRange){var%20a=e.createTextRange();t.navigator.userAgent.toLowerCase().indexOf(%22msie%22)%3E=0%26%26(n.start=e.value.substr(0,n.start).replace(/\r/g,%22%22).length,n.end=e.value.substr(0,n.end).replace(/\r/g,%22%22).length),a.collapse(!0),a.moveStart(%22character%22,n.start),a.moveEnd(%22character%22,n.end-n.start),a.select()}else%20e.setSelectionRange%26%26e.setSelectionRange(n.start,n.end)}catch(s){}},getText:function(e){return%20r(e).text},_caretMode:function(e){switch(e=e||%22keep%22,e===!1%26%26(e=%22end%22),e){case%22keep%22:case%22start%22:case%22end%22:break;default:e=%22keep%22}return%20e},replace:function(t,n,a){var%20s=r(t),o=t.value,c=e(t).scrollTop(),i={start:s.start,end:s.start+n.length};t.value=o.substr(0,s.start)+n+o.substr(s.end),e(t).scrollTop(c),this.setPos(t,i,a)},insertBefore:function(t,n,a){var%20s=r(t),o=t.value,c=e(t).scrollTop(),i={start:s.start+n.length,end:s.end+n.length};t.value=o.substr(0,s.start)+n+o.substr(s.start),e(t).scrollTop(c),this.setPos(t,i,a)},insertAfter:function(t,n,a){var%20s=r(t),o=t.value,c=e(t).scrollTop(),i={start:s.start,end:s.end};t.value=o.substr(0,s.end)+n+o.substr(s.end),e(t).scrollTop(c),this.setPos(t,i,a)}};e.extend({selection:function(r){var%20a=%22text%22===(r||%22text%22).toLowerCase();try{if(t.getSelection){if(a)return%20t.getSelection().toString();var%20s,o=t.getSelection();return%20o.getRangeAt%3Fs=o.getRangeAt(0):(s=n.createRange(),s.setStart(o.anchorNode,o.anchorOffset),s.setEnd(o.focusNode,o.focusOffset)),e(%22%3Cdiv%3E%3C/div%3E%22).append(s.cloneContents()).html()}if(n.selection)return%20a%3Fn.selection.createRange().text:n.selection.createRange().htmlText}catch(c){}return%22%22}}),e.fn.extend({selection:function(e,t){switch(t=t||{},e){case%22getPos%22:return%20a.getPos(this[0]);case%22setPos%22:return%20this.each(function(){a.setPos(this,t)});case%22replace%22:return%20this.each(function(){a.replace(this,t.text,t.caret)});case%22insert%22:return%20this.each(function(){%22before%22===t.mode%3Fa.insertBefore(this,t.text,t.caret):a.insertAfter(this,t.text,t.caret)});case%22get%22:default:return%20a.getText(this[0])}return%20this}})})(jQuery,window,window.document),alert((new%20Date).toISOString().split(%22.%22)[0].replace(/[T:]/g,%22-%22)+%22.md\n\n---\ntitle:%20'%22+document.title+%22'\nlink:%20%22+document.location+%22\n---\n%22+e.selection())},n=e%26%26e.fn%26%26parseFloat(e.fn.jquery)%3E=1.7;if(n)t(e);else{var%20r=document.createElement(%22script%22);r.src=%22//ajax.googleapis.com/ajax/libs/jquery/1/jquery.js%22,r.onload=r.onreadystatechange=function(){var%20e=this.readyState;e%26%26%22loaded%22!==e%26%26%22complete%22!==e||t(jQuery.noConflict())}}document.getElementsByTagName(%22head%22)[0].appendChild(r)}(window.jQuery);">.jekyll</a> | |
bookmarklet to your toolbar, then go to a page, select some text and click it (text selection doesn't work on some sites, e.g. github 😖).</p> | |
<p>You get an alert with handy text to copy. That's all there is to it.</p> |