// ==UserScript== // @name Fast look up JP and EN // @namespace http://d.hatena.ne.jp/jimo1001/ // @description Fast look up Japanese and English character strings. // @include * // ==/UserScript== var VERSION = "2009.03.16"; var SITEINFO_IMPORT_URLS = [ 'http://wedata.net/databases/FluJE/items.json', ]; //----------------------------------------------------------------------------- // SPACE ALC(英辞郎 on the WEB)はコメントを外せば利用できますが、『英辞郎 on the Web』の利用規約に違反しますので自己責任で行ってください. //----------------------------------------------------------------------------- var LOCAL_SITEINFO = [ // { // name: 'SPACE ALC(英辞郎)', // url: 'http://eow.alc.co.jp/[context]/', // icon: 'data:image/gif;base64,R0lGODlhEAAQALMAABQSFI+Qj8/Pz1FRUbGxsefp53Nzc6KjouDf4GNkY769vvz+/ICCgCQmJJmYmVxaXCH5BAAAAAAALAAAAAAQABAAAwRocElZThqGzC1Pe4cgOE/ALUx2IJtjbASzEIPCObL0SuyZSAHBiUM4oIYcRFCzKfQmhQDhYTAkEg+AI7l9ChJCjsI2YTAKw62EAEYW1IgBEhheOBLoJOMpUTwYBCIHDGpDAgcBDgp5ExEAOw==', // xpath: '(id("searchWord")/strong | id("itemsNumber") | id("resultList")//ul//li[position()<4])', // NGxpath: 'id("resultArea")//ul/div/ul', // lang: 'both', // type: 'dictionary', // enc: 'UTF-8' // }, ] var SITEINFO = []; //=== Default settings === var DefaultSettings = function() { var s = { ver: VERSION, shortcutkey: { navi_toggle: 'A-y', // show toggle(open/close) navi close_all: 'ESC', // close all element QL_run: 'y', // Run quick Look up site: [], }, remove_result_all: true, enable_wheel_button: true, enable_modifier_key: true, // push modifier key when select character strings. modifier_key: 'altKey', // modifier key for selection. effect : true, lookup: { // word, search ja: [], // default site of input japanese strings en: [], // default site of input english strings ja_type: 'dictionary', en_type: 'dictionary', }, translation: { // for select text JtoE: true, // translate Japanese to English ja_chars: '10', // translate Japanese more than this number of characters EtoJ: true, // translate English to Japanese en_words: '3', // translate Enlish more than this number of words ja: [], en: [], } } return s; } //=== images === var IMAGES = { close: 'data:image/png;base64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UjObdwyWJKkgjcDCo2/CqyGgGVzcFGbXsfDfhQhIOcea/KoUgPtjSiaGNl6+UgmZYV8LbREVUDos8ibANH0uZ5kHMPUBc4JXCpSKgL562CpC5kPRJBgHEROBMhA88K2ZzNZQJVud4pPtQD0k5aAYIITqSv0KxKyplKlVjIHS1WbV3WehibfKEgGdkpvTV28J5QVXjvERG8cyTVvrea5ZKUM16VBGzbnXVF0kv8wxbLdW3fvQ6Dfnys1cDzvT2AeZhOJnPg5RM//PMXp6cfZNZKu1WM2pTsOqErzk5ZKfpVrc2SqdaYgisTawXc7MNvgLAPzawN0nuCqqIr/KCiuz7uYpLFNUMy7mkDZuuz6jJzRUz3/A2zW5Vjf/O/vf/2r9of0FcAZ6gVKMEAAAAASUVORK5CYII=', maximize: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABsAAAAXCAYAAAD6FjQuAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAewQAAHsEBw2lUUwAAAAd0SU1FB9gBFxEUA2hUPdwAAAECSURBVEjH7ZU9boQwEIU/ByRL29ClS2txhDRcALmhSscRqSwuQJErcIFcARrMbBEiWbBIoKyp9klT2J4fv3n+UYDkeU5s9H1PCjDPMwAiAoBS6mFAuC4iG79HcyFSgGmauAIpgPf++mLrNoUtLctyN0nbtrvxYY6ntPFo/IbZelchmqbZHJCqqjYyrFn9jU8x29P2FLNxHA857/kdjU/PaFPX9b+0VYDcbrfox34Yhl9mSZJcc8+01pcU01qDMUYA0VoLEMW01mKMEQVQFMU38BmTWdd1KgXIsuwL8M65n+hv40J3tta+Ax6YFvPA5Jx7yrfwZq39WJLOKwv7/sIL8XEHfSOYLUXK0YIAAAAASUVORK5CYII=', maximize_focused: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABsAAAAXCAYAAAD6FjQuAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAAewQAAHsEBw2lUUwAAA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FxEWDMrdQs8AAAFGSURBVEjH7ZQ9bsJAEIW/RYu2oqRxQxFxBxrfwBdAuZHvEeUCvgENN6DxBRAFINvsrlxsCrTYsbHJ30aKlFd5Zt/MmzcaWcRx7DabDWmakuc5obBcLpE+sNZircU5B4AQ4m5R+9051+PdywEYYxoxrTVa62DOtNaN2OVywRgTTKyqqkasqiqMMb01dVfaXtPQGrv1PbGiKIKusSzLRux0Ot2cdafy6Lptc4cceu7xeHwvFtLZ+XxuxPb7PUVRDJIPh8Nos/l8Pvo+m82Y+KCua0KiruvGmZSS6XQ6SI6iaLTZWK3vL9vkob/GT+AmppS6BlIigNsdee3eYYpOUtwhtXPXbwlsF4vFarfboZTCWhvEmVIKEcfxE5ADW2AV8kjEC/CaJACss2yU7HlfQZZlyGcgedDs0RAfxST5xrSfwW/p/OMP4w3tcqDExRHCHwAAAABJRU5ErkJggg==', openSwitch: 'data:image/gif;base64,R0lGODlhEAAQAJECAP///6uopv///wAAACH5BAEAAAIALAAAAAAQABAAAAIbVI6Zpu0PIwRAImoPjrT353nSZpFjlaWqxbAFADs=', closeSwitch: 'data:image/gif;base64,R0lGODlhEAAQAJECAP///6uopv///wAAACH5BAEAAAIALAAAAAAQABAAAAIWVI6Zpu0Po5y0JoAzflrbD4aixUxCAQA7', o: 'data:image/gif;base64,R0lGODlhEAAQAIABANLS0////yH5BAEAAAEALAAAAAAQABAAAAIcjI+py+2PgARvznZDVjLS1R0hF26kVZnQyrZQAQA7', x: 'data:image/gif;base64,R0lGODlhEAAQAIABAJ+foP///yH5BAEAAAEALAAAAAAQABAAAAIdjI+py+1vAECSyRluu9px+HkctnSdUh0pxLYuVAAAOw==', indicator: 'data:image/gif;base64,R0lGODlhEAAQAPYAAAAAAAEBAQICAgMDAwQEBAgICA0NDRMTEx4eHiAgICIiIiQkJCgoKCkpKSoqKisrKzAwMDExMTU1NTs7Oz4+Pl1dXWpqamtra3FxcZSUlJiYmJmZmZubm5ycnJ2dnaKioqOjo6ioqKmpqaurq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6NfEUsnSLWZBEotVEgEqTlkLi5ROKkMK9JPN6kCRmNQQ68AAjg3AeKJgQAh+QQBCgAAACwAAAAAEAAQAAAHZoAAgoOEhYaHiIYCCwmJhA8fHI2OABAhHwuUAAQQDQGagg4XE5+OBh4qJQqUBh2pq44FEhakjhQjIBGICGUYDCIrKxsDhgYnLi4oJsEZAoYOLcgsFRoZDIcHKcgpBwLEiBMkJBOGgQAh+QQBCgAAACwAAAAAEAAQAAAHaIAAgoOEhYaHiImKi4yNjoMGPDSNQidHL4yVl4IDDDmYhTE7kwABRlRVSgSDNUVAMoM4US4uLDs6OwREKk0+gzdPtCtLTk9DQSpMPYRDUFJJJSsrIzY+PTCEATc4BEhTU0mMMz8/M4aBACH5BAEKAAAALAAAAAAQABAAAAdmgACCg4SFhoeIiYqLjIM0DzKMWCleJwiLXS6aGJiaLpyKk1UoV4wHWSdcFIQEEA8CgwMaKytcVgYGABAhHwuDAhm0HxIeHg0MHxwJhAwZWxBaKioWAAvLhQMEABMmJhOMAgoKsIWBACH5BAEKAAAALAAAAAAQABAAAAdqgACCg4SFgwE3OAKGhkNQY0aLjII3Ty4uKwyTgjhRl2Q5mwAESFRVSgSbYEgnSxFfoj9jK2IQogCyK04Rt2BJJEOwtwBhQUQ1wz5NKkTDPUwqQDBCQgaTMD0+MTtdXTvDNEdHNMMALy+MgQA7' } //----------------------------------------------------------------------------- // 設定ここまで //----------------------------------------------------------------------------- var SETTINGS = ''; var FluJE = { resultList: [], resultCloseFlag: false, selectionFlag: true, //=== remove result calame === removeResult: function (e) { var navi = $('FluJE_navi'); var selection = window.getSelection().toString(); if(selection!="" || !FluJE.resultCloseFlag) return; if(navi && navi.style.display!='none') return; if(SETTINGS.remove_result_all){ if(FluJE.resultList.length){ FluJE.resultList.forEach(function (c_node){ document.body.removeChild(c_node); }); FluJE.resultList = []; FluJE.resultCloseFlag = false; } }else{ var result = FluJE.resultList[FluJE.resultList.length-1]; if(result){ document.body.removeChild(result); FluJE.resultList.pop(); } } }, //=== All close (remove result calame and close navi calame) === allRemove: function(){ var navi = $('FluJE_navi'); var qlookup = $('FluJE_quick_lookup'); if(qlookup){ qlookup.style.display = 'none'; qlookup.style.opacity = 0; } if(navi){ navi.style.display = 'none'; navi.style.opacity = 0; } if(FluJE.resultList.length){ FluJE.resultList.forEach( function (e){ document.body.removeChild(e); }); FluJE.resultList = []; } }, //=== Mouseup Event (selection) === selectionEvent: function(evt, ids, force){ var self = FluJE; var selection = window.getSelection().toString(); if(!selection || !FluJE.selectionFlag) return; FluJE.resultCloseFlag = false; setTimeout(function(){ FluJE.resultCloseFlag = true }, 100); if(!force) { if(SETTINGS.enable_modifier_key){ if(!(evt[SETTINGS.modifier_key]) || evt.button != 0 ) return; }else{ if(evt[SETTINGS.modifier_key] || evt.button != 0) return; else if(selection) setTimeout(function(){ return; }, 100); } } if(ids && ids.length) FluJE.showResult(selection, self.autoSelector(selection, ids)); else FluJE.showResult(selection, self.autoSelector(selection)); window.getSelection().removeAllRanges(); }, //=== select site(s) automatic === autoSelector: function(str, ids){ var ids_ja = [], ids_en = [], type = "", lang = ""; if(ids && ids.length){ ids.forEach(function(val){ if(checkInputLang(val, 'ja')) ids_ja.push(val); if(checkInputLang(val, 'en')) ids_en.push(val); }); }else ids = [] str = str.replace(/^\s+|\s+$/g, ""); if(!str.match(/^[\S]+\s.*$/i)){ var re = new RegExp("[^a-z0-9]{"+SETTINGS.translation.ja_chars+",}", "i"); if(/^\s*$|[^a-z\s]/i.test(str)){ lang = "ja"; if(SETTINGS.lookup.ja_type=='search') type = 'lookup'; else if(re.test(str) && SETTINGS.translation.JtoE) type = 'translation' else type = 'lookup' }else { lang = 'en'; type='lookup'; } }else { lang = 'en' if(SETTINGS.lookup.en_type=='search') type = 'lookup' else if((str.match(/\s/mg).length >= SETTINGS.translation.en_words-1) && SETTINGS.translation.EtoJ) type = 'translation' else type = 'lookup' } if(ids.length){ if(lang == 'ja') return ids_ja; else if (lang == 'en') return ids_en; else return; } if(SETTINGS[type][lang] && SETTINGS[type][lang].length) return SETTINGS[type][lang]; }, //----------------------------------------------------------------------------- // output result gotten from keyword //----------------------------------------------------------------------------- //=== show results === loaded: false, initCSS: function(){ var cls1 = 'div.FluJE_result', cls2 = cls1+' div.FluJE_result_area', cls3 = cls2+' div.FluJE_result_article'; var inherit = 'background: inherit; background-image: inherit; background-color: inherit; color: inherit; text-align: inherit; font-size: inherit; font-style: inherit; font-weight: inherit; margin: inherit; text-decoration: inherit; border: 0px; height: auto; padding: 0; font-family: inherit; vertical-align: inherit; line-height: inherit; font-stretch: inherit; font-variant: inherit; font-size-adjust: inherit; letter-spacing: inherit;'; var css = [ cls1,'{ font-size: 14px; position: fixed; margin: 0; padding: 0; bottom: 0; left: 0; right: 0; max-height: 50%; overflow: auto; vertical-align: baseline; border: 0; border-collapse: separate; text-align: left; text-indent: 0; text-decoration: none; color: #FFF; font-family: sans-serif; font-weight: normal; font-style: normal; font-size: medium; font-stretch: normal; font-variant: normal; font-size-adjust: none; letter-spacing: normal; background: none; background-color: #000; background-image: none; -moz-border-radius: 3px; opacity: 0.8; z-index: 1000; }\n', cls1,' > div{',inherit,' min-height: 22px; }\n', cls1,' img.FluJE_switch_img{ position: absolute; cursor: pointer; top: 1px; right: 1px; margin: 3px 2px 0 5px; width: 16px; height: 16px; z-index: 3000; }\n', cls2,'{ position: relative; overflow: auto; z-index: 1500; }\n', cls3,'{ position: relative; -moz-border-radius: 3px; color: #FFF; background-color: #111; margin: 5px; padding: 3px 0 0 30px; z-index: 1000; min-height: 22px; }\n', cls3,' span.indicator{ ',inherit,' position: absolute; top: 0; color: #FFF; left: 40px; width: 200px; height: 18px; padding-left: 30px; background-image: url(',IMAGES.indicator,'); background-repeat: no-repeat; z-index: 3000; }\n', cls3,' *{',inherit,' background-color: #111; margin: 0; padding: 0; color: #FFFFFF; font-size: 14px; }\n', cls3,' h1, ',cls3,' h2{ width: 100%; max-width: 100%; font-size: 110%; height: auto; font-weight: bold; color: #9FF; }\n', cls3,' h1 *, ',cls3,' h2 *{ width: 100%; max-width: 100%; font-size: 110%; height: auto; font-weight: bold; color: #9FF; }\n', cls3,' h3, ',cls3,' h4, ',cls3,' h5, ',cls3,' h6{ width: 100%; max-width: 100%; height: auto; color: #9F9; font-size: 95%; font-weight:100%; }\n', cls3,' h3 *, ',cls3,' h4 *, ',cls3,' h5 *, ',cls3,' h6 *{ width: 100%; max-width: 100%; height: auto; color: #9F9; font-size: 95%; font-weight:100%; }\n', cls3,' strong, ',cls3,' em{ color: #F99; font-size: 105%; font-weight: bold; }\n', cls3,' strong *, ',cls3,' em *{ color: #F99; font-size: 105%; font-weight: bold; }\n', cls3,' tr td{ padding: 7px; }\n', cls3,' a{ color: #FF9; text-decoration: none; }\n', cls3,' a:hover{ color: #FF9; text-decoration: underline; }\n', cls3,' img{ display: none; }\n', cls3,' a.FluJE_permalink{ position: absolute; padding: 0; margin: 0; top: 0px; left: 2px; text-decoration: none; width: 0; height: 0; color: none; border:0; background-color: none; }\n', cls3,' img.FluJE_site_icon{ position: absolute; -moz-border-radius: 3px; top: 0px; left: 2px; width: 16px; height: 16px; padding: 1px; background-color: #FFF; display: inline; }\n', cls3,' span.FluJE_msg{ padding-left: 10px; color: #999; }\n', cls3,' span.FluJE_error_msg{ padding-left: 10px; color: #999; }\n', 'div#FluJE_flash_msg{ position: fixed; bottom: 0; left: 0; right: 0; color: #9F9; font-weight: normal; font-size: 90%; text-align: center; background-color: #000; padding: 5px 0; margin: 0; opacity: 0.8; }\n', 'div#FluJE_flash_error_msg{ position: fixed; bottom: 0; left: 0; right: 0; color: #F99; font-weight: bold; font-size: 120%; text-align: center; background-color: #000; padding: 5px 0; margin: 0; opacity: 0.8; }\n' ].join(''); return css; }, showMessage: function(str, param){ var self = FluJE; if(!str) return; if(!self.loaded) loadStyle(self.loaded, self.initCSS()); if(param == "error") var msg = document.body.appendChild($N('div', {id:'FluJE_flash_error_msg', style:'display: none'}, str)); else var msg = document.body.appendChild($N('div', {id:'FluJE_flash_msg', style:'display: none'}, str)); Effect.flash(msg); return; }, showResult: function(str, items){ var self = FluJE; if(!str) return; if(loadStyle(self.loaded, self.initCSS(), function(){ self.showResult(str, items); })){ self.loaded = true; return; } if(!items){ var items = self.autoSelector(str); if(!items){ var msg = document.body.appendChild($N('div', {id:'FluJE_flash_error_msg', style:'display: none'}, '!!! Plese select one or more sites. !!!')); Effect.flash(msg); return; } } var root = document.body.appendChild($N('div', {class:'FluJE_result'})); ResultNavi.init(root, str); self.resultList.push(root); root.addEventListener('click', function(evt) { evt.stopPropagation(); var tag_name = evt.target.nodeName; if(tag_name=='IMG' || tag_name=='A' || !self.resultCloseFlag || window.getSelection().toString()!="") return; document.body.removeChild(root); self.resultList.pop(); }, false); var result_elems = [], indicator = [], permalinks = []; var indicator_img = $N('span', {class:'indicator', style:'display: inline'}, 'Now Loading...'); items.forEach(function (num, index){ indicator.push(indicator_img.cloneNode(true)); var site_icon = $N('img', {class:'FluJE_site_icon', src: getIcon(num), title: SITEINFO[num].name}); permalinks.push($N('a', {class:'FluJE_permalink', target: '_blank'}, [site_icon])); result_elems.push($N('div',{class:'FluJE_result_article'}, [permalinks[index], indicator[index]])); }); var area = root.appendChild($N('div', {class:'FluJE_result_area'}, result_elems)); self.getResults(str, items, function(results, index, hash){ if(hash){ var num = hash.num; var url = hash.url; } permalinks[index].setAttribute('href', url); indicator[index].style.display = 'none'; results.forEach(function (e){ e = document.importNode(e, true); result_elems[index].appendChild(e); }); self.resultCloseFlag = true; }); }, createElements: function(req, sites, url, index, num, func) { var info = sites[num]; var r = req.responseText.replace(//img, ''); var reqdom = convertToHTMLDocument(r); var tmp = []; var results = []; tmp = $X(info.xpath, reqdom); if(tmp!='' && (info.NGxpath==null || (info.NGxpath && $X(info.NGxpath, reqdom)==''))){ if(info.type=='dictionary' || info.type=='search'){ tmp.forEach(function(result) { var links = $X(".//a", result); links.forEach(function(link){ if(link.getAttribute("href") && link.getAttribute("href").charAt(0) != "#"){ if(link.getAttribute("href").toLowerCase().indexOf("http") != 0){ if(info.link){ link.setAttribute("href",info.link+link.getAttribute("href").replace(new RegExp('[0-9a-z/.+-]*/', 'i') ,"")); }else{ link.setAttribute("href", url.match(new RegExp('http://[0-9a-z/.+-]+/', 'i')) +link.getAttribute("href").replace(new RegExp('[0-9a-z/.+-]*/') ,"")); } } link.setAttribute("target","_blank"); }else if(link.hasChildNodes()){ link.removeAttribute('href'); } }); results.push(result); }); }else if(info.type=='translation'){ tmp.forEach(function(result){ results.push(result); }); } }else{ results.push($N('span', {class: 'FluJE_error_msg'}, 'Not Found')); } func(results, index, {num:num, url:url}); }, //=== get results === /* func::argument (1st:Results(Array), 2nd:Site Number, 3rd: Result URL) */ getResults: function(str, items, func){ var sites = SITEINFO; if(!items) return; items.forEach(function (e, index){ var data = '', method = 'GET', url = ''; if(sites[e].enc && (sites[e].lang=='ja' || sites[e].lang=='both')){ var cs = EscapeEncoding(sites[e].enc, str); }else{ var cs = str.replace(/’/mg, "\'").replace(/,/mg, ','); } if(sites[e].type=='dictionary'){ url = sites[e].url.replace(/\[context\]/, cs); }else if(sites[e].type=='search'){ cs = cs.replace(/\s/mg, sites[e].space); url = sites[e].url.replace(/\[context\]/, cs); }else if(sites[e].type=='translation'){ if(sites[e].method=='POST'){ method = 'POST'; url = sites[e].url; if(sites[e].lang == 'ja'){ data = sites[e].data.replace(/\[context\]/, cs); }else if(sites[e].lang == 'en'){ data = sites[e].data.replace(/\[context\]/, cs.replace(/\s/mg, sites[e].space)); } }else{ cs = cs.replace(/\s/mg, sites[e].space); url = sites[e].url.replace(/\[context\]/, cs); } } GM_xmlhttpRequest({ overrideMimeType:"text/html; charset="+sites[e].enc, method: method, url: url, headers: { 'User-agent': 'Mozilla/5.0 (compatible)', 'Accept': 'application/atom+xml,application/xml,text/xml', }, data: data, onerror: function(){ func([$N('span', {class: 'FluJE_error_msg'}, 'ERROR')], e, url); return; }, onload: function(res) { FluJE.createElements(res, sites, url, index, e, func); } }); }); }, getSiteInfo : function() { var a = []; var cache = eval(GM_getValue("cacheInfo")); if(!cache) { this.importSiteInfo(); return ; } a = a.concat(LOCAL_SITEINFO); SITEINFO_IMPORT_URLS.forEach(function(i) { a = a.concat(cache[i].info); }); a.forEach(function(val,index){ a[index].id = index; }); return a; }, importSiteInfo: function(){ if (document.getElementById('FluJE_navi')){ var node = document.getElementById('FluJE_navi'); node.parentNode.removeChild(node); } SITEINFO_IMPORT_URLS.forEach(function(i) { var opt = { method: 'get', url: i, onload: function(res) { FluJE.showMessage("import site info."); return FluJE.getCacheCallback(res, i); }, onerror: function(res){ FluJE.showMessage("import error.", "error"); }, } GM_xmlhttpRequest(opt); }) }, getCacheCallback: function(res, url) { if (res.status != 200) { return getCacheErrorCallback(url); } var info = null; try { info = eval(res.responseText).map(function(i) { return i.data }) } catch(e) { info = [] var matched = false var hdoc = convertToHTMLDocument(res.responseText) var textareas = $X('.//*[@class="FluJE_data"]', hdoc) textareas.forEach(function(textarea) { var d = parseInfo(textarea.value) if (d) { info.push(d) if (!matched && location.href.match(d.url)) { matched = d } } }) } if (info.length > 0) { cacheInfo = {} cacheInfo[url] = { url: url, expire: new Date(new Date().getTime()), info: info } GM_setValue('cacheInfo', cacheInfo.toSource()) SITEINFO = this.getSiteInfo(); }else { this.getCacheErrorCallback(url) } }, getCacheErrorCallback: function(url) { var expire = new Date(new Date().getTime()) var chacheInfo = {} if (cacheInfo[url]) { cacheInfo[url].expire = expire } else { cacheInfo[url] = { url: url, expire: expire, info: [] } } GM_setValue('cacheInfo', cacheInfo.toSource()) }, //=== window onLoad === onLoad: function(){ //== GM_getValue == Setting.load(); SITEINFO = FluJE.getSiteInfo(); //== Userscript command == GM_registerMenuCommand('Fast look up JP and EN - reset setting', function(){Setting.reset()}); //== Event == ShortcutKey.add(window, SETTINGS.shortcutkey.navi_toggle, Navi.toggle); ShortcutKey.add(window, SETTINGS.shortcutkey.close_all, FluJE.allRemove, true); ShortcutKey.add(window, SETTINGS.shortcutkey.QL_run, QLu.run); if(SETTINGS.shortcutkey.site.length){ var keys = []; if(SETTINGS.shortcutkey.site.length) { SETTINGS.shortcutkey.site.forEach(function(v,i){ var match = false; keys.forEach(function(key, idx){ if(key.shortcutkey == v.shortcutkey) { keys[idx].id.push(v.id); match = true; } }); if(!match) keys.push({shortcutkey:v.shortcutkey, id:[v.id]}); }); } if(keys.length) { keys.forEach(function(key, idx){ ShortcutKey.add(window, key.shortcutkey, function(evt){ FluJE.selectionEvent(evt, key.id, true); }, false); }); } } window.addEventListener("mouseup", FluJE.selectionEvent, true); window.addEventListener('click', FluJE.removeResult, false); GM_registerMenuCommand('Fast look up JP and EN - import siteinfo', function(){ FluJE.importSiteInfo(); }); if(SETTINGS.enable_wheel_button) { window.addEventListener('click', function(e){ if(e.button==1) FluJE.selectionEvent(e, false, true); }, false); } }, } //----------------------------------------------------------------------------- // EFFECT //----------------------------------------------------------------------------- var Effect = { flag: true, flash: function(node){ var self = this; this.fadeio(node); setTimeout(function(){ self.fadeio(node, null, true); }, 2000); }, highlight: function(node, bool){ if(bool){ node.style.backgroundColor = '#CFC'; setTimeout(function(){ node.style.backgroundColor='#FFF'; }, 500); }else{ node.style.backgroundColor = '#F99'; setTimeout(function(){ node.style.backgroundColor='#FFF'; }, 500); } }, smoothsize: function(node, original, fixed) { var self = this; if(original > fixed) { node.offsetHeight -= 5; orininal -= 5; setTimeout(function(){ self.smoothsize(node, original, fixed); }, 20); } return; }, fadeio: function(node, func, rm, sw, count){ var self = this; if(!sw){ if(!this.flag) return; if(!node.style.opacity) node.style.opacity = 0; if(node.style.display=='none') node.style.display = 'block'; if(parseFloat(node.style.opacity) > 0.5) { sw = 'out', count = 8, this.flag = false; }else{ sw = 'in', count = 0, this.flag = false; } } if(!SETTINGS.effect){ if(sw=='in') { node.style.opacity = 0.8; this.flag = true; }else { node.style.opacity = 0; node.style.display = 'none'; this.flag = true; } if(func) setTimeout(func, 10); return; } if(sw == 'in'){ if(count <= 8){ node.style.opacity = count/10; count++; setTimeout(function(){ self.fadeio(node, func, rm, sw, count); }, 20); }else{ if(func) func(); this.flag = true; return; } }else if(sw == 'out'){ if(count >= 0){ node.style.opacity = count/10; count--; setTimeout(function(){ self.fadeio(node, func, rm, sw, count); }, 20); }else{ if(func) func(); if(rm) node.parentNode.removeChild(node); else node.style.display = 'none'; this.flag = true; return; } } } } //----------------------------------------------------------------------------- // Navigation //----------------------------------------------------------------------------- var Navi = { loaded: false, initCSS: function() { var id1 = 'div#FluJE_navi', id2 = id1+' div#FluJE_navi_container', cls1 = id2+' table.FluJE_navi_table', cls2_1 = cls1+' .FluJE_site_num_ja', cls2_2 = cls1+' .FluJE_site_num_en', id3 = id2+' div#FluJE_navi_setting'; var inherit = 'background:inherit; background-image:inherit; background-color:inherit; color:inherit; text-align:inherit; font-size:inherit; font-style:inherit; font-weight:inherit; margin:inherit; text-decoration:inherit; border:0px; font-family:inherit; vertical-align:inherit; line-height:inherit; font-stretch:inherit; font-variant:inherit; font-size-adjust:inherit; letter-spacing:inherit;'; var css = [ id1,'{ position: fixed; margin: 0; padding: 28px 10px 20px 5px; top: 10px; left: 10px; width: 400px; height: 400px; max-height: 100%; vertical-align: baseline; border: 0; border-collapse: separate; text-align: left; text-indent: 0; text-decoration: none; color: #FFF; font-family: sans-serif; font-weight: normal; font-style: normal; font-size: 9pt; font-stretch: normal; font-variant: normal; font-size-adjust: none; letter-spacing: normal; background: none; background-color: #000; background-image: none; -moz-border-radius: 10px; opacity:0.8; z-index:1000; }\n', id1,' div#FluJE_navi_title{ ',inherit,' position: absolute; top: 3px; left: 10px; }\n', id1,' div#FluJE_navi_title span{ ',inherit,' font-size: 10pt; color: #999; font-weight: bold; }\n', id1,' div#FluJE_navi_title span#FluJE_navi_version{ ',inherit,' font-size: 90%; margin-left: 10px; color: #666; font-weight: normal; }\n', id1,' .FluJE_navi_button{ position: absolute; cursor: pointer; width: 27px; height: 23px; }\n', id1,' div#FluJE_navi_minimize_button{ top: 5px; right: 64px; background: url(',IMAGES.minimize,') no-repeat; }\n', id1,' div#FluJE_navi_minimize_button:hover{ background: url(',IMAGES.minimize_focused,') no-repeat; }\n', id1,' div#FluJE_navi_maximize_button{ top: 5px; right: 37px; background: url(',IMAGES.maximize,') no-repeat; }\n', id1,' div#FluJE_navi_maximize_button:hover{ background: url(',IMAGES.maximize_focused,') no-repeat; }\n', id1,' div#FluJE_navi_close_button{ top: 5px; right: 10px; background: url(',IMAGES.close,') no-repeat; }\n', id1,' div#FluJE_navi_close_button:hover{ background: url(',IMAGES.close_focused,') no-repeat; }\n', id1,' span.FluJE_navi_title{ ',inherit,' color: #FFF; font-weight: bold; margin-top: 5px; }\n', id2,'{ ',inherit,' position: static; top: 25px; height: 100%; max-height: 100%; width: 99%; padding: 5px; max-height: auto; overflow-y: auto; overflow-x: hidden; vertical-align: middle; border-top: 1px dashed #666; border-bottom: 1px dashed #666; }\n', id2,' div.FluJE_navi_table_area{ ',inherit,' width: 98%; padding: 5px 3px; margin-bottom: 10px; border: 1px solid #666; }\n', id2,' div.FluJE_navi_reset{ ',inherit,' float: right; border: 1px solid #999; background-color: #333; color: #F33; cursor: pointer; padding: 0 3px; }\n', cls1,'{ ',inherit,' width: 100%; border: 0; margin: 0; vertical-align: middle; border-collapse: separate; border-spacing: 2px; }\n', cls1,' tbody{ ',inherit,' width: 100%; margin: 0; vertical-align: middle; }\n', cls1,' tr, ',cls1,' td{ ',inherit,' font-size: 95%; background-color: #000; padding: 3px; margin: 0; }\n', cls1,' tr *, ',cls1,' td *{ ',inherit,' background-color: #000; }\n', cls1,' tr td input, ',cls1,' select{ background-color: #FFF; color: #000; height: 20px; width: 220px; float: right; }\n', cls1,' tr td input.FluJE_navi_site_sc{ background-color: #FFF; color: green; text-align: center; font-weight: bold; height: 20px; width: 50px; float: right; }\n', cls1,' tr td input:hover, ',id2,' tr td select:hover{ ',inherit,' color: #000; background-color: #FFF; -moz-outline: 2px solid -moz-rgba(16,96,146,0.8); -moz-outline-offset: 1px; -moz-outline-radius: 3px; }\n', cls1,' tr td input[type=\"text\"]:focus, ',id2,' tr td select:focus{ ',inherit,' color: #000; background-color: #FFF; -moz-outline: 2px solid -moz-rgba(16,186,224,0.8); -moz-outline-offset: 1px; -moz-outline-radius: 3px; }\n', cls1,' th { ',inherit,' font-weight: bold; }\n', cls1,' span{ color: #FFF; background-color: inherit; border: 0px; font-size: 9.5pt; float: left; }\n', cls1,' span.FluJE_navi_site_name{ display: none; }\n', cls1,' .FluJE_site_number{ font-size: 10pt; font-weight: bold; text-align: center; width: 16px; height: 16px; background-color: inherit; display: block; }\n', cls1,' td.FluJE_site_num_ja[state=enable]:hover{ -moz-outline: 1px solid -moz-rgba(16,96,146,0.8); -moz-outline-offset: 1px; -moz-outline-radius: 3px; background-color: #006; }\n', cls1,' td.FluJE_site_num_en[state=enable]:hover{ -moz-outline: 1px solid -moz-rgba(146,96,16,0.8); -moz-outline-offset: 1px; -moz-outline-radius: 3px; background-color: #600; }\n', cls1,' img.FluJE_navi_icon{ padding: 1px; width: 16px; height: 16px; -moz-border-radius: 3px; background-color: #FFF; margin-right: 5px; float: left; }\n', cls1,' th{ ',inherit,' text-align: center; color: #CCC; font-weight: normal; padding: 0px; }\n', cls1,' th.Flu_navi_setting_title{ ',inherit,' color: #999; font-weight: bold; font-size: 10pt; }\n', cls2_1,'{ background-color: #003; width: 16px; text-align: center; vertical-align: middle; cursor: pointer; }\n', cls2_2,'{ background-color: #300; width: 16px; text-align: center; vertical-align: middle; cursor: pointer; }\n', id3,' input[type=text]{ width: 75px; float: left; padding-left: 3px; }\n', id3,' input[type=checkbox]{ width: auto; float: left; }\n', id3,' select{ margin: 0; padding: 0; background-color: #FFF; color: #000; width: auto; float: left; }\n', id3,' select option{ background-color: #FFF; color: #000;}\n' ].join(''); return css; }, //=== create dictionary search translation table === createMainHTML: function() { var html_dict = "", html_search = "", html_trans = "", html_setting = ""; html_dict += "
reset
Dictionary" + "" + ""; html_search += "Search" + "
JaEnIconSearch formShortcut
"; html_trans += "
reset
Translation" + "
"; var item_length = SITEINFO.length; for(var i=0; i 0){ SETTINGS.shortcutkey.site.forEach(function(val,idx){ if(val.id == i) key = val.shortcutkey; }); } var sort = (type == 'translation') ? 'translation' : 'lookup'; html+="" + "" + "" + "" + ""; if(type == 'dictionary') html_dict += html; else if(type=='search') html_search += html; else if(type=='translation') html_trans += html; } html_dict += "
"+SiteNumElement.get(i, 'ja', 'html')+""+SiteNumElement.get(i, 'en', 'html')+""+site_name+"
"; html_search += "
"; html_trans += ""; return html_dict + html_search + html_trans; }, //=== crate setting table === createSettingHTML: function() { var html = "
reset
Setting" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
表示中の結果を全消去
修飾キーを有効
修飾キー
エフェクトを有効
[ Translation ]
日英翻訳を有効
辞書引き上限文字数 (Push ENTER)
英日翻訳を有効
辞書引き上限単語数 (Push ENTER)
[ Shortcut Key ](要リロード)
Naviの表示/非表示
すべて閉じる
Quick Lookup
"; return html; }, getHTML: function() { var html = "
Fast look up JP and ENver."+VERSION+"
" + "
" + "
" + "
" + "
" + Navi.createMainHTML() + "
" + this.createSettingHTML() + "
"; return html; }, //=== Navi Event === events: function(evt, navi) { var self = this; var tnode = evt.target; var container = $('FluJE_navi_container'); switch(tnode.getAttribute('evt')) { case 'close': { Effect.fadeio(navi); evt.stopPropagation(); break; } case 'minimize': { if(container.style.display != 'none') { container.style.display='none'; navi.style.width = null; navi.style.height = 'auto'; navi.style.bottom = null; break; }else { container.style.display='block'; navi.style.width = null navi.style.height = null; navi.style.bottom = null; break; } } case 'maximize': { var show_site_name = function(disp) { var max_width = 0; $X(".//span[@class='FluJE_navi_site_name']", container).forEach(function(node){ if(disp=='block') { node.style.display="block"; if(max_width < node.offsetWidth) { max_width = (node.offsetWidth*(node.offsetHeight/20)+50) } node.parentNode.style.width = max_width; }else { node.style.display="none"; node.parentNode.style.width=null } }); } if(container.style.display=='none') container.style.display = 'block'; if(navi.style.bottom != '10px') { show_site_name("block"); navi.style.width = 'auto'; navi.style.height = 'auto'; navi.style.bottom = '10px'; }else{ show_site_name("none"); navi.style.height = null; navi.style.width = null; navi.style.bottom = null; } break; } case 'lookup': { if(tnode.getAttribute('added_event')=='true') return; tnode.setAttribute('added_event', true); ShortcutKey.add(tnode, 'RET', function(evt) { FluJE.showResult(tnode.value, [parseInt(tnode.name, 10)]); evt.stopPropagation(); }, false); break; } case 'chenge_site_num': { var modifier_key = evt[SETTINGS.modifier_key]; if(tnode.getAttribute('alt') == 'site_number'){ SiteNumElement.check(tnode, container, modifier_key); break; }else if(tnode.parentNode.getAttribute('alt') == 'site_number'){ SiteNumElement.check(tnode.parentNode, container, modifier_key); break; }else break; } case 'reset_lookup': { SETTINGS.lookup.ja = [], SETTINGS.lookup.en = []; SiteNumElement.replace($X('.//td[@class="FluJE_site_num_ja"][@sort="lookup"]', container), {lang:'ja', sort:'lookup'}); SiteNumElement.replace($X('.//td[@class="FluJE_site_num_en"][@sort="lookup"]', container), {lang:'en', sort:'lookup'}); Setting.save(); break; } case 'reset_translation': { SETTINGS.translation.ja = [], SETTINGS.translation.en = []; SiteNumElement.replace($X('.//td[@class="FluJE_site_num_ja"][@sort="translation"]', container), {lang:'ja', sort:'translation'}); SiteNumElement.replace($X('.//td[@class="FluJE_site_num_en"][@sort="translation"]', container), {lang:'en', sort:'translation'}); Setting.save(); break; } case 'reset_setting': { Setting.reset([['remove_result_all'],['enable_modifier_key'],['modifier_key'],['effect'],['translation','JtoE'],['translation','ja_chars'],['translation','EtoJ'],['translation','en_words'],['shortcutkey']]); $('FluJE_navi_setting').innerHTML = this.createSettingHTML(); break; } case 'remove_result_all': { Setting.set('remove_result_all', tnode.checked); break; } case 'enable_modifier_key': { Setting.set('enable_modifier_key', tnode.checked); break; } case 'modifier_key': { if(tnode.getAttribute('added_event')=='true') return; tnode.setAttribute('added_event', true); tnode.addEventListener('keyup',function(evt){ var key = ''; if(evt.shiftKey || evt.keyCode==16) key = 'shiftKey'; if(evt.ctrlKey || evt.keyCode==17) key = 'ctrlKey'; if(evt.altKey || evt.keyCode==18) key = 'altKey'; if(evt.metaKey || evt.keyCode==224) key = 'metaKey'; tnode.value = key; if(key){ Effect.highlight(tnode, true); Setting.set('modifier_key', key); }else{ Effect.highlight(tnode, false); setTimeout(function(){ tnode.value = SETTINGS.modifier_key; }, 500); } evt.stopPropagation(); }, false); break; } case 'check_effect': { Setting.set('effect', tnode.checked); break; } case 'Ja_to_En': { Setting.set(['translation','JtoE'], tnode.checked); break; } case 'Ja_char': { if(tnode.getAttribute('added_event')=='true') return; tnode.setAttribute('added_event', true); ShortcutKey.add(tnode, 'RET', function(e) { if(isNaN(tnode.value)){ Effect.highlight(tnode, false); }else{ Effect.highlight(tnode, true); Setting.set(['translation','ja_chars'], parseInt(e.target.value, 10)); } }, false); break; } case 'En_to_Ja': { Setting.set(['translation','EtoJ'], tnode.checked); break; } case 'En_word': { if(tnode.getAttribute('added_event')=='true') return; tnode.setAttribute('added_event', true); ShortcutKey.add(tnode, 'RET', function(e) { if(isNaN(tnode.value)){ Effect.highlight(tnode, false); }else{ Effect.highlight(tnode, true); Setting.set(['translation','en_words'], parseInt(e.target.value, 10)); } }, false); break; } case 'navi_toggle': { ShortcutKey.set(tnode, 'navi_toggle'); break; } case 'close_all': { ShortcutKey.set(tnode, 'close_all'); break; } case 'QL_run': { ShortcutKey.set(tnode, 'QL_run'); break; } case 'shortcut': { var index = null, _s = SETTINGS.shortcutkey; var id = tnode.getAttribute('site_id'); if(!_s.site){ SETTINGS.shortcutkey.site = []; }else{ _s.site.forEach(function(val,i){ if(val.id == id) index = i; }); } if(index == null){ _s.site.push({id:parseInt(id)}); index = _s.site.length - 1; } ShortcutKey.set(tnode, 'site', index); break; } default: break; } }, //=== show toggle (open/close) Navi === toggle: function(){ var self = Navi; var navi = $('FluJE_navi'); if(navi){ if(navi.style.display != 'none'){ Effect.fadeio(navi); return; }else{ Effect.fadeio(navi); return; } }else{ if(loadStyle(self.loaded, self.initCSS(), self.toggle)){ self.loaded = true; return; } var navi = document.body.appendChild($N('div', {id:'FluJE_navi'})); navi.innerHTML = self.getHTML(); Effect.fadeio(navi); //== Navi Event Listener == navi.addEventListener('keyup', function(evt){ self.events(evt, navi); }, false); navi.addEventListener('click', function(evt){ self.events(evt, navi); }, false); } } } //----------------------------------------------------------------------------- // Navigation at result area. //----------------------------------------------------------------------------- var ResultNavi = { loaded: false, initCSS: function(){ var cls1 = 'div.FluJE_result div.FluJE_result_navi', cls2 = cls1+' div.FluJE_result_navi_area', cls3_1 = cls2+' td.FluJE_site_num_ja', cls3_2 = cls2+' td.FluJE_site_num_en'; var inherit = 'background: inherit; background-image: inherit; background-color: inherit; color: inherit; text-align: inherit; font-size: inherit; font-style: inherit; font-weight: inherit; margin: inherit; text-decoration: inherit; border: 0px; height: auto; padding: 0; font-family: inherit; vertical-align: inherit; line-height: inherit; font-stretch: inherit; font-variant: inherit; font-size-adjust: inherit; letter-spacing: inherit;'; var css = [ cls1,'{ background: #333; background-image: none; background-color: #333; color: #FFF; text-align: inherit; font-size: 16px; font-style: normal; font-weight: normal; margin: 0; text-decoration: none; border: 0px; font-family: inherit; vertical-align: middle; line-height: 100%; font-stretch: normal; font-variant: normal; font-size-adjust: none; letter-spacing: normal; height: auto; max-height: 70px; padding: 1px 30px 1px 0; }\n', cls1,' *{ ',inherit,' padding: 0; }\n', cls2,'{ padding-top:5px; }\n', cls2,' div{ height: 18px; }\n', cls2,' td{ padding: 0 2px; }\n', cls2,' img.FluJE_site_icon{ -moz-border-radius: 3px; cursor: pointer; background-color: #FFF; padding: 1px; margin: 0; width: 16px; height: 16px; }\n', cls2,' span.FluJE_site_number{ text-align: center; color: #FFF; font-weight: bold; font-size: 14px; }\n', cls2,' table{ vertical-align: middle; border-collapse: separate; border-spacing: 2px; }\n', cls3_1,'{ cursor: pointer; width: 18px; height: 18px; text-align: center; background-color: #335; }\n', cls3_2,'{ cursor: pointer; width: 18px; height: 18px; text-align: center; background-color: #533; }\n', cls3_1,'[state=enable]:hover{ -moz-outline: 1px solid -moz-rgba(16,96,146,0.8); -moz-outline-offset: 1px; -moz-outline-radius: 3px; }\n', cls3_2,'[state=enable]:hover{ -moz-outline: 1px solid -moz-rgba(146,96,16,0.8); -moz-outline-offset: 1px; -moz-outline-radius: 3px; }\n' ].join(''); return css; }, createHTML: function(){ var html_icon = "", html_ja = "", html_en = ""; SITEINFO.forEach(function(e, num){ var type = SITEINFO[num].type, lang = SITEINFO[num].lang, id = SITEINFO[num].id; var sort = (type == 'translation') ? 'translation' : 'lookup'; html_icon += ""; html_ja += ""; html_en += ""; }); html_icon += ""; html_ja += ""; html_en += "
Lang
Ja
En"+SiteNumElement.get(num, 'ja', 'html')+""+SiteNumElement.get(num, 'en', 'html')+"
"; return html_icon+html_ja+html_en; }, init: function(pNode, str){ var self = ResultNavi; var root = ''; var oicon = pNode.appendChild($N('img', {class:'FluJE_switch_img', src:IMAGES.openSwitch, style:'display: inline;'})); var cicon = pNode.appendChild($N('img', {class:'FluJE_switch_img', src:IMAGES.closeSwitch, style:'display: none;'})); oicon.addEventListener('click', function(e){ oicon.style.display = 'none'; cicon.style.display = 'inline'; if(!root){ if(loadStyle(self.loaded, self.initCSS(), function(){ root = self.show(pNode, str); })){ self.loaded = true; return; }else{ root = self.show(pNode, str); } }else if(root.style.display == 'none'){ root.style.display='block'; }else{ return; } }, false); cicon.addEventListener('click', function(evt){ oicon.style.display = 'inline'; cicon.style.display = 'none'; root.style.display = 'none'; FluJE.resultCloseFlag = true; }, false); }, show: function(pNode, str){ var root = $N('div', {class: 'FluJE_result_navi'}); var area = root.appendChild($N('div', {class:'FluJE_result_navi_area', style:'display: block; float: right;'})); area.innerHTML = this.createHTML(); area.addEventListener('click', function(evt){ var tnode = evt.target; switch(tnode.getAttribute('evt')){ case 'chenge_site_num': { if(tnode.getAttribute('alt') == 'site_number'){ SiteNumElement.check(tnode, area); evt.stopPropagation(); break; }else if(tnode.parentNode.getAttribute('alt') == 'site_number'){ SiteNumElement.check(tnode.parentNode, area); evt.stopPropagation(); break; }else break; } case 'relookup': { FluJE.showResult(str, [parseInt(tnode.name, 10)]); break; } default: break; } }, false); root.appendChild($N('div', {style:'clear:both !important;'})); pNode.insertBefore(root, pNode.firstChild); return root; } } //----------------------------------------------------------------------------- // Quick Lookup //----------------------------------------------------------------------------- var QLu = { loaded: false, initCSS: function() { var id1 = 'div#FluJE_quick_lookup', id2 = id1+' input#FluJE_quick_lookup_input'; var inherit = 'background: inherit; background-image: inherit; background-color: inherit; color: inherit; text-align: inherit; font-size: inherit; font-style: inherit; font-weight: inherit; margin: inherit; text-decoration: inherit; border: 0px; height: auto; padding: 0; font-family: inherit; vertical-align: inherit; line-height: inherit; font-stretch: inherit; font-variant: inherit; font-size-adjust: inherit; letter-spacing: inherit;'; var css = [ id1,'{ background: #000; background-image: none; background-color: #000; color: #FFF; text-align: center; font-size: 15px; font-style: normal; font-weight: normal; margin: 0; text-decoration: none; border: 0px; padding: 0; font-family: inherit; vertical-align: middle; line-height: 100%; font-stretch: normal; font-variant: normal; font-size-adjust: none; letter-spacing: normal; z-index: 10000; height: 40px; position: fixed; left: 10px; right: 10px; bottom: 51%; padding-top: 20px; opacity: 0; -moz-border-radius: 10px; }\n', id1,' span{ ',inherit,' margin-right: 10px; font-weight: bold; }\n', id2,'{ ',inherit,' padding-left: 3px; padding-top: 2px; height: 20px; width: 85%; background-color: #FFF; color: #333; text-align: left; }\n' ].join(''); return css; }, close: function(elm) { $('FluJE_quick_lookup_input').blur(); Effect.fadeio(elm); }, createNode: function(){ var self = this; var title = $N('span', null, 'Quick Lookup:'); var input = $N('input', {id:'FluJE_quick_lookup_input'}); var div = document.body.appendChild($N('div', {id:'FluJE_quick_lookup'}, [title, input])); //== Event == div.addEventListener('click', function(e){ if(e.target != input) self.close(div); }, false); input.addEventListener('focus', function(){ input.style.backgroundColor = "#FFFFFF"; },false); input.addEventListener('blur', function(){ input.style.backgroundColor = "#CCCCCC"; },false); ShortcutKey.add(input, 'RET', function(evt){ switch(evt.target.value){ case 'exit': { self.close(div); return; } case '': { FluJE.removeResult(); break;} default: FluJE.removeResult(); break; } FluJE.showResult(input.value); }); return div; }, run: function() { var self = QLu; if($('FluJE_quick_lookup')){ Effect.fadeio($('FluJE_quick_lookup'), function(){ $('FluJE_quick_lookup_input').select(); }); return; } if(loadStyle(self.loaded, self.initCSS(), self.run)){ self.loaded = true; return; } var div = self.createNode(); Effect.fadeio(div, function(){ $('FluJE_quick_lookup_input').select(); }); } } //----------------------------------------------------------------------------- // SETTING CONTROL //----------------------------------------------------------------------------- var Setting = { _default: DefaultSettings(), save: function() { GM_setValue('settings', SETTINGS.toSource()); }, load: function(){ try { var s = eval(GM_getValue('settings')); if(s.ver && s.ver == VERSION){ SETTINGS = s; return 1; } } catch(e) {} Setting.reset(); SETTINGS = this._default; this.save(); return 0; }, reset: function(args){ switch(typeof args){ case 'object': { for(var i in args){ var type = typeof args[i]; if(type == 'object'){ this.set(args[i], "default", false); }else if(type == 'string'){ this.set(args, "default", false); break; }else { break; } } break; } case 'string': { this.set(args, "default", false); break; } case 'undefined': { this.set(); break; } default: break; } this.save(); }, set: function(name, value, bool){ var d = this._default; switch(typeof name){ case 'object': { if(name.length <= 2){ if(value=='default') (name.length===1) ? value = d[name[0]] : value = d[name[0]][name[1]]; (name.length===1) ? SETTINGS[name[0]] = value : SETTINGS[name[0]][name[1]] = value; }else { var str = ""; for(var n in name) str += "[\'"+name[n]+"\']"; if(value=="default") value = eval("Setting._default" + str); str = "SETTINGS" + str; str += (typeof value == 'string') ? "=\'"+value.toString()+"\'" : "="+value.toString(); eval(str); } break; } case 'string': { SETTINGS[name] = value; break; } case 'undefined': { SETTINGS = this._default; break; } default: break; } if(bool!=false){ this.save(); } }, setSite: function(lang, num, param, modifier_key){ var n = null; var sites = SITEINFO; var t = sites[num].type; var s = (t == 'dictionary' || t == 'search') ? 'lookup' : 'translation'; if (!SETTINGS[s]) SETTINGS = Setting._default; n = SETTINGS[s]; var lookup_type = (lang=='ja') ? 'ja_type' : 'en_type'; if(param){ if(modifier_key) n[lang].unshift(num); else n[lang].push(num); if(t=='dictionary'){ if(!n[lookup_type]) n[lookup_type] = t; }else if(t=='search'){ n[lookup_type] = t; } }else{ n[lang] = this.delArray(n[lang], num); if(t == 'search'){ var ck_search = false; for(var i in n[lang]){ if(sites[i].type == 'search'){ ck_search = true; break; } n[lookup_type] = (ck_search) ? 'search' : 'dictionary'; } } } this.save(); }, delArray: function(array, num){ var a = 0, b = null; array.forEach(function(e){ if(e==num){ b = a; } a++; }); var array_new = new Array(); array_new = array.slice(0,b); for(var i = b;i"+(i+1).toString()+""; else return $N('span', {class:'FluJE_site_number', title:SITEINFO[num].name, name: num, param: 'true', state:'enable', evt: 'chenge_site_num' }, (i+1).toString()); } } if(checkInputLang(num, lang)){ if(format=='html') return ""; else return $N('img', {class:'FluJE_site_number', title:SITEINFO[num].name, name: num, param: 'false', state:'enable', evt: 'chenge_site_num', src:IMAGES.o}); } if(format=='html') return ""; else return $N('img', {class:'FluJE_site_number', title:SITEINFO[num].name, name: num, param: 'false', state:'disable', evt: 'chenge_site_num', src:IMAGES.x}); }, replace: function(list, args, self, modifier_key) { var lang = args.lang, sort = args.sort; if(self){ var elm = self.firstChild; if(elm.getAttribute('state')=='disable') return; Setting.setSite(lang, parseInt(elm.getAttribute('name'), 10), !eval(elm.getAttribute('param')), modifier_key); } var num = list.length; for(var i=0; i>6|192).toString(16)+"%"+(c&63|128).toString(16):"%"+(c>>12|224).toString(16)+"%"+(c>>6&63|128).toString(16)+"%"+(c&63|128).toString(16)).toUpperCase() }) }; //=== like prototype.js === function $(id){ return document.getElementById(id); } function $N(name, attr, childs) { var ret = document.createElement(name); for (var k in attr) { if (!attr.hasOwnProperty(k)) continue; v = attr[k]; if (k == "class") { ret.className = v; } else { ret.setAttribute(k, v); } } switch (typeof childs) { case "string": { ret.appendChild(document.createTextNode(childs)); break; } case "object": { for (var i = 0, len = childs.length; i < len; i++) { var child = childs[i]; if (typeof child == "string") { ret.appendChild(document.createTextNode(child)); } else { ret.appendChild(child); } } break; } } return ret; } //=== extend version of $X === /* $X(exp); $X(exp, context); $X(exp, type); $X(exp, context, type); http://coderepos.org/share/browser/lang/javascript/userscripts/jautopagerize.user.js?rev=1966 */ function $X (exp, context, type /* want type */) { if (arguments.callee.forceRelative || navigator.userAgent.indexOf("Safari/523.12") != -1) exp = exp.replace(/id\(\s*(["'])([^"']+)\1\s*\)/g, '//*[@id="$2"]'); if (arguments.callee.forceRelative) exp = exp.indexOf("(//") == 0 ? "(.//" + exp.substring(3) : (exp[0] == "/" ? "." : "./") + exp; if (typeof context == "function") { type = context; context = null; } if (!context) context = document; exp = (context.ownerDocument || context).createExpression(exp, function (prefix) { return document.createNSResolver((context.ownerDocument == null ? context : context.ownerDocument).documentElement) .lookupNamespaceURI(prefix) || document.documentElement.namespaceURI; }); switch (type) { case String: return exp.evaluate(context, XPathResult.STRING_TYPE, null).stringValue; case Number: return exp.evaluate(context, XPathResult.NUMBER_TYPE, null).numberValue; case Boolean: return exp.evaluate(context, XPathResult.BOOLEAN_TYPE, null).booleanValue; case Array: var result = exp.evaluate(context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var ret = []; for (var i = 0, len = result.snapshotLength; i < len; i++) { ret.push(result.snapshotItem(i)); } return ret; case undefined: var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); switch (result.resultType) { case XPathResult.STRING_TYPE : return result.stringValue; case XPathResult.NUMBER_TYPE : return result.numberValue; case XPathResult.BOOLEAN_TYPE: return result.booleanValue; case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: { /* not ensure the order. */ var ret = []; var i = null; while (i = result.iterateNext()) { ret.push(i); } return ret; } } return null; default: throw(TypeError("$X: specified type is not valid type.")); } } //=== HTML -> DOM === function convertToHTMLDocument(html) { var xml_str = [ '', '', '', '' ].join('\n'); var xsl = (new DOMParser()).parseFromString(xml_str, 'text/xml'); var xsltp = new XSLTProcessor(); xsltp.importStylesheet(xsl); var doc = xsltp.transformToDocument(document.implementation.createDocument("", "", null)); doc.appendChild(doc.createElement("html")); var range = doc.createRange(); range.selectNodeContents(doc.documentElement); doc.documentElement.appendChild(range.createContextualFragment(html)); return doc; }