aboutsummaryrefslogtreecommitdiffstats
path: root/gbmark.js
blob: 22de6c8564516552b4d2542da2c772fcee5e2ff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// INFO //
var INFO = 
<plugin name="gbmark.js" version="0.2"
        summary="Add Google Bookmark."
        href="http://github.com/vimpr/vimperator-plugins/blob/master/gbmark.js"
        xmlns="http://vimperator.org/namespaces/liberator">
  <author email="mitsugu.oyama@gmail.com">Mitsugu Oyama</author>
  <license href="http://opensource.org/licenses/mit-license.php">MIT</license>
  <project name="Vimperator" minVersion="2.3"/>
  <p>Add Google Bookmark.</p>
  <item>
    <tags>'gbmark.js'</tags>
    <spec>:gbmark</spec>
    <description>
      <p>Add Google Bookmark.</p>
    </description>
  </item>
</plugin>;

(function(){
  commands.addUserCommand(
    ['gbmark'],
    'Add Google Bookmark.',
    function(){
      let Cc=Components.classes;
      let Ci=Components.interfaces;
      let doc=gBrowser.selectedBrowser.contentDocument;
      let strEndPoint='http://www.google.com/bookmarks/mark?op=add&bkmk=';
      let strUrl=doc.URL;
      let strTitle=doc.title;
      let strSelect=doc.defaultView.getSelection().toString();
      let strUri;
      if(1<strSelect.length){
        strUri=strEndPoint+encodeURIComponent(strUrl)
          +'&title='+encodeURIComponent(strTitle)
          +'&annotation='+encodeURIComponent(strSelect)+'&hl=ja';
      }else{
        strUri=strEndPoint+encodeURIComponent(strUrl)
          +'&title='+encodeURIComponent(strTitle)+'&hl=ja';
      }
      gBrowser.addTab(strUri);
    }
  );
})();
_initialize.apply(this, arguments); } Highlighter.prototype = { _initialize: function (args) { if (args) this.set(args); this.highlightList = []; }, set: function (args) { this.color = args.color; this.opacity = args.opacity; this.interval = args.interval; this._prepareTemplate(); return this; }, _prepareTemplate: function () { let div = window.document.createElement('div'); div.className = 'vimp_plugin_highlightelement'; let style = fixedStyle + [ 'background-color: ' + this.color + ';', '-moz-opacity: ' + this.opacity + ';' ].join(''); div.setAttribute('style', style); this._highlightTemplate = div; }, highlight: function (element) { if (!this._isDisplay(element)) return; let doc = element.ownerDocument; // TODO: highlight XUL elements if (!doc.body) return; let scrollX = doc.defaultView.scrollX; let scrollY = doc.defaultView.scrollY; let rects = element.getClientRects(); for (let i=0, l=rects.length ; i<l ; ++i) { let r = rects[i]; let h = this._buildHighlighter({ top: r.top + scrollY, left: r.left + scrollX, width: r.right - r.left, height: r.bottom - r.top, }); this.highlightList.push(h); doc.body.appendChild(h); } }, _unhighlight: function (element) { if (element.intervalId) clearInterval(element.intervalId); element.parentNode.removeChild(element); }, unhighlightAll: function () { let list = this.highlightList; while (list.length) this._unhighlight(list.pop()); }, _isDisplay: function (element) { let computedStyle = content.document.defaultView.getComputedStyle(element, null); return ( computedStyle.getPropertyValue('visibility') !== 'hidden' && computedStyle.getPropertyValue('display') !== 'none'); }, _buildHighlighter: function (rect) { let div = this._highlightTemplate.cloneNode(false); div.style.top = rect.top + 'px'; div.style.left = rect.left + 'px'; div.style.width = rect.width + 'px'; div.style.height = rect.height + 'px'; if (this.interval > 0) { div.intervalId = setInterval( function () { let d = div.style.display; div.style.display = (d === 'block' ? 'none' : 'block'); }, this.interval ); } else { div.intervalId = undefined; } return div; }, }; if (!plugins.highlighterFactory) { plugins.highlighterFactory = function () { let h = new Highlighter(); return h.set.apply(h, arguments); } } } )(); // vim: set sw=4 ts=4 et;