var userAgent, preciseUserAgent; if (navigator.userAgent.match(/Android|Adr|iPhone|SymbianOS|Windows Phone|iPad|iPod/i)) { userAgent = 'phone'; if (document.querySelector('div.bd_body')) { preciseUserAgent = 'BlueDict'; } } else { userAgent = 'pc'; if (navigator.userAgent.match(/goldendict/i)) { preciseUserAgent = 'GoldenDict'; } else { preciseUserAgent = 'Eudic'; } } var root = document.querySelector('div#olect-wrapper'); var headWordRoot = root.getAttribute('head-word-root-level'); if (localStorage) { var myStorage = localStorage; } else if (sessionStorage) { var myStorage = sessionStorage; } else { return; } var keyDown = false; document.onkeydown = function (e){ if (e.keyCode == 17) { // 左ctrl键 keyDown = true; } } document.onkeyup = function (e){ if (e.keyCode == 17) { // 左ctrl键 keyDown = false; } } AddEventListeners(root); function AddEventListeners (rootNode, embedded) { if (embedded || myStorage.getItem('OLECT_COLLAPSED')) { var arrSections = rootNode.querySelectorAll(':scope>div.entry-content'); for (var j=1; jdiv.entry-content'); var allShown = true; for (var j=0; jdiv.entry-content:not(' + id + ')'); for (var j=0; jdiv.entry-content'); var allShown = true; for (var j=0; j.+?)olect_.+?(?(#ID.+)?)$/i; matchObj = reg.exec(linkNodeHref); reg = /"entry:\/\/(?[^<>]+?)"/ig; content = content.replace(reg, '"' + matchObj.groups.prefix + '$' + matchObj.groups.id + '"'); reg = /[^<>]*?>.+?<\/sh-g>)/ig; matches = content.match(reg); var extractedContent = ""; for (var j=0; j[^\/_]+?)_(?\d+)(#ID.+)?$/; var matchObj = reg.exec(linkNodeHref); var headWord = matchObj.groups.headWord; var dictIdx = matchObj.groups.dictIdx; // 找到当前层级点击链接后插入节点的位置 NodeExtraAddedAfter,不会为null if (groupNode.parentNode.tagName.toLowerCase() == "xr-seea-blk") { var NodeExtraAddedAfter = groupNode.parentNode; } else { var NodeExtraAddedAfter = groupNode; } var nextElementSibling = NodeExtraAddedAfter.nextElementSibling; while (nextElementSibling && (nextElementSibling.tagName.toLowerCase() == "xr-seea-blk" || (nextElementSibling.tagName.toLowerCase() == "xr-blk" && nextElementSibling.getAttribute('xt') == 'opp' && nextElementSibling.getAttribute('xth') == 'opp'))) { NodeExtraAddedAfter = nextElementSibling; nextElementSibling = NodeExtraAddedAfter.nextElementSibling; } // 找到当前层级点击链接所指向的节点 nodeExtraCurrentLevel,如果该节点尚未插入不存在则其值为null var nodeExtraCurrentLevel = null; while (nextElementSibling && nextElementSibling.tagName.toLowerCase() == "div" && nextElementSibling.classList.contains('extra-content')) { if (nextElementSibling.getAttribute('word-index') == linkNodeWordIdx && nextElementSibling.getAttribute('head-word') == headWord && nextElementSibling.getAttribute('dict-idx') == dictIdx) { nodeExtraCurrentLevel = nextElementSibling; break; } nextElementSibling = nextElementSibling.nextElementSibling; } // 如果当前层级点击链接所指向的节点尚未插入,检查父级的每一个层级是否有相同内容节点, nodeExtraPresentUpperLever为检查结果 var nodeExtraPresentUpperLever = false; if (!nodeExtraCurrentLevel) { var parentNode = groupNode.parentNode; var divEntryContent, sh_gTopmost; do { var nodeExtraPresentUpperLeverNonEmbedded = (parentNode.tagName.toLowerCase() == "div" && parentNode.classList.contains('extra-content') && parentNode.getAttribute('word-index') == linkNodeWordIdx && parentNode.getAttribute('head-word') == headWord && parentNode.getAttribute('dict-idx') == dictIdx); var nodeExtraPresentUpperLeverEmbedded = (parentNode.tagName.toLowerCase() == "div" && parentNode.classList.contains('extra-content') && parentNode.getAttribute('head-word-subroot-level') == headWord); //查询adequate,点击最上方句型和搭配中的level, 在level近义词组中找到scale, 点击full-scale=>detailed,再点击添加出来内容中 scale-level, 如果没有这里的nodeExtraPresentUpperLeverEmbedded,将再次添加重复内容scale的释义 if (nodeExtraPresentUpperLeverNonEmbedded || nodeExtraPresentUpperLeverEmbedded) { nodeExtraPresentUpperLever = true; break; } if (parentNode.tagName.toLowerCase() == 'sh-g') { sh_gTopmost = parentNode; // 最上层节点 } else if (parentNode.tagName.toLowerCase() == 'div' || parentNode.classList.contains('entry-content')) { divEntryContent = parentNode; // 最上层div.entry-content节点 } parentNode = parentNode.parentNode; } while (parentNode != root) if (!nodeExtraPresentUpperLever) { if (sh_gTopmost.getAttribute('order-num') == linkNodeWordIdx) { var divEntryContentId = divEntryContent.getAttribute('id'); var divEntryContentHeadWord = divEntryContentId.split('_')[1]; var divEntryContentDictIdx = divEntryContentId.split('_')[2]; if (divEntryContentHeadWord == headWord && divEntryContentDictIdx == dictIdx) { nodeExtraPresentUpperLever = true; } } } } if (cmd == 'mouseenter') { if (nodeExtraCurrentLevel) { nodeExtraCurrentLevel.style.display = 'block'; InsertAfter(nodeExtraCurrentLevel, NodeExtraAddedAfter); } else if (!nodeExtraPresentUpperLever) { AddExtraNode(); } else { return; } } else if (cmd == 'mouseleave') { if (nodeExtraCurrentLevel && nodeExtraCurrentLevel.classList.contains('hide-when-mouse-leave')) { nodeExtraCurrentLevel.style.display = 'none'; } } else if (cmd == 'click') { // click时如果nodeExtraPresentUpperLever == true 则nodeExtraCurrentLevel == null if (nodeExtraCurrentLevel) { if (nodeExtraCurrentLevel.classList.contains('hide-when-mouse-leave')) { nodeExtraCurrentLevel.classList.remove('hide-when-mouse-leave'); nodeExtraCurrentLevel.style.display = 'block'; InsertAfter(nodeExtraCurrentLevel, NodeExtraAddedAfter); // 将节点排在最前且使之显示 } else { nodeExtraCurrentLevel.classList.add('hide-when-mouse-leave'); nodeExtraCurrentLevel.style.display = 'none'; } } else if (userAgent == 'phone' && !nodeExtraPresentUpperLever) { AddExtraNode(); nodeExtraCurrentLevel.classList.remove('hide-when-mouse-leave'); // 若无此语句,添加节点之后第一次隐藏它需要单击两次 } } } var arrSubEntry = root.querySelectorAll('sh-container sh, span.see-also-entry, cl-g x-blk cl'); for (var i=0; i div.extra-content') // 嵌套生成的内容不算,故用scope> for (var i=0; i div.extra-content') // 嵌套生成的内容不算,故用scope> for (var i=0; i'; html += map[MapHeadWord(arrHeadWords[i])][0]; var arrEntryIdx = map[MapHeadWord(arrHeadWords[i])][1]; for (var j=0; j'; if (!dict[MapHeadWord(arrEntryIdx[j][0])] || !dict[MapHeadWord(arrEntryIdx[j][0])][arrEntryIdx[j][1]] || !dict[MapHeadWord(arrEntryIdx[j][0])][arrEntryIdx[j][1]][2]) { return null; } var content = dict[MapHeadWord(arrEntryIdx[j][0])][arrEntryIdx[j][1]][2]; //dict[MapHeadWord(headWord)][dictIdx][2] var idx = GetEntryIndex(arrHeadWords[i], content); if (idx != -1) { var reg = /(?.+?<\/syn>)/ig; matches = content.match(reg); var replacer = matches[idx].replace(reg, '$'); content = content.replace(matches[idx], replacer); reg = new RegExp('(?.+?)','ig'); // 有两千多个这种形式的, 例词:force => control => force var nodeSh_g = reg.exec(content)[0]; replacer = nodeSh_g.replace(reg, '$'); reg = / .+?<\/sh>)/ig; //有的同义词entry中有多个词,如base下的 locate, be located replacer = replacer.replace(reg, ''); content = content.replace(nodeSh_g, replacer); } html += content + ''; } html += ''; } if (html == '') { return null; } var div = document.createElement("div"); div.classList.add('embedded-full-entry-added'); div.setAttribute("head-words", arrHeadWords.toString()); div.innerHTML = MapEntryLink(html); var arrCtrlsExpansion = div.querySelectorAll(':scope>div.extra-content[head-word-subroot-level]'); for (var i=0; iall rightall ˈright 这些标签中的href,id属性也会有重复相同,这将导致跳转错乱,故统一为动态添加的内容修改这些href,id属性的值 var randomId = '_' + parseInt(Math.random()* 10000); content = content.replace(/(?' + randomId + '"'); content = content.replace(/(?' + randomId + '"'); content = content.replace(/(?' + randomId + '"'); content = content.replace(/(?
' + randomId + '"'); // 欧路和GoldenDict内部处理a标签跳转的方式不同 if (preciseUserAgent = 'GoldenDict' || root.innerHTML.indexOf('gdlookup://localhost/') != -1) { return content.replace(/entry:\/\//gim, 'gdlookup://localhost/'); } else if (root.innerHTML.indexOf('(?]+?>)(?.+?)<\/a><\/syn>/ig; var matchesSynWordLinkList = content.match(regSynWordLinkList); for (var i=0; i.+?)"[^<>]+?>(?.+?)<\/sh>/ig; var matchesSynWordEntryBelow = content.match(regSynWordEntryBelow); for (var j=0; j