Skip to content

Commit

Permalink
add vimperator stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukkee committed Feb 28, 2011
1 parent e5a395b commit cba4128
Show file tree
Hide file tree
Showing 12 changed files with 2,907 additions and 5 deletions.
731 changes: 731 additions & 0 deletions vimperator/plugin/_libly.js

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions vimperator/plugin/auto-focus-frame.js
@@ -0,0 +1,89 @@
/* NEW BSD LICENSE {{{
Copyright (c) 2009, 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>Auto focus frame</name>
<description>Automatically focus to largest frame.</description>
<description lang="ja">最も大きなフレームに自動的にフォーカスする。</description>
<version>1.0.10</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/auto-focus-frame.js</updateURL>
<minVersion>2.3pre</minVersion>
<maxVersion>2.3pre</maxVersion>
<detail><![CDATA[
== Usage ==
Only install.
]]></detail>
<detail lang="ja"><![CDATA[
== Usage ==
インストールするだけ
一番面積の大きいフレームをフォーカスします
]]></detail>
</VimperatorPlugin>;
// }}}

(function () {

function onLoad () {
if (!(window.content.document instanceof HTMLDocument) || (content.frames.length <= 1))
return;

let targetFrames = [
frame
for (frame in util.Array.itervalues(content.frames))
if (frame.frameElement instanceof HTMLFrameElement)
];

let [maxSize, maxFrame] = [-1, null];
targetFrames.forEach(function(frame) {
if (frame.scrollMaxX <= 0 && frame.scrollMaxY <= 0)
return;
let size = frame.innerWidth * frame.innerHeight;
if (maxSize < size)
[maxSize, maxFrame] = [size, frame];
});
if (maxFrame)
maxFrame.focus();
}

getBrowser().addEventListener("DOMContentLoaded", onLoad, true);


})();

// vim:sw=2 ts=2 et si fdm=marker:
120 changes: 120 additions & 0 deletions vimperator/plugin/commandBookmarklet.js
@@ -0,0 +1,120 @@
/**
* bookmarklet wo command ni suru plugin
*
* @author halt feits <halt.feits@gmail.com>
* @version 0.6.4
*/

let PLUGIN_INFO =
<VimperatorPlugin>
<name>{NAME}</name>
<description>convert bookmarklets to commands</description>
<description lang="ja">ブックマークレットをコマンドにする</description>
<author mail="halt.feits@gmail.com">halt feits</author>
<version>0.6.6</version>
<minVersion>2.0pre</minVersion>
<maxVersion>2.1pre</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/commandBookmarklet.js</updateURL>
<detail><![CDATA[
== SYNOPSIS ==
This plugin automatically converts bookmarklets to valid commands for Vimperator.

== COMMAND ==
Nothing built-in command, but each bookmarklets convert to commands that start with "bml".

== EXAMPLE ==
"Hatena-Bookmark" -> bmlhatena-bookmark
== GLOBAL VARIABLES ==
command_bookmarklet_prefix:
This variable determines the prefix of a command name.
command_bookmarklet_use_sandbox:
When this variable is 1, execute the script of bookmarklets in Sandbox.
If you use NoScript addon, probably you should enable this option.
== KNOWN ISSUES ==
When title has non-ASCII characters, it converts to unaccountable command.
You should rewrite title of bookmarklet to ASCII characters, to escape this issue.
]]></detail>
<detail lang="ja"><![CDATA[
== SYNOPSIS ==
このプラグインはブックマークレットを Vimperator で実行可能なコマンドに自動的に変換します。
== COMMAND ==
固有のコマンドはありませんが、それぞれのブックマークレットは "bml" ではじまるコマンドに変換されます。
== EXAMPLE ==
"Hatena-Bookmark" -> bmlhatena-bookmark
== GLOBAL VARIABLES ==
command_bookmarklet_prefix:
コマンドの先頭に付加される文字列を規定します。
デフォルトは "bml"
command_bookmarklet_use_sandbox:
1 の時、ブックマークレットのスクリプトを sandbox で実行します。
NoScript アドオンをつかっている場合は、このオプションを有効にする必要があるでしょう。
== KNOWN ISSUES ==
タイトルに ASCII 文字以外が含まれている場合、わけのわからないコマンドになります。
この問題を避けるためにブックマークレットのタイトルを ASCII 文字のみに書き換えることをおすすめします。
]]></detail>
</VimperatorPlugin>;
( function () {
let prefix = liberator.globalVariables.command_bookmarklet_prefix;
if (prefix === undefined)
prefix = 'bml';
let items = bookmarks.get('javascript:');
if (!items.length) {
liberator.echoerr('No bookmarks set');
return;
}
items.forEach(function (item) {
commands.addUserCommand(
[toValidCommandName(item.title)],
'bookmarklet : ' + item.title,
function () evalScript(item.url),
{ shortHelp: 'Bookmarklet' },
false
);
});
function toBoolean (value, def) {
switch (typeof value) {
case 'undefined':
return def;
case 'number':
return !!value;
case 'string':
return !/^(\d+|false)$/i.test(value) || parseInt(value);
default:
return !!value;
}
}
function evalInSandbox (str) {
let sandbox = new Components.utils.Sandbox("about:blank");
sandbox.__proto__ = content.window.wrappedJSObject;
return Components.utils.evalInSandbox(str, sandbox);
}

function evalScript (url) {
if (toBoolean(liberator.globalVariables.command_bookmarklet_use_sandbox, false)) {
evalInSandbox(decodeURIComponent(url.replace(/^\s*javascript:/i, '')));
} else {
liberator.open(url);
}
}

function toValidCommandName(str) {
str = prefix + escape(str.replace(/ +/g, '').toLowerCase()).replace(/[^a-zA-Z]+/g,'');
return str.substr(0, str.length > 50 ? 50 : str.length);
}

} )();
// vim:sw=2 ts=2 et:

0 comments on commit cba4128

Please sign in to comment.