-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
88 lines (82 loc) · 2.35 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
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
document.addEventListener('keyup', function(e) {
var tag = e.target.tagName.toLowerCase();
// keycode for 'i' is 73
// Ignore when composing tweets...
if (tag == 'input' || tag == 'textarea' || e.keyCode != 73)
return true;
var hovered = $('.selected-stream-item');
var text = $('.hovered-stream-item .js-tweet-text').text().trim();
if (hovered.length != 0) {
// find links
var links = hovered.find('.twitter-timeline-link');
var processed = [];
if (links.length != 0) {
// send each unique link to instapaper.
links.each(function(i){
if ($.inArray(this.href, processed) == -1){
saveToInstapaper(this.href, text);
animateSharedLink(this);
processed.push(this.href);
}
return true;
});
}
else {
// otherwise, send tweet permalink.
var permalink = hovered.find('.js-permalink')[0];
if ($.inArray(permalink.href, processed) == -1){
saveToInstapaper(permalink.href, text);
animatePermalink(permalink);
processed.push(permalink.href);
}
}
}
}, true);
function saveToInstapaper(url, text) {
chrome.storage.local.get("t2i_settings", function(data) {
settings = data["t2i_settings"];
$.ajax({
url: "https://www.instapaper.com/api/add",
type: 'GET',
data: {
url: encodeURI(url),
selection: text,
username: settings.username,
password: settings.pwd
},
dataType: 'json'
}
);
});
}
function animateSharedLink(item){
var txt = $(item).find('.js-display-url')[0];
animateTextNode(txt);
}
function animatePermalink(item){
var txt = $(item).find('.js-short-timestamp')[0];
animateTextNode(txt);
}
function animateTextNode(txt){
var p = $(txt).parent();
p.css("position", "relative");
$(txt).clone()
.appendTo(p)
.css("position", "absolute")
.css("left", "0")
.animate({
fontSize: "24px",
left: "-=100"
},
{
step: function(current, fx){
if (fx.prop == "left" && current <= -50) {
$(fx.elem).css("color", "#222");
}
}
})
.prepend("\u272A ")
.fadeOut('slow', function(){
$(this).remove();
});
}