|
阅读:6245回复:13
请问“复制链接文字”的功能是否可以编写脚本实现?
现在是用copy link text这个插件来实现
觉得单独占用一个插件有些浪费,不知道能不能把它编写成firegestures的一个脚本,用鼠标手势来实现,请指教 |
|
|
1楼#
发布于:2014-11-19 17:02
|
|
|
|
2楼#
发布于:2013-10-27 23:16
|
|
|
3楼#
发布于:2008-08-05 13:34
赞!
好用,多谢~~ |
|
|
4楼#
发布于:2008-08-05 13:34
|
|
|
5楼#
发布于:2008-08-05 13:34
附上copy link text扩展的js源代码部分,大家帮忙看看怎么改成firegestures的脚本。谢了!
var copylinktext = {
onLoad: function() {
// initialization code
this.initialized = true;
this.strings = document.getElementById("copylinktext-strings");
document.getElementById("contentAreaContextMenu")
.addEventListener("popupshowing", function(e) { copylinktext.showContextMenu(e); }, false);
},
showContextMenu: function(event) {
// show or hide the menuitem based on what the context menu is on
// see http://kb.mozillazine.org/Adding_items_to_menus
document.getElementById("context-copylinktext").hidden = !gContextMenu.onLink;
},
onMenuItemCommand: function(e) {
// Get the link text
var copytext = gContextMenu.linkText();
// Start preparation to add contents to clipboard
var strunicode = Components.classes["@mozilla.org/supports-string;1"].
createInstance(Components.interfaces.nsISupportsString);
if (!strunicode) return false;
var strhtml = Components.classes["@mozilla.org/supports-string;1"].
createInstance(Components.interfaces.nsISupportsString);
if (!strhtml) return false;
// Assign link text to clipboard variables
strhtml.data = copytext;
strunicode.data = copytext;
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if (!trans) return false;
trans.addDataFlavor("text/html");
trans.addDataFlavor("text/unicode");
trans.setTransferData("text/html", strhtml, copytext.length * 2);
trans.setTransferData("text/unicode", strunicode, copytext.length * 2);
var clipid = Components.interfaces.nsIClipboard;
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
if (!clip) return false;
// Add the link text to the clipboard
clip.setData(trans, null, clipid.kGlobalClipboard);
},
};
window.addEventListener("load", function(e) { copylinktext.onLoad(e); }, false); |
|
|
6楼#
发布于:2008-08-05 13:34
wushi777兄,你的代码我试了下,复制下来的是链接地址而非链接文字,麻烦你再修改下,辛苦了~~
|
|
|
7楼#
发布于:2008-08-05 13:34
var clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"]
.getService(Ci.nsIClipboardHelper);
clipboard.copyString(FireGestures.sourceNode);
FireGestures.setStatusText(FireGestures.sourceNode); |
|
|
8楼#
发布于:2008-08-05 13:34
!
在firegestures下划过一次你写的脚本对应的手势后,链接的右键菜单就多了一个“复制链接文本”的选项,但是无效,而且重启后该选项就消失了 我还是希望用firegestures在链接处为起点画一个手势后可以复制该链接的文字,因为如果卸了CoLT装上userChrome等于还是没少啊,呵呵。不知能否实现,谢谢~ |
|
|
9楼#
发布于:2008-08-05 13:34
楼上的兄弟,你的脚本我在firegestures里尝试没有成功啊。这个脚本只是userChrome扩展适用的?
|
|
|
10楼#
发布于:2008-08-05 13:34
userchrome.js扩展+
var copyLink = {
copy: function(aString) {
var clipb = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipb.copyString(aString);
dump(aString);
},
text: function() {
this.copy(gContextMenu.linkText());
},
init: function()
{
this.mItem = document.createElement("menuitem");
this.mItem.setAttribute("label", "\u590D\u5236\u94FE\u63A5\u6587\u672C");
this.mItem.setAttribute("accesskey", "T");
document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", function() { copyLink.onPopupShowing(this); }, false);
},
onPopupShowing: function(aPopup)
{
aPopup.insertBefore(this.mItem, document.getElementById("context-copylink"));
this.mItem.setAttribute("oncommand", "copyLink.text();");
this.mItem.hidden = !gContextMenu.onLink;
}
}
window.setTimeout(function() {
copyLink.init();
}); |
|
|
|
11楼#
发布于:2008-08-05 13:34
tazzy: 嗯,不是要当前浏览页的,我的意思是比如页面内有一个链接,文字是“百度”,链接到“www.baidu.com”,现在我想在该链接上画一个鼠标手势,能够将“百度”二字复制到剪贴版上。不知道是否能编写出这样的脚本 |
|
|
12楼#
发布于:2008-08-05 13:34
tazzy: 看那个代码似乎只是生成标签页HTML Link 跟copy link text的功能有很大不同啊 |
|
|
13楼#
发布于:2008-08-05 13:34
midavid:现在是用copy link text这个插件来实现 http://www.xuldev.org/firegestures/getscripts.php 有现成的 Copy Page Title and URL to Clipboard |
|
|
