From 41d88a510a2949c9aaae31ea1ab82e1710cb173b Mon Sep 17 00:00:00 2001 From: drry Date: Tue, 8 Apr 2008 15:27:31 +0000 Subject: lang/javascript/vimperator-plugins/trunk/encodingSwitcher.js: * 間違えてしまった [8307] を直しました。ごめんなさい。 * ほか、インデントなど。 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@9153 d0d07461-0603-4401-acd4-de1884942a52 --- encodingSwitcher.js | 226 ++++++++++++++++++++++++---------------------------- 1 file changed, 106 insertions(+), 120 deletions(-) (limited to 'encodingSwitcher.js') diff --git a/encodingSwitcher.js b/encodingSwitcher.js index 2518998..f4014bd 100644 --- a/encodingSwitcher.js +++ b/encodingSwitcher.js @@ -1,5 +1,5 @@ /** - * encodingSwithcer (vimperator plugin) + * encodingSwithcer (Vimperator plugin) * @author teramako teramako@gmail.com * @version 0.1 * @@ -36,147 +36,133 @@ CreateMenu('browser'); CreateMenu('more-menu'); var allEnum = cm.GetAllResources(); while (allEnum.hasMoreElements()){ - var res = allEnum.getNext().QueryInterface(Ci.nsIRDFResource); - var value = res.Value; - if (RDFCU.IsContainer(cm, res) || value.indexOf('charset.') == 0 || value.indexOf('----') == 0) { - continue; - } - var label = sbCharTitle.GetStringFromName(value.toLowerCase() + '.title'); - if (res.Value.indexOf('chardet.') == 0){ - value = value.substr('chardet.'.length); - var buf = createDetector(value); - buf[1] = label; - detectors.push(buf); - } else { - encodings.push([value,label]); - } + var res = allEnum.getNext().QueryInterface(Ci.nsIRDFResource); + var value = res.Value; + if (RDFCU.IsContainer(cm, res) || value.indexOf('charset.') == 0 || value.indexOf('----') == 0) { + continue; + } + var label = sbCharTitle.GetStringFromName(value.toLowerCase() + '.title'); + if (res.Value.indexOf('chardet.') == 0){ + value = value.substr('chardet.'.length); + var buf = createDetector(value); + buf[1] = label; + detectors.push(buf); + } else { + encodings.push([value,label]); + } } function createDetector(name){ - var i = name.indexOf('_'); - if ( i > 0 ){ - return [name.substr(0,i),null,name.substr(i)]; - } - return [name,null,'']; + var i = name.indexOf('_'); + if (i > 0){ + return [name.substr(0,i),null,name.substr(i)]; + } + return [name,null,'']; } function getDetector(name){ - detectors.forEach(function(detector){ - if (detector[0].toLowerCase() == name.toLowerCase()){ - return detector[0] + detector[2]; - } - }); + for (let i = 0, l = detectors.length; i < l; i++){ + if (detectors[i][0].toLowerCase() == name.toLowerCase()){ + return detectors[i][0] + detectors[i][2]; + } + } } function getEncoding(name){ - encodings.forEach(function(encoding){ - if (encoding[0].toLowerCase() == name.toLowerCase()){ - return encoding[0]; - } - }); -} -function isValid(array, value){ - return array.some(function(v){ - return v[0].toLowerCase() == value.toLowerCase(); - }); + for (let i = 0, l = encodings.length; i < l; i++){ + if (encodings[i][0].toLowerCase() == name.toLowerCase()){ + return encodings[i][0]; + } + } } +function isValid(array, value) array.some(function(v) + v[0].toLowerCase() == value.toLowerCase()); function completion(array, filter){ - if (!filter) return array; - filter = filter.toLowerCase(); - return array.filter(function(v){ - return v[0].toLowerCase().indexOf(filter) == 0; - }); + if (!filter) return array; + filter = filter.toLowerCase(); + return array.filter(function(v) + v[0].toLowerCase().indexOf(filter) == 0); } var sbCharDefault = sbService.createBundle(gPrefService.getDefaultBranch('intl.charset.').getCharPref('default')); const DEFAULT_CHARSET = sbCharDefault.GetStringFromName('intl.charset.default'); liberator.options.add(['fileencoding','fenc'],'set the charactor encoding for the current page','string', DEFAULT_CHARSET, - { - setter: function(value){ - if (!value) return; - value = getEncoding(value); - SetForcedCharset(value); - //SetDefaultCharacterSet(value); - BrowserSetForcedCharacterSet(value); - }, - getter: function(){ - return getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset; - }, - validator: function(value){ - return isValid( encodings, value); - }, - completer: function(filter){ - return [0,completion( encodings, filter)]; - } - } - + { + setter: function(value){ + if (!value) return; + value = getEncoding(value); + SetForcedCharset(value); + //SetDefaultCharacterSet(value); + BrowserSetForcedCharacterSet(value); + }, + getter: function() + getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset, + validator: function(value) + isValid( encodings, value), + completer: function(filter) + [0,completion( encodings, filter)] + } ); var sbCharDetector = sbService.createBundle(gPrefService.getDefaultBranch('intl.charset.').getCharPref('detector')); const DEFAULT_DETECTOR = createDetector(sbCharDetector.GetStringFromName('intl.charset.detector'))[0]; liberator.options.add(['autodetector','audet'],'set auto detect character encoding','string',DEFAULT_DETECTOR, - { - setter: function(value){ - SetForcedDetector(true); - var pref = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch); - var str = Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString); - if (!value || value == 'off') { - str.data = ''; - } else { - str.data = value = getDetector(value); - } - pref.setComplexValue('intl.charset.detector',Ci.nsISupportsString, str); - BrowserSetForcedCharacterSet(value); - }, - getter: function(){ - var elms = document.getElementById('charsetMenu').getElementsByAttribute('checed','true'); - for (var i=0; i'); - list.forEach(function(i){ - if (reg.test(i[0]) || reg.test(i[1])){ - str.push(''); - if (current == i[0]){ - str.push('' + i[0] + '' + i[1] + ''); - } else { - str.push('' + i[0] + '' + i[1] + ''); - } - str.push(''); - } - }); - str.push(''); - liberator.echo( str.join(''), true); + if (!arg) arg = '.'; + var reg = new RegExp(arg,'i'); + var str = []; + str.push(''); + list.forEach(function(i){ + if (!reg.test(i[0]) && !reg.test(i[1])) return; + str.push(''); + if (current == i[0]){ + str.push(''); + } else { + str.push(''); + } + str.push(''); + }); + str.push('
' + i[0] + '' + i[1] + '' + i[0] + '' + i[1] + '
'); + liberator.echo( str.join(''), true); } liberator.commands.addUserCommand(['listencoding','lsenc'],'list all encodings', - function(arg){ - listCharset(arg, liberator.options.fileencoding, encodings); - },{ - completer: function(filter){ - return [0,completion(encodings, filter)]; - } - } + function(arg){ + listCharset(arg, liberator.options.fileencoding, encodings); + },{ + completer: function(filter) + [0,completion(encodings, filter)] + } ); liberator.commands.addUserCommand(['listdetector','lsdet'],'list all auto detectors', - function(arg){ - listCharset(arg, liberator.options.autodetector, detectors); - },{ - completer: function(filter){ - return [0,completion(detectors, filter)]; - } - } + function(arg){ + listCharset(arg, liberator.options.autodetector, detectors); + },{ + completer: function(filter) + [0,completion(detectors, filter)] + } ); })(); -- cgit v1.2.3