Usage
Drag the following link to your link toolbar:
Click your "Dictionary Tootip" button on your link toolbar, and it will add an extension that shows the meaning of the selected phrase in a tooltip on the same page, by automatic searching the selected text in dict.cn, which provides online dictionary search service.
Last Version
http://bsmagic.jot.com/WikiHome/DictTooltipJS
Source Code
http://bsmagic.jot.com/WikiHome/DictTooltipJS/dict_cn.js
<a href="javascript:
var js1 = document.createElement('script');
js1.language = 'javascript';
js1.setAttribute('src', 'http://bsmagic.jot.com/WikiHome/DictTooltipJS/dict_cn.js');
document.body.appendChild(js1);
dictInit();
">Link4</a>
var js1 = document.createElement('script');
js1.language = 'javascript';
js1.setAttribute('src', 'http://bsmagic.jot.com/WikiHome/DictTooltipJS/dict_cn.js');
document.body.appendChild(js1);
dictInit();
">Link4</a>
Test Code
<SCRIPT LANGUAGE="JavaScript">
function Initial() {
var setInnerHTML = function (el, htmlCode) {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
'<script$1 defer="true">');
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 = 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 DictInsert() {
var js1 = document.createElement('script');
js1.language = 'javascript';
js1.setAttribute('src', 'http://dict.cn/hc/');
document.body.appendChild(js1);
dictInit();
}
function DictTips() {
Initial();
DictInsert();
}
</SCRIPT>
Click this button <Input type='button' onClick="DictTips();" Value="Dict Ext"></input>
and then select the following text for test: dictionary.<br>
function Initial() {
var setInnerHTML = function (el, htmlCode) {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
'<script$1 defer="true">');
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 = 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 DictInsert() {
var js1 = document.createElement('script');
js1.language = 'javascript';
js1.setAttribute('src', 'http://dict.cn/hc/');
document.body.appendChild(js1);
dictInit();
}
function DictTips() {
Initial();
DictInsert();
}
</SCRIPT>
Click this button <Input type='button' onClick="DictTips();" Value="Dict Ext"></input>
and then select the following text for test: dictionary.<br>
Todos
Support Other Dictionary Service.
Promote the speed.
Reference
http://johnvey.com/features/deliciousdirector/web-service-broker.html
http://www.ajaxwing.com/index.php?c=DOM
http://www.coolcode.cn/?p=117#pp=0
Demo and Code for running script while insert innerHTML
http://test.coolcode.cn/innerhtml/index2.php
<script type="text/javascript">
<!--
/**//*
* 描述:跨浏览器的设置 innerHTML 方法
* 允许插入的 HTML 代码中包含 script 和 style
* 作者:kenxu <ken@ajaxwing.com>
* 日期: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 = '<div style="display:none">for IE</div>' + htmlCode;
htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
'<script$1 defer="true">');
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)
}
}
}
//-->
</script>
Search Terms
document.createElement('script');
