📄 csdnscriptworkshop.js
字号:
clearTimeout(timer);
CsdnScriptPlugins[name].loading = false;
}
CsdnScriptWorkshop.changeButton(name);
});
return;
}
callScript(CsdnScriptPlugins[name].url, function() {
try {
eval("CsdnScriptPlugins[\"" + name + "\"].plugin = " + name + ";");
CsdnScriptPlugins[name].download = true;
CsdnScriptWorkshop.loadPlugin(name);
} catch (e) {
CsdnScriptPlugins[name].plugin = null;
CsdnScriptPlugins[name].download = false;
setCookie(name, "", -1);
alert("插件装载出现异常。--" + e.message);
} finally {
clearTimeout(timer);
CsdnScriptPlugins[name].loading = false;
}
CsdnScriptWorkshop.changeButton(name);
}, function() {
setCookie(name, "", -1);
clearTimeout(timer);
CsdnScriptPlugins[name].plugin = null;
CsdnScriptPlugins[name].download = false;
CsdnScriptPlugins[name].loading = false;
CsdnScriptWorkshop.changeButton(name);
alert("无效脚本文件。");
});
}
return true;
},
/// <summary>
/// 释放UBB插件对象,拒绝访问
/// </summary>
/// <param name="plugin">脚本对象</param>
/// <returns>返回是否释放成功</returns>
freePlugin: function(name) {
var plugin = CsdnScriptPlugins[name].plugin;
if (!plugin) return false;
if (plugin.interfaceVersion != this.interfaceVersion) return false;
if (typeof plugin.free != "function") return false;
if (!plugin.loaded) return false; // 未激活
if (name == "CsdnScriptPlugin999") {
CsdnScriptPlugin999 = null;
CsdnScriptPlugins[name].plugin = null;
CsdnScriptPlugins[name].download = false;
}
setCookie(name, "", -1);
plugin.free();
plugin.loaded = false;
CsdnScriptWorkshop.changeButton(name);
return true;
},
/// <summary>
/// 改变按钮状态
/// </summary>
/// <param name="name">插件名</param>
changeButton: function(name) {
var button_load = document.getElementById("button_" + name + "_load");
var button_free = document.getElementById("button_" + name + "_free");
if (CsdnScriptPlugins[name].loading) {
if (button_load) {
button_load.style.color = "Green";
button_load.style.cursor = "default";
button_load.innerHTML = "装载中...";
button_load.onclick = null;
}
if (button_free) {
button_free.style.color = "Green";
button_free.style.cursor = "default";
button_free.innerHTML = "装载中...";
button_free.onclick = null;
}
} else if (CsdnScriptPlugins[name].plugin && CsdnScriptPlugins[name].plugin.loaded) {
if (button_load) {
button_load.style.color = "Red";
button_load.style.cursor = "default";
button_load.innerHTML = "已装载";
button_load.onclick = null;
}
if (button_free) {
button_free.style.color = "Blue";
button_free.style.cursor = "pointer";
button_free.innerHTML = "卸载";
button_free.onclick = function() { CsdnScriptWorkshop.freePlugin(name); };
}
} else {
if (button_load) {
button_load.style.color = "Blue";
button_load.style.cursor = "pointer";
button_load.innerHTML = "装载";
button_load.onclick = function() { CsdnScriptWorkshop.loadPlugin(name); };
}
if (button_free) {
button_free.style.color = "Red";
button_free.style.cursor = "default";
button_free.innerHTML = "已卸载";
button_free.onclick = null;
}
}
},
/// <summary>
/// 获得UBB编辑器,推荐访问
/// </summary>
/// <returns>返回编辑对象</returns>
getEditor: function() {
return document.getElementById("tb_ReplyBody___Editor") ||
document.getElementById("ctl00_ctl00_CPH_Content_CPH_BaseContent_tb_TopicBody___Editor");
},
/// <summary>
/// 获得UBB编辑器文本,推荐访问
/// </summary>
/// <returns>返回全部文本</returns>
getEditorText: function() {
var editor = this.getEditor();
if (editor) return editor.value;
},
/// <summary>
/// 设置UBB编辑器文本,推荐访问
/// </summary>
/// <param name="value">文本内容</param>
setEditorText: function(value) {
var editor = this.getEditor();
if (editor) return editor.value = value;
},
/// <summary>
/// 获得UBB编辑器选中文本,推荐访问
/// </summary>
/// <returns>返回当前选中的文本</returns>
getSelectText: function() {
var editor = this.getEditor();
if (!editor) return;
editor.focus();
if (this.range)
return this.range.text;
else if (editor.document && editor.document.selection)
return editor.document.selection.createRange().text;
else if (typeof editor.selectionStart != "undefined")
return editor.value.substring(editor.selectionStart, editor.selectionEnd);
},
/// <summary>
/// IE编辑器文字选区
/// </summary>
range: null,
/// <summary>
/// 设置UBB编辑器选中文本,推荐访问
/// </summary>
/// <param name="value">文本内容</param>
setSelectText: function(value) {
var editor = this.getEditor();
if (!editor) return;
editor.focus();
if (this.range) {
this.range.text = value;
this.range.select();
this.range = null;
} else if (editor.document && editor.document.selection)
editor.document.selection.createRange().text = value;
else if (typeof editor.selectionStart != "undefined") {
var str = editor.value;
var start = editor.selectionStart;
var top = editor.scrollTop;
editor.value = str.substr(0, start) + value +
str.substring(editor.selectionEnd, str.length);
editor.selectionStart = start + value.length;
editor.selectionEnd = start + value.length;
editor.scrollTop = top;
}
},
/// <summary>
/// 添加工具按钮,推荐访问
/// </summary>
/// <param name="hint">提示内容</param>
/// <param name="icon">图标URL,16*16,可以通过个人空间上传</param>
/// <param name="click">点击按钮执行的函数</param>
addButton: function(hint, icon, click) {
if (!this.initialized) return;
var a_button = document.createElement("a");
a_button.input_button = document.createElement("input");
a_button.input_button.className = "menuitem";
if (icon) a_button.input_button.style.backgroundImage = "url(" + icon + ")";
a_button.input_button.type = "button";
a_button.input_button.title = hint;
a_button.input_button.workshop = this;
a_button.input_button.onfocus = function() { this.blur(); };
if (typeof click == "function") a_button.input_button.onclick = click;
a_button.appendChild(a_button.input_button);
this.toolbar.appendChild(a_button);
return a_button;
},
/// <summary>
/// 删除工具按钮,推荐访问
/// </summary>
/// <param name="button">按钮对象</param>
deleteButton: function(button) {
if (!button) return false;
button.input_button.parentNode.removeChild(button.input_button);
button.parentNode.removeChild(button);
return true;
},
/// <summary>
/// 添加工具分隔条,推荐访问
/// </summary>
addSeparator: function() {
if (!this.initialized) return;
var input_separator = document.createElement("input");
input_separator.className = "menuitem space";
input_separator.type = "button";
input_separator.disabled = "true";
input_separator.onfocus = function() { this.blur(); };
this.toolbar.appendChild(input_separator);
return input_separator;
},
/// <summary>
/// 删除工具分隔条,推荐访问
/// </summary>
/// <param name="separator">分隔条对象</param>
deleteSeparator: function(separator) {
if (!separator) return;
separator.parentNode.removeChild(separator);
},
/// <summary>
/// 显示对话框,推荐访问
/// </summary>
/// <param name="title">标题</param>
/// <param name="html">显示的html内容</param>
/// <param name="left">左边距</param>
/// <param name="top">上边距</param>
/// <param name="width">宽度</param>
/// <param name="height">高度</param>
showDialog: function(title, html, left, top, width, height) {
var editor = this.getEditor();
if (editor) {
editor.focus();
if (editor && editor.document && editor.document.selection)
this.range = editor.document.selection.createRange(); // 记忆编辑框选区,在IE中如果在其他文本框输入内容将导致UBB编辑框的选区失效,所以需要记忆
} else this.range = null;
left = typeof left == "undefined" ? -1 : left;
top = typeof top == "undefined" ? -1 : top;
if (typeof showWindow == "function")
showWindow({ "html": html, "width": width, "height": height, "title": title,
"left": left, "top": top
});
},
/// <summary>
/// 关闭对话框,推荐访问
/// </summary>
closeDialog: function() {
this.range = null;
if (typeof closeWindow == "function") closeWindow();
}
}
addEventHandler(window, "load", function() {
if (typeof CsdnDialog == "undefined") {
callScript("../ui/scripts/Csdn/Plugin/CsdnDialog.js?version=2008120901", function() {
if (typeof CsdnDialog != "undefined" && typeof CsdnScriptPlugins != "undefined")
CsdnScriptWorkshop.initialize();
});
}
if (typeof CsdnScriptPlugins == "undefined") {
callScript("../ui/scripts/Csdn/Plugin/CsdnScriptPlugins.js?version=2008120907", function() {
if (typeof CsdnDialog != "undefined" && typeof CsdnScriptPlugins != "undefined")
CsdnScriptWorkshop.initialize();
});
}
});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -