-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.html
89 lines (88 loc) · 3.04 KB
/
background.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!-- Copyright 2010, [email protected]
Licensed under the BSD license
http://www.opensource.org/licenses/bsd-license.php -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body onload="myLoad();">
<div id="myDiv">
</div>
<script type="text/javascript" src="words.js"></script>
<script type="text/javascript">
function myLoad() {
chrome.contextMenus.create(
{
'title': 'Insert SpamGourmet address',
'contexts': ['editable'],
'onclick': doSG
}
);
};
function doSG(info, tab) {
var user = localStorage['user'];
if (user == undefined || user == '') {
chrome.tabs.create({'url': 'options.html'});
return;
}
var domain = localStorage['domain'];
if (domain == undefined) {
domain = 'spamgourmet.com';
}
var prefix = localStorage['prefix'];
if (prefix == undefined || prefix == '') {
prefix = '';
} else {
prefix += '.';
}
var num = localStorage['num'];
if (num == undefined || num == '0') {
num = '';
} else {
num += '.';
}
var word;
var site = info.pageUrl.split('/', 3)[2].split('.');
switch (localStorage['word']) {
case 'site':
word = site.join('');
break;
case 'random':
var chars = new Array(8);
var a = "a".charCodeAt(0);
for (var i=0; i<8; ++i) {
chars[i] = String.fromCharCode(
Math.floor(Math.random()*26) + a);
}
word = chars.join('');
break;
case 'aword':
word = words[Math.floor(Math.random()*words.length)];
break;
default:
word = site[site.length - 2];
}
var email = prefix + word +
"." + num + user + '@' + domain;
if (localStorage['copy'] !== 'false') {
myDiv.innerHTML = email;
var range = document.createRange();
range.selectNodeContents(document.getElementById('myDiv'));
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('Copy', false, '');
}
chrome.tabs.executeScript(
null,
{
'allFrames': true,
'code': "document.execCommand('insertHTML', false, '" +
email + "');"
}
);
};
</script>
</body>
</html>