Changeset 29671

Show
Ignore:
Timestamp:
02/07/09 13:00:49 (4 years ago)
Author:
anekos
Message:

add some keywords.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/copy.js

    r29550 r29671  
    44<description>enable to copy strings from a template (like CopyURL+)</description> 
    55<description lang="ja">テンプレートから文字列のコピーを可能にします(CopyURL+みたいなもの)</description> 
    6 <minVersion>2.0</minVersion> 
     6<minVersion>2.0pre</minVersion> 
    77<maxVersion>2.0pre</maxVersion> 
    88<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/copy.js</updateURL> 
    99<author mail="teramako@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/teramako/">teramako</author> 
    1010<license>MPL 1.1/GPL 2.0/LGPL 2.1</license> 
    11 <version>0.6</version> 
     11<version>0.7</version> 
    1212<detail><![CDATA[ 
    1313== Command == 
     
    3434%HTMLSEL%: 
    3535    to the html string of selection 
     36%HOSTNAME%: 
     37    to the hostname of the current location 
     38%PATHNAME%: 
     39    to the pathname of the current location 
     40%HOST%: 
     41    to the host of the current location 
     42%PORT%: 
     43    to the port of the current location 
     44%PROTOCOL%: 
     45    to the protocol of the current location 
     46%SEARCH%: 
     47    to the search(?..) of the current location 
     48%HASH%: 
     49    to the hash(anchor #..) of the current location 
    3650 
    3751== How to create template == 
     
    114128}); 
    115129 
     130const REPLACE_TABLE = { 
     131    get TITLE () buffer.title, 
     132    get URL () buffer.URL, 
     133    get SEL () { 
     134        if (sel) 
     135            return sel; 
     136        else if (selection.rangeCount < 1) 
     137            return ''; 
     138 
     139        for (var i=0, c=selection.rangeCount; i<c; i++){ 
     140            sel += selection.getRangeAt(i).toString(); 
     141        } 
     142        return sel; 
     143    }, 
     144    get HTMLSEL () { 
     145        if (htmlsel) 
     146            return sel; 
     147        else if (selection.rangeCount < 1) 
     148            return ''; 
     149 
     150        var serializer = new XMLSerializer(); 
     151        for (var i=0, c=selection.rangeCount; i<c; i++){ 
     152            htmlsel += serializer.serializeToString(selection.getRangeAt(i).cloneContents()); 
     153        } 
     154        return htmlsel; 
     155    } 
     156}; 
     157'hostname pathname host port protocol search hash'.split(' ').forEach(function (name){ 
     158    REPLACE_TABLE[name.toUpperCase()] = function () content.location && content.location[name]; 
     159}); 
     160 
    116161// used when argument is none 
    117162//const defaultValue = templates[0].label; 
     
    157202    var sel = '', htmlsel = ''; 
    158203    var selection =  win.getSelection(); 
    159     function replacer(value){ //{{{ 
    160         switch(value){ 
    161             case '%TITLE%': 
    162                 return buffer.title; 
    163             case '%URL%': 
    164                 return buffer.URL; 
    165             case '%SEL%': 
    166                 if (sel) 
    167                     return sel; 
    168                 else if (selection.rangeCount < 1) 
    169                     return ''; 
    170  
    171                 for (var i=0, c=selection.rangeCount; i<c; i++){ 
    172                     sel += selection.getRangeAt(i).toString(); 
    173                 } 
    174                 return sel; 
    175             case '%HTMLSEL%': 
    176                 if (htmlsel) 
    177                     return sel; 
    178                 else if (selection.rangeCount < 1) 
    179                     return ''; 
    180  
    181                 var serializer = new XMLSerializer(); 
    182                 for (var i=0, c=selection.rangeCount; i<c; i++){ 
    183                     htmlsel += serializer.serializeToString(selection.getRangeAt(i).cloneContents()); 
    184                 } 
    185                 return htmlsel; 
    186         } 
    187         return ''; 
     204    function replacer(orig, name){ //{{{ 
     205        if (name == '') 
     206            return '%'; 
     207        if (!REPLACE_TABLE.hasOwnProperty(name)) 
     208            return orig; 
     209        let value = REPLACE_TABLE[name]; 
     210        if (typeof value == 'function') 
     211            return value(); 
     212        else 
     213            return value.toString(); 
     214        return orig; 
    188215    } //}}} 
    189     return str.replace(/%(TITLE|URL|SEL|HTMLSEL)%/g, replacer); 
     216    return str.replace(/%([A-Z]*)%/g, replacer); 
    190217} 
    191218