-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
176 lines (159 loc) · 5.65 KB
/
script.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
$(function () {
startFeatures();
});
function startFeatures() {
if (location.href.indexOf("news.ykt.ru") != -1) startNewsFeatures();
if (location.href.indexOf("joker.ykt.ru") != -1) startJokerFeatures();
addTopPanel();
}
function startNewsFeatures() {
removeSocialWidgets();
resizeImages();
markBadComments();
}
function startJokerFeatures() {
prepareNextPageLink();
generateVideoLinks();
showProfile();
}
function removeSocialWidgets() {
$("#facebook-jssdk").remove();
$(".fb_iframe_widget").remove();
$("#vk_groups").remove();
}
function markBadComments() {
$(".comment", $("#articleComments")).each(function () {
if ($(".plusminus", $(this)).hasClass("negative")) {
$(".body", $(this)).addClass("plus-bad");
}
});
}
function resizeImages() {
$("img", $(".comment-img")).each(function () {
if ($(this).width() > $(this).height())
$(this).height("100%");
});
}
function addTopPanel() {
$("body").append("<div class='plus-top'><div class='plus-top-panel'><div class='plus-top-button' title='Наверх'>↑</div></div></div>");
}
$(document).on("click", ".plus-top-panel", function () {
$.scrollTo(0, 100, { axis: "y", onAfter: function () { lastPosition = 0; $(".plus-top").hide(); } });
});
function showProfile() {
$("div.nav").each(function () {
var parent = $(this);
if (!parent.hasClass("plus-processed")) {
var user = $("b", parent);
var anchor = $("a", user);
var name = anchor.attr("href");
var index = name.indexOf("user/");
if (index != -1) {
name = name.substring(index + 5).replace("/", "");
$.get("/engine/ajax/profile.php", { name: name, skin: "Default" }, function (data) {
$("img", data).each(function () {
if ($(this).attr("alt") == "rss")
return;
if ($(this).attr("src").indexOf("online") != -1 || $(this).attr("src").indexOf("offline") != -1)
return;
$(this).addClass("plus-avatar");
anchor.prepend($(this));
parent.addClass("plus-processed");
});
});
}
}
});
}
function appendLink(parent, href, width, position) {
parent.append('<div class="plus-container" style="width:' + (position == "center" ? "100%" : width) + '"><a href="' + href + '" class="plus-link">Скачать</a></div>');
}
function generateVideoLinks() {
var parent, position, src, width;
$("embed").each(function () {
parent = $(this).parent();
if (!parent.hasClass("plus-processed")) {
position = parent.css("text-align");
width = $(this).attr("width");
if (src = $(this).attr("flashvars")) {
var startIndex = src.indexOf("file=");
if (startIndex != -1) {
src = src.substring(5 + startIndex);
var endIndex = src.indexOf("&");
if (endIndex != -1) {
src = src.substring(0, endIndex);
appendLink(parent, src, width, position);
parent.addClass("plus-processed");
}
}
}
}
});
$("video").each(function () {
parent = $(this).parent();
if (!parent.hasClass("plus-processed")) {
position = parent.css("text-align");
width = "640px";
$("source", $(this)).each(function () {
if (src = $(this).attr("src")) {
appendLink(parent, src, width, position);
parent.addClass("plus-processed");
}
});
}
});
}
function getNextPageLink() {
var nextPageLink;
$("a", $("div.style2")).each(function () {
if ($(this).text() == "Следующая страница") {
$(this).attr("id", "plus-next");
nextPageLink = $(this);
}
});
return nextPageLink;
}
$(document).on("click", "#plus-next", function () {
var parent = $(this);
$.jGrowl("Подождите, загружается следующая страница...", {
open: function () {;
parent.parent().remove();
$(".plus-loader").show();
var href = parent.attr("href");
$.ajax({
url: href,
success: function (response) {
$("#dle-content").append($(response).find("#dle-content").html());
startJokerFeatures();
isNextPageLoading = false;
$.jGrowl("close");
}
});
}
});
});
function prepareNextPageLink() {
var nextPageLink;
if (nextPageLink = getNextPageLink()) {
if (nextPageLink.attr("href")) {
nextPageLink.parent().hide();
$(".plus-loader").remove();
$("#dle-content").append('<div class="plus-loader"><img src="' + chrome.extension.getURL('images/ajax-loader.gif') + '"/></div>');
}
}
}
var isNextPageLoading = false;
var lastPosition = 0;
$(window).scroll(function () {
if (lastPosition < window.pageYOffset)
$(".plus-top").show();
lastPosition = window.pageYOffset;
if (isNextPageLoading)
return;
if ($(window).scrollTop() + 10 >= ($(document).height() - ($(window).height()))) {
isNextPageLoading = true;
var nextPageLink;
if (nextPageLink = getNextPageLink())
nextPageLink.click();
}
});