-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
27 lines (24 loc) · 1.33 KB
/
background.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
'use strict';
chrome.commands.onCommand.addListener(function(command) {
var subjectText = "";
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
subjectText = response.subjectText;
//TODO: these strings above should only be replaced if they're at the beginning of the subject string (but please note that they might be in a different order, so simply changing the below implementation to ltrim() won't be sufficient). Edge case so I don't care for MVP, feel free to add it, Fellow Contributor!
subjectText = subjectText.replace("RE: ","");
subjectText = subjectText.replace("Re: ","");
subjectText = subjectText.replace("Fwd: ","");
subjectText = subjectText.replace("FW: ","");
subjectText = subjectText.replace("AW: ","");
subjectText = 'subject:"'+subjectText+'"';
var el = document.createElement('textarea');
el.value = subjectText;
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
});
});
});