frdic.com/dic_resource/frdic_grab.js
原代码如下
frdic.com/dic_resource/frdic_grab.js
原代码如下
var dict_is_ie = true;
var dict_host = 'http://www.frdic.com/';
var dict_help = 'http://www.frdic.com/service.aspx';
var dict_partner = '';
var dict_enable = false;
var dict_old_word = '';
var dict_moving = 0;
var dict_onmove = 0;
var dict_onlayer = 0;
var dict_startx = 0;
var dict_starty = 0;
var dict_cx = 0;
var dict_cy = 0;
var dict_x = 0;
var dict_y = 0;
var dict_layer;
var dict_iframe;
/*
* 描述:跨浏览器的设置 innerHTML 方法
* 允许插入的 HTML 代码中包含 script 和 style
* 作者:kenxu
* 日期:2006-03-23
* 参数:
* el: 合法的 DOM 树中的节点
* htmlCode: 合法的 HTML 代码
* 经测试的浏览器:ie5+, firefox1.5+, opera8.5+
*/
var setInnerHTML = function (el, htmlCode) {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
htmlCode = 'for IE
' + htmlCode;
htmlCode = htmlCode.replace(/]*)>/gi,
'');
el.innerHTML = htmlCode;
el.removeChild(el.firstChild);
}
else {
var el_next = el.nextSibling;
var el_parent = el.parentNode;
el_parent.removeChild(el);
el.innerHTML = htmlCode;
if (el_next) {
el_parent.insertBefore(el, el_next)
} else {
el_parent.appendChild(el);
}
}
}
/*
* 描述:通过重定义 document.write 函数,避免在使用 setInnerHTML 时,
* 插入的 HTML 代码中包含 document.write ,导致原页面受到破坏的情况。
*/
document.write = function() {
var body = document.getElementsByTagName('body')[0];
for (var i = 0; i < arguments.length; i++) {
argument = arguments[i];
if (typeof argument == 'string') {
var el = body.appendChild(document.createElement('div'));
setInnerHTML(el, argument)
}
}
}
//-->
function dictInit(){
var agt = navigator.userAgent.toLowerCase();
dict_is_ie = (agt.indexOf("msie")!=-1 && document.all);
var h = '';
h += '
';
h += '' ;
h += '';
h += ' ';
h += '';
h += ' ';
document.write(h);
dict_layer = document.getElementById('dict_layer');
dict_iframe = document.getElementById('dictFrame');
dictClose();
if (dictRCookie("dictstate") == '0' || dict_enable) dict_enable = true;
dictUpdateStatus();
if (dict_is_ie) {
document.attachEvent("onmousemove", dictMove);
document.attachEvent("ondblclick", dictQuery);
document.attachEvent("onmouseup", dictQuery);
document.attachEvent("onselectstart", dictSelect);
document.attachEvent("onmousedown", dictCheck);
window.attachEvent("onload", dictUpdateStatus);
} else {
document.addEventListener("mousemove", dictMove, true);
document.addEventListener("dblclick", dictQuery, true);
document.addEventListener("mouseup", dictQuery, true);
document.addEventListener("selectstart", dictSelect, true);
document.addEventListener("mousedown", dictCheck, true);
window.addEventListener("load", dictUpdateStatus, true);
}
}
function dictGetSel()
{
if (window.getSelection) return window.getSelection();
else if (document.getSelection) return document.getSelection();
else if (document.selection) return document.selection.createRange().text;
else return '';
}
function dictGetPos(event){
if (dict_is_ie) {
dict_x = window.event.clientX + document.documentElement.scrollLeft
+ document.body.scrollLeft;
dict_y = window.event.clientY + document.documentElement.scrollTop
+ document.body.scrollTop;
}else {
dict_x = event.clientX + window.scrollX;
dict_y = event.clientY + window.scrollY;
}
}
function dictSelect(e){
if (dict_moving == 2)
return false;
else
return true;
}
function dictCheck(e) {
dictGetPos(e);
var cx = 0;
var cy = 0;
var obj = dict_layer;
if (obj.offsetParent){
while (obj.offsetParent){
cx += obj.offsetLeft;
cy += obj.offsetTop;
obj = obj.offsetParent;
}
}else if (obj.x){
cx += obj.x;
cy += obj.y;
}
if(dict_moving>0){
if(dict_onmove == 1){
dict_moving = 2;
dict_startx = dict_x;
dict_starty = dict_y;
}else if(dict_x < cx || dict_x > (cx + 240) || dict_y < cy || (!dict_onlayer && dict_y > (cy + 100) ) ){
dictClose();
}else{
dict_moving = 1;
}
}
}
function dictQuery(e) {
if(dict_moving == 1){
if (dict_is_ie) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}else{
e.preventDefault();
}
return false;
}
if(dict_moving == 2) {
dict_cx = dict_x;
dict_cy = dict_y;
dict_moving = 1;
return false;
}
dictGetPos(e);
if (!dict_enable) return true;
var word = dictGetSel();
if(dict_is_ie) word=word.replace(/^\s*|\s*$/g,"");
if(word == "" || word.length > 16 || word == dict_old_word) return true;
dictShow(word);
}
function dictDisplay(){
var dx=262;
var dy=264;
dict_y += 8;
dict_x += 16;
if(dict_is_ie){
if (document.documentElement.offsetHeight && document.body.scrollTop+document.documentElement.scrollTop+document.documentElement.offsetHeight - dict_y < dy){
dict_y = document.body.scrollTop+document.documentElement.scrollTop + document.documentElement.offsetHeight - dy;
dict_x += 14;
}
if (document.documentElement.offsetWidth && document.body.scrollLeft+document.documentElement.scrollLeft+document.documentElement.offsetWidth - dict_x < dx){
dict_x = document.body.scrollLeft+document.documentElement.scrollLeft + document.documentElement.offsetWidth - dx;
}
}else{
dx-=1;
dy+=11;
if (self.innerHeight && document.body.scrollTop+document.documentElement.scrollTop + self.innerHeight - dict_y < dy) {
dict_y = document.body.scrollTop+document.documentElement.scrollTop + self.innerHeight - dy;
dict_x += 14;
}
if (self.innerWidth && document.body.scrollLeft+document.documentElement.scrollLeft + self.innerWidth - dict_x < dx) {
dict_x = document.body.scrollLeft+document.documentElement.scrollLeft + self.innerWidth - dx;
}
}
dict_cx = dict_x;
dict_cy = dict_y;
dict_startx = dict_x;
dict_starty = dict_y;
dict_layer.style.left = dict_cx+'px';
dict_layer.style.top = dict_cy+'px';
dict_layer.style.display="";
dict_moving = 1;
}
function dictShow(word){
dictDisplay();
try{
dict_iframe.src='about:blank';
iframeWin = window.frames.dictFrame;
iframeWin.document.open();
iframeWin.document.write(' 正在查找 '+word+' ,请稍后...');
iframeWin.document.close();
}catch(x){
}
var u=dict_host+'SearchGrab.aspx?Word='+encodeURI(word);
dict_iframe.src=u;
if(dict_is_ie) dict_old_word = word;
}
//function dictAdd(word){
// dictDisplay();
// try{
// dict_iframe.src='about:blank';
// iframeWin = window.frames.dictFrame;
// iframeWin.document.open();
// iframeWin.document.write('添加生词本: '+word+'
生词上传中... 请稍候...');
// iframeWin.document.close();
// }catch(x){
// }
// dict_old_word = '';
// dict_iframe.src='http://bbs.dict.cn/vocabulary.php?mini=1&word='+word;
//}
function dictMove(e){
if(dict_moving==2) {
dictGetPos(e);
dict_x = dict_x-dict_startx+dict_cx;
dict_y = dict_y-dict_starty+dict_cy;
if (document.documentElement.scrollWidth - dict_x < 262) {
dict_x = document.documentElement.scrollWidth - 262;
}
dict_layer.style.left = dict_x+'px';
dict_layer.style.top = dict_y+'px';
}
}
function dictClose() {
try
{
dict_moving = 0;
dict_onmove = 0;
dict_onlayer = 0;
dict_layer.style.display="none";
if(window.sf) sf();
}
catch (x)
{
}
}
function dictWCookie(name,value)
{
var date=new Date();
var now=date.getTime();
date.setTime(now+365*24*60*60*1000);
document.cookie=name+"="+value+"; path=/; expires="+date.toGMTString();
}
function dictRCookie(name)
{
var cookie=String(document.cookie);
var pos=cookie.indexOf(name+"=");
if(pos!=-1){
var end=cookie.indexOf("; ",pos);
return cookie.substring(pos+name.length+1,end==-1?cookie.length:end);
}
return "";
}
function dictEnable(){
if (dict_enable){
dict_enable = false;
dictWCookie("dictstate", '1');
}else{
dict_enable = true;
dictWCookie("dictstate", '0');
}
dictUpdateStatus();
}
function dictUpdateStatus(){
var el = document.getElementById('dict_status');
if(el){
el.innerHTML = dictStatus();
}
}
function dictStatus(){
if (dict_enable){
return '[划词翻译已开启]';
}else{
return '[划词翻译已关闭]';
}
}
|