// // This is a Greasemonkey user script. To install it, you need // Greasemonkey 0.3 or later: http://greasemonkey.mozdev.org/ // Then restart Firefox and revisit this script. // Under Tools, there will be a new menu item to "Install User Script". // Accept the default configuration and install. // // To uninstall, go to Tools/Manage User Scripts, // select "Hello World", and click Uninstall. // //
// // ==UserScript== // @name Show Selection prototype // @namespace http://raymondyee.net/projects/greasemonkey/ // @description example script to show the parameters of the selection object on every page // @include * // ==/UserScript==
GM_registerMenuCommand("Show selection", function() { if (window.getSelection) {
-
selObj = window.getSelection(); // http://dev.lophty.com/ahoy/article.htm //var blnRangeImplemented = document.implementation.hasFeature("Range", "2.0"); //if (blnRangeImplemented) {alert('Range implemented');} else {alert('Range not implemented');}
selText = selObj.toString(); //if (selObj.anchorNode) {alert('anchorNode defined');} else {alert('anchorNode undefined');}
anchorNode = selObj.anchorNode; anchorOffset = selObj.anchorOffset; focusNode = selObj.focusNode; focusOffset = selObj.focusOffset; rangeCount = selObj.rangeCount;
alert(selText + "\n " + "anchorNode, anchorOffset: " + anchorNode + anchorOffset + "\n" +
-
"focusNode, focusOffset: " + focusNode + focusOffset + "\n" + "rangeCount: " + rangeCount);
-
// display range info
for (var i=0; i<rangeCount; i++) {
-
range = selObj.getRangeAt(i); startContainer = range.startContainer; endContainer = range.endContainer; startOffset = range.startOffset; endOffset = range.endOffset; commonAncestorContainer = range.commonAncestorContainer; alert('startContainer, startOffset: ' + startContainer + startOffset + "\n" +
-
'endContainer, endOffset: ' + endContainer + endOffset + "\n" + 'commonAncestorContainer: ' + commonAncestorContainer.innerHTML);
} });
