diff options
-rw-r--r-- | _libly.js | 2 | ||||
-rw-r--r-- | asdfghjkl.js | 2 | ||||
-rw-r--r-- | browser_object.js | 4 | ||||
-rw-r--r-- | chaika.js | 24 | ||||
-rw-r--r-- | edit-vimperator-files.js | 7 | ||||
-rw-r--r-- | googleselect.js | 96 | ||||
-rw-r--r-- | microsoft-translator.js | 169 | ||||
-rw-r--r-- | pixiv.js | 49 | ||||
-rw-r--r-- | twittperator.js | 8 | ||||
-rw-r--r-- | zip-de-download.js | 2 | ||||
-rw-r--r-- | zoom-em-all.js | 10 |
11 files changed, 259 insertions, 114 deletions
@@ -280,7 +280,7 @@ libly.$U = {//{{{ } original = obj[name]; let current = obj[name] = function () { - let self = this, args = arguments; + let self = this, args = Array.from(arguments); return func.call(self, function (_args) original.apply(self, _args || args), args); }; libly.$U.extend(current, {original: original && original.original || original, restore: restore}); diff --git a/asdfghjkl.js b/asdfghjkl.js index 1f48516..7826a48 100644 --- a/asdfghjkl.js +++ b/asdfghjkl.js @@ -98,7 +98,7 @@ let PLUGIN_INFO = xml` function around (obj, name, func) { let next = obj[name]; obj[name] = function () - let (self = this, args = arguments) + let (self = this, args = Array.from(arguments)) func.call(self, function () next.apply(self, args), args); diff --git a/browser_object.js b/browser_object.js index badeba4..9260b1d 100644 --- a/browser_object.js +++ b/browser_object.js @@ -281,12 +281,12 @@ let PLUGIN_INFO = xml` liberator.modules.mappings.addUserMap([liberator.modules.modes.NORMAL],
[prefix + motion.id + "/"], "Browser Object Mappings",
function (){
- liberator.modules.commandline.input("/",function(s){
+ liberator.modules.commandline.input(motion.id + "/",function(s){
var target = browserObject.targets.get("t");
var targetCollection = (function(ary){
var pattern;
if(XMigemoCore != undefined){
- pattern = new RegExp(XMigemoTextUtils.sanitize(s) + "|" + XMigemoCore.getRegExp(s),"i");
+ pattern = new RegExp(XMigemoService.textUtils.sanitize(s) + "|" + XMigemoCore.getRegExp(s),"i");
}else{
pattern = new RegExp(s,"i");
}
@@ -64,7 +64,8 @@ let INFO = xml` (function () { const Chaika = {}; Components.utils.import("resource://chaika-modules/ChaikaThread.js", Chaika); - Components.utils.import("resource://chaika-modules/Chaika2chViewer.js", Chaika); + // FIXME + // Components.utils.import("resource://chaika-modules/Chaika2chViewer.js", Chaika); function deleteCurrentThreadLog () { let currentURI = getBrowser().currentURI.QueryInterface(Ci.nsIURL); @@ -107,16 +108,17 @@ let INFO = xml` } } ), - new Command( - ['auth'], - 'Maru auth(?)', - function (args) { - Chaika.Chaika2chViewer.auth(); - }, - { - argCount: '0' - } - ), + // FIXME + // new Command( + // ['auth'], + // 'Maru auth(?)', + // function (args) { + // Chaika.Chaika2chViewer.auth(); + // }, + // { + // argCount: '0' + // } + // ), new Command( ['abonem[anager]'], 'Open abone manager', diff --git a/edit-vimperator-files.js b/edit-vimperator-files.js index e6cc6cb..27fc698 100644 --- a/edit-vimperator-files.js +++ b/edit-vimperator-files.js @@ -34,7 +34,7 @@ THE POSSIBILITY OF SUCH DAMAGE. // INFO {{{ let INFO = xml` - <plugin name="EditVimperatorFile" version="1.2.3" + <plugin name="EditVimperatorFile" version="1.3.0" href="http://github.com/vimpr/vimperator-plugins/blob/master/edit-vimperator-files.js" summary="Open vimperator files with text-editor." lang="en-US" @@ -49,7 +49,7 @@ let INFO = xml` <description><p></p></description> </item> </plugin> - <plugin name="EditVimperatorFile" version="1.2.3" + <plugin name="EditVimperatorFile" version="1.3.0" href="http://github.com/vimpr/vimperator-plugins/blob/master/edit-vimperator-files.js" summary="Vimperator 関連のファイルをエディタで開く" lang="ja" @@ -81,9 +81,10 @@ let INFO = xml` } let dirs = toArray(liberator.globalVariables.plugin_loader_roots || []).map(function (path) io.File(path).path); + let directoryName = liberator.globalVariables.edit_vimperator_files_directory_names || 'plugin colors styles style script'; // XXX dont remove first space - ' plugin colors styles style script'.split(/\s/).forEach( + (' ' + directoryName).split(/\s/).forEach( function (name) (dirs = dirs.concat(io.getRuntimeDirectories(name).map(function (file) file.path))) ); diff --git a/googleselect.js b/googleselect.js new file mode 100644 index 0000000..24c4eca --- /dev/null +++ b/googleselect.js @@ -0,0 +1,96 @@ + +// PLUGIN_INFO {{{ +let PLUGIN_INFO = xml` +<VimperatorPlugin> +<name>GoogleSelect</name> +<name lang="ja">グーグルセレクト</name> +<description>you can quick select in Google search result page</description> +<description lang="ja">Google検索結果からページ選択を楽にできる</description> +<version>1.0</version> +<author mail="hiro@elzup.com" homepage="blog.elzup.com">elzup</author> +<minVersion>1.0</minVersion> +<maxVersion>2.0pre</maxVersion> +<detail lang="ja"><![CDATA[ +]]></detail> +</VimperatorPlugin>`; +// }}} + +(function () { + var google_url = 'https:\/\/www.google.co.jp\/search.*'; + /* user config */ + // 選択状態表示マーカー + var SELECT_MARKER_CHAR = '▶'; + // マーカー位置微調整 + var SELECT_MARKER_REPOSITION_LEFT = '0em'; + var SELECT_MARKER_REPOSITION_TOP = '0.3em'; + + /* hard config */ + var GOOGLE_SELECTION_CLASS = 'r'; + var GOOGLE_SELECTION_SELECTED_CLASS = 'r-selected'; + + commands.addUserCommand( + ['googleselect'], + 'move select in google search result', + function (args) { + var v = 1; + if (args.length && args[0] == 'back') { + v = -1; + } + var $rs = window.content.window.document.getElementsByClassName(GOOGLE_SELECTION_CLASS); + var pre = -1; + for (var i = 0; i < $rs.length; i++) { + if ($rs[i].className.indexOf(GOOGLE_SELECTION_SELECTED_CLASS) != -1) { + pre = i; + break; + } + } + // ターゲット表示スタイル + var $pointer = window.content.window.document.createElement('span'); + $pointer.style.color = 'blue'; + $pointer.id = 'google-select-pointer'; + $pointer.style.position = 'absolute'; + $pointer.style.marginTop = SELECT_MARKER_REPOSITION_TOP; + $pointer.style.left = SELECT_MARKER_REPOSITION_LEFT; + $pointer.innerHTML = SELECT_MARKER_CHAR; + + if (pre != -1) { + // 現在の選択状態削除 + $rs[pre].className = GOOGLE_SELECTION_CLASS; +// $rs[pre].style.borderLeft = "none"; + $rs[pre].childNodes[0].blur(); + var $e = window.content.window.document.getElementById('google-select-pointer'); + $e.parentNode.removeChild($e); + } else if (v == -1) { + pre = $rs.length; + } + if ((pre == 0 && v == -1) || (pre == $rs.length - 1 && v == 1)) { + return; + } + +// $rs[pre + v].style.borderLeft = "solid 5px blue"; + $rs[pre + v].className = $rs[pre + v].className + " " + GOOGLE_SELECTION_SELECTED_CLASS; + $rs[pre + v].childNodes[0].focus(); + $rs[pre + v].parentNode.parentNode.insertBefore($pointer, $rs[pre + v].parentNode.parentNode.firstChild); + }, + { + literal: 0, + bang: true, + count: true, + argCount: '?', + options: [], + completer: function (context, args) { + context.title = ['value', 'description']; + context.completions = [ + ['front', 'move front item'], + ['back', 'move back item'] + ]; + } + }, + true // replace + ); + + +})(); + +// vim:sw=2 ts=2 et si fdm=marker: + diff --git a/microsoft-translator.js b/microsoft-translator.js index 5b412f8..44ae587 100644 --- a/microsoft-translator.js +++ b/microsoft-translator.js @@ -1,6 +1,6 @@ /* NEW BSD LICENSE {{{ Copyright (c) 2009-2010, anekos. -Copyright (c) 2012-2013, Jagua. +Copyright (c) 2012-2014, Jagua. All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -35,7 +35,7 @@ THE POSSIBILITY OF SUCH DAMAGE. // INFO {{{ let INFO = xml` -<plugin name="Microsoft Translator" version="1.0.1" +<plugin name="Microsoft Translator" version="1.1.0" href="http://github.com/vimpr/vimperator-plugins/blob/master/microsoft-translator.js" summary="Translate with Microsoft AJAX Language API" xmlns="http://vimperator.org/namespaces/liberator"> @@ -54,9 +54,9 @@ let INFO = xml` Translate!!!!!!!!!!! </p> <p> - You need to get an Access Token from http://www.bing.com/developers/appids.aspx - to use this plugin. and add liberator.globalVariables.mstrans_appid setting - to your ".vimperatorrc". + You need to get an Access Token from http://msdn.microsoft.com/en-us/library/hh454950.aspx + to use this plugin. and add g:microsoft_translator_client_id and + g:microsoft_translator_client_secret settings to your ".vimperatorrc". </p> <p>The following options are interpreted.</p> <dl> @@ -124,6 +124,15 @@ let INFO = xml` ['', 'Unknown'] ]; + const config = { + access_token: liberator.globalVariables.mstrans_appid || '', + expires: 0, + get client_id () + liberator.globalVariables.microsoft_translator_client_id, + get client_secret () + liberator.globalVariables.microsoft_translator_client_secret, + }; + const settings = { get pair () (liberator.globalVariables.microsoft_translator_pair || 'ja en').split(' '), @@ -131,52 +140,93 @@ let INFO = xml` (liberator.globalVariables.microsoft_translator_actions || 'echo').split(' ') }; - function guessRequest (appId, text, done) { - let url = - 'http://api.microsofttranslator.com/V2/Ajax.svc/Detect' + - '?appId=' + appId + - '&text=' + encodeURIComponent(text); - let req = - new plugins.libly.Request( - url, - { + function auth(config, text, opts, callback) { + if (config.client_secret == undefined || (new Date()).getTime() / 1000 < config.expires) { + callback(config, text, opts); + } else { + let url = 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13'; + let postBody = + 'client_id=' + encodeURIComponent(config.client_id) + + '&client_secret=' + encodeURIComponent(config.client_secret) + + '&scope=http://api.microsofttranslator.com' + + '&grant_type=client_credentials'; + let req = + new plugins.libly.Request( + url, + { Referrer: refererURL, + }, + { + postBody: postBody, + } + ); + req.addEventListener( + 'onSuccess', + function (res) { + let token = JSON.parse(res.responseText); + if (token.hasOwnProperty('expires_in') && token.expires_in.match(/^\d+$/)) { + config.expires = (new Date()).getTime() / 1000 + parseInt(token.expires_in, 10); + config.access_token = token.access_token; + callback(config, text, opts); + } } ); - req.addEventListener( - 'onSuccess', - function (res) { - var result = res.responseText; - done(result.substring(1,result.length-1)); - } - ); - req.get(); + req.post(); + } } - function translateRequest (appId, text, opts /* from, to, done */) { - opts || (opts = {}); - let url = - 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate' + - '?appId=' + appId + - '&text=' + encodeURIComponent(text) + - '&from=' + (opts.from || 'en') + '&to=' + (opts.to || 'ja') + - '&contentType=text/plain' ; - let req = - new plugins.libly.Request( - url, - { - Referrer: refererURL, + function guessRequest (config, text, opts /* from, to, done */) { + auth(config, text, opts, function (config, text, opts) { + let url = + 'http://api.microsofttranslator.com/V2/Ajax.svc/Detect' + + '?appId=' + (config.client_secret == undefined ? config.access_token : '') + + '&text=' + encodeURIComponent(text); + let req = + new plugins.libly.Request( + url, + { + Referrer: refererURL, + Authorization: 'Bearer ' + config.access_token, + } + ); + req.addEventListener( + 'onSuccess', + function (res) { + var result = res.responseText; + opts.done(result.substring(1,result.length-1)); } ); - req.addEventListener( - 'onSuccess', - function (res) { - let translated = res.responseText; - liberator.log('translated: ' + translated); - opts.done(translated); - } - ); - req.get(); + req.get(); + }); + } + + function translateRequest (config, text, opts /* from, to, done */) { + auth(config, text, opts, function (config, text, opts) { + opts || (opts = {}); + let url = + 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate' + + '?appId=' + (config.client_secret == undefined ? config.access_token : '') + + '&text=' + encodeURIComponent(text) + + '&from=' + (opts.from || 'en') + '&to=' + (opts.to || 'ja') + + '&contentType=text/plain'; + let req = + new plugins.libly.Request( + url, + { + Referrer: refererURL, + Authorization: 'Bearer ' + config.access_token, + } + ); + req.addEventListener( + 'onSuccess', + function (res) { + let translated = res.responseText; + liberator.log('translated: ' + translated); + opts.done(translated); + } + ); + req.get(); + }); } // 何語か妄想する @@ -239,13 +289,12 @@ let INFO = xml` ['mstrans'], 'Microsoft Translator', function (args) { - let appId = liberator.globalVariables.mstrans_appid; let text = args.literalArg; let actionNames = args['-action'] || settings.actions; let [from, to] = [args['-from'], args['-to']]; - if (appId == undefined) { - liberator.echoerr('The setting of liberator.globalVariables.mstrans_appid in .vimperatorrc is required.'); + if (config.client_id == undefined && config.client_secret == undefined && liberator.globalVariables.mstrans_appid == undefined) { + liberator.echoerr('The setting of g:microsoft_translator_client_(id|secret) in .vimperatorrc is required.'); return false; } @@ -254,9 +303,11 @@ let INFO = xml` if (args['-guess']) { guessRequest( - appId, + config, text, - function (lang) [liberator.echo("<p>"+v+"</p>",liberator.commandline.FORCE_MULTILINE) for ([, [k, v]] in Iterator(languages)) if (k == lang)] + { + done: function (lang) [liberator.echo("<p>"+v+"</p>",commandline.FORCE_MULTILINE) for ([, [k, v]] in Iterator(languages)) if (k == lang)] + } ); return; } @@ -275,7 +326,7 @@ let INFO = xml` function req () { translateRequest( - appId, + config, text, { done: function (text) actionNames.forEach(function (name) actions[name](text)), @@ -290,15 +341,17 @@ let INFO = xml` req(); } else { guessRequest( - appId, + config, text, - function (fromLang) { - from = fromLang; - liberator.log('lang: ' + fromLang); - setPair(); - if (args['-to']) - to = args['-to']; - req(); + { + done: function (fromLang) { + from = fromLang; + liberator.log('lang: ' + fromLang); + setPair(); + if (args['-to']) + to = args['-to']; + req(); + }, } ); } @@ -212,22 +212,13 @@ commands.addUserCommand( // }}} // {{{ save single image file - let getImageUrl=function(pageContents){ - let url; - let htmldoc=getDOMHtmlDocument(pageContents); - if(htmldoc){ - if(0<htmldoc.getElementsByTagName('img').length) - url=htmldoc.getElementsByTagName('img').item(0).getAttribute('src'); - else - url=''; - }else{ - url=pageContents.match(/http:\/\/img[0-9]{2}\.pixiv\.net\/img\/[0-9a-z_]+\/[0-9]+\.jpg|http:\/\/img[0-9]{2}\.pixiv\.net\/img\/[0-9a-z_]+\/[0-9]+\.png/i); - } + let getImageUrl=function(pContents){ + let url = pContents.getElementsByClassName("_layout-thumbnail _illust_modal")[0].childNodes.item( 1 ).getAttribute( "data-src" ); return url; }; let saveImageFile=function(){ - let imgUrl=getImageUrl(xhrImgInfo.responseText); + let imgUrl=getImageUrl(contents); if(0<imgUrl.length){ let destPath=getDestPath(imgUrl); if(destPath==null){ @@ -278,9 +269,7 @@ commands.addUserCommand( // {{{ trueImgINfo let trueImgInfo=function(){ - if(-1!=type.search(/big&illust_id=/i)){ - saveImageFile(); - }else if(-1!=type.search(/manga&illust_id=/i)){ + if(-1!=type.search(/manga&illust_id=/i)){ saveMangaFiles(); }else{ liberator.echoerr("This page is not image page and not manga page."); @@ -301,16 +290,20 @@ commands.addUserCommand( done : function (aResult) { if ( aResult == fp.returnOK ) { saveDirectory = fp.file; - xhrImgInfo = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] - .createInstance(); - xhrImgInfo.QueryInterface( Ci.nsIDOMEventTarget ); - xhrImgInfo.addEventListener( "load", trueImgInfo, false ); - xhrImgInfo.addEventListener( "error", falseImgInfo, false ); - xhrImgInfo.QueryInterface( Ci.nsIXMLHttpRequest ); - xhrImgInfo.open( "GET", url, true); - xhrImgInfo.setRequestHeader( 'Referer', contents.URL ); - xhrImgInfo.setRequestHeader( 'Cookie', cookie ); - xhrImgInfo.send( null ); + if ( url == null ) { + saveImageFile(); + } else { + xhrImgInfo = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] + .createInstance(); + xhrImgInfo.QueryInterface( Ci.nsIDOMEventTarget ); + xhrImgInfo.addEventListener( "load", trueImgInfo, false ); + xhrImgInfo.addEventListener( "error", falseImgInfo, false ); + xhrImgInfo.QueryInterface( Ci.nsIXMLHttpRequest ); + xhrImgInfo.open( "GET", url, true); + xhrImgInfo.setRequestHeader( 'Referer', contents.URL ); + xhrImgInfo.setRequestHeader( 'Cookie', cookie ); + xhrImgInfo.send( null ); + } } } }; @@ -318,9 +311,9 @@ commands.addUserCommand( type = contents.getElementsByClassName('works_display') .item(0).firstChild.getAttribute('href'); - if(-1!=type.search(/big&illust_id=/i)){ - url=contents.documentURI.replace('medium','big'); - }else if(-1!=type.search(/manga&illust_id=/i)){ + if( type == null ){ // single iamge + url=null; + }else if(-1!=type.search(/manga&illust_id=/i)){ // plural image url=contents.documentURI.replace('medium','manga')+'&type=scroll'; }else{ liberator.echoerr("This page is not image page and not manga page."); diff --git a/twittperator.js b/twittperator.js index 609a36a..215750f 100644 --- a/twittperator.js +++ b/twittperator.js @@ -1253,7 +1253,7 @@ let INFO = xml` callback(d.responseText); } }else{ - callback(d.statusText); + throw d.statusText || d.toString(); } }, }; @@ -1286,7 +1286,7 @@ let INFO = xml` } } else { // typeof d == object - callback(d); + throw d.statusText || d.toString(); } } }; @@ -1315,7 +1315,7 @@ let INFO = xml` callback(d.responseText); } }else{ - callback(d.statusText); + throw d.statusText; } }, }; @@ -1636,7 +1636,7 @@ let INFO = xml` }; // }}} let Twitter = { // {{{ destroy: function(id) { // {{{ - tw.jsonDelete("statuses/destroy/" + id, null, function(res) { + tw.jsonPost("statuses/destroy/" + id, null, function(res) { res = Utils.fixStatusObject(res); Twittperator.echo("delete: " + res.user.name + " " + res.text) }); diff --git a/zip-de-download.js b/zip-de-download.js index 3de7ddb..8f74636 100644 --- a/zip-de-download.js +++ b/zip-de-download.js @@ -186,7 +186,7 @@ let SITE_INFO = [ } function getXPathFromExtensions(exts){ function getXPath(elem){ - if (!elem) + if (!elem || !elem.getAttribute) return ''; // 連番かもしれない id は無視する diff --git a/zoom-em-all.js b/zoom-em-all.js index 177cc6a..864a33e 100644 --- a/zoom-em-all.js +++ b/zoom-em-all.js @@ -1,5 +1,5 @@ /* NEW BSD LICENSE {{{ -Copyright (c) 2010, anekos. +Copyright (c) anekos. All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -39,7 +39,7 @@ let PLUGIN_INFO = xml` <name lang="ja">Zoom Em All</name> <description>Zoom them all.</description> <description lang="ja">ブラウザ全体をズーム</description> - <version>1.1.0</version> + <version>1.1.1</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> @@ -56,7 +56,7 @@ let PLUGIN_INFO = xml` // }}} // INFO {{{ let INFO = xml` - <plugin name="ZoomEmAll" version="1.1.0" + <plugin name="ZoomEmAll" version="1.1.1" href="http://github.com/vimpr/vimperator-plugins/blob/master/zoom-em-all.js" summary="Zoom or pan for whole firefox." lang="en-US" @@ -75,7 +75,7 @@ let INFO = xml` </description> </item> </plugin> - <plugin name="ZoomEmAll" version="1.1.0" + <plugin name="ZoomEmAll" version="1.1.1" href="http://github.com/vimpr/vimperator-plugins/blob/master/zoom-em-all.js" summary="ブラウザ全体をズーム" lang="ja" @@ -104,7 +104,7 @@ let INFO = xml` getInterface(Ci.nsIWebNavigation). QueryInterface(Ci.nsIDocShell). contentViewer. - QueryInterface(Ci.nsIMarkupDocumentViewer); + QueryInterface(Ci.nsIMarkupDocumentViewer || Ci.nsIContentViewer); __context__.__defineGetter__('fullZoom', function () docViewer.fullZoom); __context__.__defineSetter__('fullZoom', function (v) docViewer.fullZoom = v); |