-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtabUI.js
42 lines (38 loc) · 1.13 KB
/
tabUI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function restore_options() {
chrome.storage.sync.get(['selectedText','selectedTextClean','selectedTextEmoji'], function(data) {
//$('.selected').val(data.selectedText);
$('.selected-clean').text(data.selectedTextClean);
$('.selected-emoji').text(data.selectedTextEmoji);
});
}
$(document).ready(function(){
restore_options();
});
function copyFromElement(element){
$(element).selectText();
document.execCommand("Copy");
}
$("#btn-copy-clean").click(function(){
copyFromElement('#clean');
$(this).text("Copied!");
});
$("#btn-copy-emoji").click(function(){
copyFromElement('#emoji');
$(this).text("Copied!");
});
jQuery.fn.selectText = function(){
var doc = document;
var element = this[0];
console.log(this, element);
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
};