aboutsummaryrefslogtreecommitdiffstats
path: root/zoom-em-all.js
blob: 68771142984bb858dc7b299d655e7a180590c6ac (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* NEW BSD LICENSE {{{
Copyright (c) 2010, anekos.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
    3. The names of the authors may not be used to endorse or promote products
       derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.


###################################################################################
# http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license       #
# に参考になる日本語訳がありますが、有効なのは上記英文となります。                #
###################################################################################

}}} */

// PLUGIN_INFO {{{
let PLUGIN_INFO =
<VimperatorPlugin>
  <name>Zoom Em All</name>
  <name lang="ja">Zoom Em All</name>
  <description>Zoom them all.</description>
  <description lang="ja">ブラウザ全体をズーム</description>
  <version>1.1.0</version>
  <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author>
  <license>new BSD License (Please read the source code comments of this plugin)</license>
  <license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license>
  <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/zoom-em-all.js</updateURL>
  <minVersion>2.3</minVersion>
  <maxVersion>2.3</maxVersion>
  <detail><![CDATA[
    ----
  ]]></detail>
  <detail lang="ja"><![CDATA[
    ----
  ]]></detail>
</VimperatorPlugin>;
// }}}
// INFO {{{
let INFO =
<>
  <plugin name="ZoomEmAll" version="1.1.0"
          href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/zoom-em-all.js"
          summary="Zoom or pan for whole firefox."
          lang="en-US"
          xmlns="http://vimperator.org/namespaces/liberator">
    <author email="anekos@snca.net">anekos</author>
    <license>New BSD License</license>
    <project name="Vimperator" minVersion="2.3"/>
    <p>Zoom or pan browser.</p>
    <item>
      <tags>:zoomall</tags>
      <tags>:zooma</tags>
      <spec>:zoomall <oa>percentage</oa></spec>
      <description>
        <p>Zoom to <oa>percentage</oa>.</p>
        <p>If not given the argument, reset zoom.</p>
      </description>
    </item>
  </plugin>
  <plugin name="ZoomEmAll" version="1.1.0"
          href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/zoom-em-all.js"
          summary="ブラウザ全体をズーム"
          lang="ja"
          xmlns="http://vimperator.org/namespaces/liberator">
    <author email="anekos@snca.net">anekos</author>
    <license>New BSD License</license>
    <project name="Vimperator" minVersion="2.3"/>
    <p>ブラウザ全体を拡大縮小します</p>
    <item>
      <tags>:zoomall</tags>
      <tags>:zooma</tags>
      <spec>:zoomall <oa>percentage</oa></spec>
      <description>
        <p><oa>percentage</oa>(%)で拡縮します。</p>
        <p>引数省略時は100%にリセットします</p>
      </description>
    </item>
  </plugin>
</>;
// }}}

(function () {

  const docViewer =
    window.QueryInterface(Ci.nsIInterfaceRequestor).
      getInterface(Ci.nsIWebNavigation).
      QueryInterface(Ci.nsIDocShell).
      contentViewer.
      QueryInterface(Ci.nsIMarkupDocumentViewer);

  __context__.__defineGetter__('fullZoom', function () docViewer.fullZoom);
  __context__.__defineSetter__('fullZoom', function (v) docViewer.fullZoom = v);


  commands.addUserCommand(
    ['zooma[ll]', 'zoomemall'],
    'Zoom Em All',
    function (args) {
      let [, s, d] = args.literalArg.trim().match(/^([-+])(\d+)/) || [];
      if (d) {
        docViewer.fullZoom += parseInt(args.literalArg || '100', 10) / 100;
      } else {
        docViewer.fullZoom = parseInt(args.literalArg || '100', 10) / 100;
      }
    },
    {
      literal: 0
    },
    true
  );

})();

// vim:sw=2 ts=2 et si fdm=marker:
span>,key,desc,aroundFunc,extra){ var old = liberator.modules.mappings.getDefault(mode,key); var oldAction = old.action; old.description = desc; old.action = function() let (self = this,args = arguments) aroundFunc(function() oldAction.apply(self,args)); } var LDRizeCooperation = new Class(); LDRizeCooperation.prototype = { initialize: function(){ var self = this; this.LDRize = {getSiteinfo: function() undefined}; this.Minibuffer = null; this.handlerInfo = handlerInfo; this.LDRizeCooperationPanel = this.setupStatusbarPanel(); this.isEnable = liberator.globalVariables.ldrc_enable != undefined ? window.eval(liberator.globalVariables.ldrc_enable) : true ; this.isIntelligenceBind = liberator.globalVariables.ldrc_intelligence_bind != undefined ? window.eval(liberator.globalVariables.ldrc_intelligence_bind) : false ; this.isModHints = liberator.globalVariables.ldrc_hints != undefined ? window.eval(liberator.globalVariables.ldrc_hints) : false ; this.captureMappings = window.eval(liberator.globalVariables.ldrc_captureMappings) || ["j","k","p","o"]; this.skipHeight = liberator.globalVariables.ldrc_skip != undefined ? window.eval(liberator.globalVariables.ldrc_skip) : 0.5 ; this.convertHandlerInfo(this.handlerInfo); this.hookGreasemonkey(); this.initLDRizeCaptureKeys(this.captureMappings); this.initLDRizeCooperationFuture(); if(liberator.plugins.LDRizeCooperationPlugins != undefined){ liberator.plugins.LDRizeCooperationPlugins.forEach(function(func){ func.apply(self,arguments); }); delete liberator.plugins.LDRizeCooperationPlugins; } }, setupStatusbarPanel: function(){ var self = this; var LDRizeCooperationPanel = document.createElement("statusbarpanel"); LDRizeCooperationPanel.setAttribute("id","ldrizecopperation-status"); LDRizeCooperationPanel.setAttribute("class","statusbarpanel-iconic"); LDRizeCooperationPanel.setAttribute("src",this.isEnable ? ENABLE_ICON : DISABLE_ICON); LDRizeCooperationPanel.addEventListener("click",function(e){ self.isEnable = !self.isEnable; },false); document.getElementById("status-bar").insertBefore(LDRizeCooperationPanel,document.getElementById("security-button").nextSibling); return LDRizeCooperationPanel; }, hookGreasemonkey: function(){ var self = this; var GreasemonkeyService; try{ GreasemonkeyService = Cc["@greasemonkey.mozdev.org/greasemonkey-service;1"].getService().wrappedJSObject; this.addAfter(GreasemonkeyService,"evalInSandbox",function(code,codebase,sandbox){ if(sandbox.window.LDRize != undefined && sandbox.window.Minibuffer != undefined){ sandbox.window.addEventListener("focus",function(){ self.LDRize = liberator.eval("self",sandbox.LDRize.getSiteinfo); self.Minibuffer = liberator.eval("command",sandbox.Minibuffer.addCommand); },false); if(window.content.wrappedJSObject == sandbox.unsafeWindow){ self.LDRize = liberator.eval("self",sandbox.LDRize.getSiteinfo); self.Minibuffer = liberator.eval("command",sandbox.Minibuffer.addCommand); } } }); }catch(e){ liberator.log(e); } }, initLDRizeCaptureKeys: function(keys){ var self = this; keys.forEach(function(x){ var map = liberator.modules.mappings.get(null,x) || liberator.modules.mappings.getDefault(null,x); var oldAction = map.action; var getter = "getPrev"; switch(x){ case "j": getter = "getNext"; case "k": map.action = function(){ self.isEnableLDRizeCooperation() ? self.isIntelligenceBind && self.isScrollOrBind(getter) ? oldAction.apply(this,arguments) // scroll : self.sendRawKeyEvent(0,x.charCodeAt(0)) // bind : oldAction.apply(this,arguments); }; break; case "J": case "K": map.action = function(){ self.isEnableLDRizeCooperation() ? self.sendRawKeyEvent(0,x.charCodeAt(0) + 32) : oldAction.apply(this,arguments); }; break; default: map.action = function(){ self.isEnableLDRizeCooperation() ? self.sendRawKeyEvent(0,x.charCodeAt(0)) : oldAction.apply(this,arguments); }; break; } }); }, initLDRizeCooperationFuture: function(){ var self = this; //Hints [ ["l","LDRize paragraphes",liberator.CURRENT_TAB], ["L","LDRize paragraphes (in a new tab",liberator.NEW_TAB] ].forEach(function([mode,prompt,target]){ liberator.modules.hints.addMode(mode,prompt, function(elem) liberator.modules.buffer.followLink(elem,target), function(){ var siteinfo = self.LDRize.getSiteinfo(); return siteinfo.paragraph + "/" + siteinfo.link; }); }); //Commands liberator.modules.commands.addUserCommand(["pin"],"LDRize Pinned Links", function(){ var links = self.getPinnedItems(); var showString = links.length + " Items<br/>"; links.forEach(function(link){ showString += link + "<br/>"; }); liberator.modules.commandline.echo(showString,liberator.modules.commandline.HL_NORMAL,liberator.modules.commandline.FORCE_MULTILINE); },{}); liberator.modules.commands.addUserCommand(["mb","m","minibuffer"],"Execute Minibuffer", function(arg){ self.Minibuffer.execute(arg.string.replace(/\\+/g,"")) }, { completer: function(context,arg,special){ var filter = context.filter; var completionList = []; var command = self.Minibuffer.command; var alias = self.Minibuffer.alias_getter(); var tokens = filter.split("|").map(function(str) str.replace(/\s+/g,"")); var exp = new RegExp("^" + tokens.pop()); for(let i in command) if(exp.test(i))completionList.push([tokens.concat(i).join(" | "),"MinibufferCommand"]); for(let i in alias) if(exp.test(i))completionList.push([i,"MinibufferAlias"]); context.title = ["Minibuffer Command","Description"]; context.completions = completionList; } }); liberator.modules.commands.addUserCommand(["pindownload"],"Download pinned links by any software", function(arg){ self.downloadLinksByProgram(self.getPinnedItems());},{}); liberator.modules.commands.addUserCommand(["toggleldrizecooperation","toggleldrc"],"Toggle LDRize Cooperation", function(arg){ self.isEnable = !self.isEnable},{}); //Options liberator.modules.options.add(["ldrc","ldrizecooperation"],"LDRize cooperation","boolean",this.isEnable, { setter: function(value){ self.isEnable = value; }, getter: function() self.isEnable } ); liberator.modules.options.add(["ldrchints"],"mod hinttags for LDRize","boolean",this.isModHints, { setter: function(value){ self.isModHints = value; }, getter: function() self.isModHints } ); }, convertHandlerInfo: function(handlerInfoArray){ handlerInfoArray.forEach(function(x){ x.include = typeof x.include != "undefined" ? typeof x.include == "string" ? new RegExp(x.include) : new RegExp(x.include[0],x.include[1]) : typeof x.pattern != "undefined" ? new RegExp("^"+String(x.pattern).replace(/\s+/g,"").replace(/[\\^$.+?|(){}\[\]]/g,"\\$&") .replace(/(?=\*)/g,".")+"$","i") : /(?:)/; delete x.pattern; }); }, get isEnable() _isEnable, set isEnable(value){ this.LDRizeCooperationPanel.setAttribute("src",value ? DISABLE_ICON : ENABLE_ICON); _isEnable = value; }, isEnableLDRize: function() this.LDRize.getSiteinfo() != undefined, isEnableLDRizeCooperation: function() this.isEnable && this.isEnableLDRize(), //Pin getPinnedItems: function(){ var linkXpath = this.LDRize.getSiteinfo()["link"]; var viewXpath = this.LDRize.getSiteinfo()["view"] || linkXpath + "/text()"; return this.LDRize.getPinnedItems().map(function(i){ var linkResult = i.XPath(linkXpath),viewResult = i.XPath(viewXpath); return [linkResult,viewResult ? viewResult.textContent : null]; }); }, downloadLinksByProgram: function(links){ var self = this; var count = 0; links.forEach(function([url,title]){ for each(let x in self.handlerInfo){ if(x.include.test(url)){ setTimeout(function(){ if(typeof x.handler == "object"){ let args = x.handler[1].map(function(s) s.replace(/%URL%/g,url).replace(/%TITLE%/g,title)); liberator.modules.io.run(x.handler[0],args,false); }else if(typeof x.handler == "string"){ liberator.modules.io.run(x.handler,[url],false); }else if(typeof x.handler == "function"){ x.handler(url.toString(),title); } },x.wait != undefined ? x.wait * count++ : 0); return; } } liberator.echoerr("LDRize Cooperation: download pattern not found!!"); }); }, isScrollOrBind: function(getter){ var self = this; var paragraphes,paragraph,current,next,innerHeight,scrollY,limit,p,np,cp; try{ paragraphes = this.LDRize.getParagraphes(); paragraph = paragraphes[getter](); current = paragraphes.current; next = paragraphes.getNext(); innerHeight = window.content.innerHeight; scrollY = window.content.scrollY; limit = window.content.innerHeight * (self.skipHeight + 0.5); if(paragraph.paragraph == undefined) return true; // scroll if(current.paragraph == undefined) return false; // bind if(current.paragraph.y - window.content.scrollY == this.LDRize.getScrollHeight() && getter == "getPrev") return false; // bind p = this.getClientPosition(paragraph.paragraph.node); np = next && next.paragraph.node != undefined ? this.getClientPosition(next.paragraph.node) : {top: window.content.scrollMaxY + window.content.innerHeight,left: 0}; cp = this.getClientPosition(current.paragraph.node); /* *log(p); *log(np); *log(cp); */ //check current paragraph if(!(scrollY < np.top && cp.top < scrollY + innerHeight)) return false; // bind //check next/prev paragraph if(Math.abs(p.top - (scrollY + innerHeight/2)) < innerHeight * 0.5) return false; // bind if(Math.abs(p.top - (scrollY + innerHeight/2)) > limit) return true; // scroll return false; // bind }catch(e){ liberator.log(e); } }, //Utils addAfter: function(target,name,after){ var original = target[name]; target[name] = function(){ var tmp = original.apply(target,arguments); after.apply(target,arguments); return tmp; }; }, getClientPosition: function(elem){ var position; try{ position = elem.getBoundingClientRect(); }catch(e){ position = elem.parentNode.getBoundingClientRect(); } return { left: Math.round(window.content.scrollX+position.left), top: Math.round(window.content.scrollY+position.top) }; }, sendRawKeyEvent: function(keyCode,charCode){ var evt = window.content.wrappedJSObject.document.createEvent("KeyEvents"); evt.initKeyEvent("keypress",true,true,window.content.wrappedJSObject,false,false,false,false,keyCode,charCode); window.content.wrappedJSObject.document.dispatchEvent(evt); }, }; liberator.plugins.LDRizeCooperation = new LDRizeCooperation(); })();