-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (52 loc) · 2.31 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Gmail Message Length Checker 1.1
* (c) Neil Gupta 2011
* https://github.com/neilgupta/Gmail-Message-Length-Checker/
*
* Displays how long your email will take to read.
*
*/
// calculates reading length of email,
// using equation from http://www.leancrew.com/all-this/2011/06/reading-time-in-textmate/
$("textarea[name='body']").live("keyup blur",function() {
var str = $.trim($(this).val()),
wc = str === "" ? 0 : str.split(" ").length, // calculate word count
min = Math.floor(wc/250),
sec = pad(new Number((wc % 250)/250*60).toFixed(), "0", 2),
$container = $(this).parents("table").prev().find("tr").children().last(),
$time = $container.find("span#metamorphium-time");
if ($time.length === 0)
// add our notice element to the DOM, right next to the "Check Spelling" button in Gmail
$time = $("<span id='metamorphium-lengthnotice'>Reading time: <span id='metamorphium-time'></span></span>")
.prependTo($container).find("span#metamorphium-time");
// update text
$time.text(min+":"+sec);
// show red warning if email will take more than maxSeconds to read
var maxTime = settings.maxSeconds / 60;
if (settings.doWarning && min >= Math.floor(maxTime) && (wc % 250)/250 > (maxTime % 1))
$time.addClass("metamorphium-warning");
else
$time.removeClass("metamorphium-warning");
});
var pad = function (val, pad, size) { while (val.length < size) val = pad + val; return val; };
// convoluted method for getting Safari settings
var settings;
safari.self.tab.dispatchMessage("settings"); // ask for value
safari.self.addEventListener("message", getMessage, false); // wait for reply
function getMessage(event) {
if (event.name === "settingsAre")
settings = event.message;
}
// Commented out because I could not figure out how to prevent Gmail from sending the email
// after send button had been pushed.
/*
$("div[role='navigation'] div[role='button']:contains('Send')").live("click", function() {
var str = $.trim($(this).val()),
wc = str === "" ? 0 : str.split(" ").length, // calculate word count
min = Math.floor(wc/250),
sec = pad(new Number((wc % 250)/250*60).toFixed(), "0", 2),
if (min > 0 || (wc % 250)/250 > 0.5)
return !confirm("Your email will take "+min+":"+sec+" to read! Consider making it shorter?"+'\n'+
'\n'+"Press OK to edit your email, press Cancel to send anyway.");
});
*/