Skip to content

Instantly share code, notes, and snippets.

@snaka
Created May 27, 2009 00:11
Show Gist options
  • Save snaka/118378 to your computer and use it in GitHub Desktop.
Save snaka/118378 to your computer and use it in GitHub Desktop.
(function(){
liberator.echomsg("Start js phase...");
// color scheme
if (liberator.has("Win32"))
liberator.execute("colorscheme sweets");
else
liberator.execute("colorscheme sweets_snaka");
// for copy.js
// 今見ているページのURLや選択範囲をテンプレートに従ってクリップボードにコピー
liberator.globalVariables.copy_templates = [
{ label: 'exlink', value: '<a href="%URL%" class="exlink">%TITLE%</a>' },
{ label: 'code', value: '<code>%SEL%</code>' },
{ label: 'H::D', value: '[%URL%:title=%TITLE%]' },
{ label: 'H::D(Quote)', value: '>%URL%:title=%TITLE%>\n%SEL%\n<<' },
{ label: 'H::D(Image)', value: '[%URL%:image]' },
{ label: 'titleAndURL', value: '%TITLE%\n%URL%' },
{ label: 'title', value: '%TITLE%' },
{ label: 'url', value: '%URL%' },
{ label: 'selanchor', value: '<a href="%URL%" title="%TITLE%">%SEL%</a>' },
{ label: 'htmlblockquote', value: '<blockquote cite="%URL%" title="%TITLE%">%HTMLSEL%</blockquote>' },
{ label: 'lilurl', value: 'Get lilurl', custom: function(){ return util.httpGet('http://10.73.127.27/lilurl/index.php?onlytext=true&longurl=' + encodeURIComponent(buffer.URL)).responseText;}}
];
// for toggler.js
// ツールバー,Deliciousバーの表示/非表示をクルクル切り替える
liberator.globalVariables.toggler = {
// ツールバー関係
go: [
["set go=Tm","js document.getElementById('ybToolbar').hidden=false"],
["set go=" ,"js document.getElementById('ybToolbar').hidden=false"],
["set go=" ,"js document.getElementById('ybToolbar').hidden=true"]
],
// サイドバー関係
sb:["sbclose","sbar Delicious"],
};
// _libly.js のXPath関数のショートカット
function $LX(a,b) plugins.libly.$U.getFirstNodeFromXPath(a,b);
function $LXs(a,b,c,d) plugins.libly.$U.getNodesFromXPath(a,b,c,d);
// _smooziee.js スペースバーでスムーズスクロール
mappings.addUserMap([modes.NORMAL], ["<Space>"], "Page Down",
function() plugins.smooziee.smoothScrollBy(content.innerHeight - 40)
);
mappings.addUserMap([modes.NORMAL], ["<S-Space>"], "Page Up",
function() plugins.smooziee.smoothScrollBy((content.innerHeight - 40)*-1)
);
// l ivedoor Weather API からじょうほう取得
//var location = 63;
//var weatherInfoXML = getlivedoorWeather(location, ldweather.DAY_TODAY);
//[imageURL, caption, description] = extractWeatherInfo(weatherInfoXML);
// for MultiRequester
liberator.globalVariables.multi_requester_siteinfo = [
{
args: 'location', // optional:
name: 'weather-com', // required: subcommand name
description: 'Retleave weather information from www.weather.com.', // required: commandline short help
url: 'http://www.weather.com/outlook/travel/businesstraveler/local/JAXX0085?lswe=%s&from=searchbox_localwx', // required: %s <-- replace string
//xpath: "//*[@id='wmContent']", // optional: default all
},
];
// フィードボタンをステータスラインに移動
var feedButton = document.getElementById('feed-button');
feedButton.parentNode.removeChild(feedButton);
var feedPanel = document.createElement('statusbarpanel');
feedPanel.setAttribute('id', 'feed-panel-clone');
feedPanel.appendChild(feedButton.cloneNode(true));
document.getElementById('status-bar').insertBefore(
feedPanel,
document.getElementById('security-button')
);
// MOWの高さを制限する
document.getElementById("liberator-multiline-output").parentNode.maxHeight = content.innerHeight * 0.4
//
// Processes after load plugins
//
liberator.registerObserver("enter", function() {
// for auto_word_select.js
mappings.addUserMap(
[modes.AUTO_WORD_SELECT, modes.VISUAL, modes.NORMAL, modes.CARET],
["s"],
"Translate selected word by multi_requester.js.",
function() {
// FIXME:
// A present mode is preserved in the stack beforehand by the push() method
// because it doesn't return to AUTO_WORD_SELECT mode before that when
// returning from the OUTPUT_MULTILINE mode.
modes.push(modes.AUTO_WORD_SELECT, null, true);
var selText = content.getSelection().toString();
var pattern = /[a-zA-Z]+/;
selText = pattern.test(selText) ? pattern.exec(selText) : selText;
//events.feedkeys(":mr alc " + selText + "<CR>", true, true);
liberator.execute(":mr alc " + selText);
let selection = content.getSelection();
if (selection.focusNode.parentNode)
selection.focusNode.parentNode.scrollIntoView();
}
);
// キャレット位置のリンクをたどる
mappings.addUserMap(
[modes.AUTO_WORD_SELECT, modes.CARET],
["<C-]>"],
"Follow link",
function() {
let selection = content.getSelection();
if (selection.rangeCount == 0)
return;
let link = extractLink(getContainerNode(selection), selection);
if (link)
buffer.followLink(link, liberator.CURRENT_TAB);
else
liberator.echoerr("Link item doesn't exists.");
}
);
function extractLink(node, selection) {
if (node.tagName == "A")
return node;
for each (let i in node.getElementsByTagName('a'))
if (selection.containsNode(i, true))
return i;
return null;
}
});
//
// XPath Inspect hint mode
//
hints.addMode(
'i', 'inspectThis',
function(elem) inspectDOMNode(elem),
function() '//*'
);
commands.addUserCommand(
['setInspectionXPath', 'six'],
'Set a XPath in the Hints Mode of Inspection',
function(args){
hints.addMode(
'i', 'inspectThis',
function(elem) inspectDOMNode(elem),
function() args.string
);
},
{},
true
);
liberator.echomsg("Finish js phase...");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment