-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHabr2kindle.user.js
47 lines (41 loc) · 1.76 KB
/
Habr2kindle.user.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
// ==UserScript==
// @name Habr2kindle
// @namespace http://habrahabr.ru
// @version 1
// @grant none
// ==/UserScript==
var infopanels = document.getElementsByClassName('infopanel');
Element.prototype.appendPostToRss = function(title, url) {
var url;
var title;
var postDiv = this.parentNode.parentNode.parentNode;
var titleDiv = postDiv.getElementsByTagName('h1')[0];
if (titleDiv.getElementsByTagName('a').length > 0) {
// This is a list of posts
var titleLink = titleDiv.getElementsByTagName('a')[0];
url = titleLink.getAttribute("href");
title = titleLink.childNodes[0].data;
} else {
// This is the page with post
url = document.URL;
title = titleDiv.getElementsByTagName('span')[0].childNodes[0].data;
}
var xmlhttp = new XMLHttpRequest();
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// TODO Change URL to URL of your feed!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
xmlhttp.open("POST", "http://example.com/rss_feed.php", false);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(("url=" + encodeURIComponent(url) + "&title=" + encodeURIComponent(title)).replace(/%20/g, '+'));
this.setAttribute("onclick", "");
this.style.color = "#AAAAAA";
};
for (var i=0, max=infopanels.length; i < max; i++) {
var postDiv = infopanels[i].parentNode.parentNode;
var text = document.createTextNode("2kindle");
var sendToKindle = document.createElement("div");
sendToKindle.appendChild(text);
sendToKindle.setAttribute("style", "float:left;font-weight:700;line-height:27px;margin-left:10px;");
sendToKindle.setAttribute("onclick", "this.appendPostToRss();");
infopanels[i].appendChild(sendToKindle);
}