Skip to content

Commit f04b35c

Browse files
committed
feat(selected): add implementation
1 parent 6c65fd0 commit f04b35c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
'use strict';
22
/**
3-
* @return {string} plain-text title from current page.
3+
* @return {string} selected text or plain-text title from current page.
44
**/
55
module.exports = function () {
6-
return window.document.title;
6+
var selected = ('getSelection' in window ? window : document).getSelection().toString();
7+
var title = window.document.title;
8+
if (selected) {
9+
return selected;
10+
}
11+
return title;
712
};

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ browserTitleOrSelection();
2929

3030
### browserTitleOrSelection() -> String
3131

32-
*Title*
32+
*Selected text* OR *Title*
3333

3434

3535
## Changelog

0 commit comments

Comments
 (0)