(function($) { //Sınıf function Bookmarklet() { this.prepare(); } //Stylesheet dosyası Bookmarklet.STYLE = { _textarea: { width: 200, height: 50, outline: 'none', border: 0 }, _submit: { width: 200 }, _container: { position: 'absolute', top: 10, right: 10, width: 200, background: '#CCC', padding: 10, WebkitBorderRadius: 10, WebkitBoxShadow: '1px 1px 2px #222', zIndex: 9999999 } }; Bookmarklet.prototype.prepare = function() { //Dökümandaki seçili texti al. Not: Browserlara göre farklılaşabilir. var text = window.getSelection().toString(); var _textarea = $('<textarea/>').val(text); var _container = $('<div/>'); var _submit = $('<button/>'); //Css'leri uygula _textarea.css(Bookmarklet.STYLE._textarea); _container.css(Bookmarklet.STYLE._container); _submit.css(Bookmarklet.STYLE._submit); if (text!='') _submit.html('Tweet Selected'); else _submit.html('Tweet!'); _submit.click(function() { window.open('http://twitter.com/?status='+encodeURIComponent(_textarea.val())); }); _container.append(_textarea); _container.append(_submit); //Div'i ekliyoruz $(document.body).prepend(_container); }; //jQuery var mı? //Burada jQuery kontrolü yapılır ve yoksa eklenir. if (typeof $ == 'undefined') { var jquery = document.createElement('script'); jquery.src = 'http://code.jquery.com/jquery-latest.js'; jquery.onerror = function() { //jQuery yüklenemezse alert('Bookmarklet error, please try again.'); }; jquery.onload = function() { //jQuery yüklendiğinde sınıftan bir instance oluştur. if (!$)$ = window.jQuery; var bookmarklet = new Bookmarklet(); }; document.getElementsByTagName('head')[0].appendChild(jquery); } else { var bookmarklet = new Bookmarklet(); } })(window.jQuery);