aboutsummaryrefslogtreecommitdiff
path: root/content.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-03-16 22:04:56 -0700
committerAlex Yatskov <alex@foosoft.net>2016-03-16 22:04:56 -0700
commit3fd7ab16ac6f3c97822951eaddd7d9a090cea48a (patch)
treeef015556afbe726a17ccec07f37b2c347fb74576 /content.js
parent4c8960dba591beb850ea1b49d02c8771ab705d08 (diff)
Test code
Diffstat (limited to 'content.js')
-rw-r--r--content.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/content.js b/content.js
index 1e586602..119fce55 100644
--- a/content.js
+++ b/content.js
@@ -20,4 +20,32 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-document.body.style.background = 'lightyellow';
+function insertBreakAtPoint(e) {
+ var range;
+ var textNode;
+ var offset;
+
+ if (document.caretPositionFromPoint) {
+ range = document.caretPositionFromPoint(e.clientX, e.clientY);
+ textNode = range.offsetNode;
+ offset = range.offset;
+ } else if (document.caretRangeFromPoint) {
+ range = document.caretRangeFromPoint(e.clientX, e.clientY);
+ textNode = range.startContainer;
+ offset = range.startOffset;
+ }
+
+ // only split TEXT_NODEs
+ if (textNode.nodeType == 3) {
+ var replacement = textNode.splitText(offset);
+ var br = document.createElement('br');
+ textNode.parentNode.insertBefore(br, replacement);
+ }
+}
+
+function onMouseDown(e) {
+ insertBreakAtPoint(e);
+}
+
+
+window.addEventListener('mousedown', onMouseDown, false);