-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCleanReader.user.js
More file actions
347 lines (308 loc) · 10.4 KB
/
CleanReader.user.js
File metadata and controls
347 lines (308 loc) · 10.4 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// ==UserScript==
// @name CleanReader
// @namespace https://greasyfork.org/zh-CN/users/141921
// @version 0.3.3
// @description 启用后,自动进入简洁阅读模式。
// @author Vinx
// @match
// @require https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
// @require https://greasyfork.org/scripts/38955-jquery-print/code/jQueryprint.js?version=254772
// @include *
// @grant none
// @run-at document-end
// @note 2018.11.07-V0.3.3 修复了CSDN打印的问题,添加OSChina等网站
// @note 2018.03.18-V0.3.2 添加放大缩小按钮,并支持按键缩放(+/= :放大,- :缩小)
// @note 2018.03.18-V0.3.1 添加ESC退出阅读模式功能
// @note 2018.03.15-V0.3.0 添加对Discuz论坛的支持,修改标题和内容居中显示
// @note 2018.02.28-V0.2.0 不在自动进入,添加了阅读及打印按钮
// @note 2017.07.19-V0.1.0 首次发布,启用后,自动进入简洁阅读模式。
// ==/UserScript==
var contents = {
'blog.csdn.net': {
'title':".title-article|.csdn_top",
'content':".article_content"
},
'www.cnblogs.com': {
'title' :"#cb_post_title_url",
'content':"#cnblogs_post_body"
},
'blog.sina.com.cn': {
'title' :".articalTitle",
'content':".articalContent"
},
'bbs.fishc.com': {
'title' :"#thread_subject",
'content':"[id^='postmessage_']:first"
},
'www.liaoxuefeng.com': {
'title' :".x-content h4",
'content':".x-main-content"
},
'blog.163.com': {
'title' :".title.pre.fs1",
'content':".bct.fc05.fc11.nbw-blog.ztag"
},
'www.runoob.com': {
'title' :".article-intro h1:first",
'content':".article-body"
},
'lib.uml.com.cn': {
'title' :".arttitle",
'content':".artcontent"
},
'bbs.pediy.com': {
'title' :".break-all.subject",
'content':".message.break-all:first"
},
'www.oschina.net': {
'title' :".article-detail>.header",
'content':"#articleContent"
},
'my.oschina.net': {
'title' :".article-detail>.header",
'content':"#articleContent"
}
};
(function() {
'use strict';
var J;
if (typeof jQuery != 'undefined') { //避免与原网页中的Jquery冲突
J = jQuery.noConflict(true);
}
AddTemplateSite();
if(!IsContentPage()) return;
J("head").append('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.css">');
var html_height = J("html").css("height");
var body_height = J("body").css("height");
var body_background = J("body").css("background");
var body_text_align = J("body").css("text-align");
var body_margin = J("body").css("margin");
var body_padding = J("body").css("padding");
var body_overflow_y = J("body").css("overflow-y");
var read_button=document.createElement("div");
J(read_button).css("width",24);
J(read_button).css("height",24);
J(read_button).css("right",32);
J(read_button).css("bottom",32);
J(read_button).css("z-index",999999);
J(read_button).css("cursor","pointer");
J(read_button).css("position","fixed");
J(read_button).css("margin","0 auto");
J(read_button).css("color","#0593d3");
J(read_button).css("font-size",24);
J(read_button).attr("class","fa fa-book fa-2");
J(read_button).attr("id","readbutton");
var print_button=document.createElement("div");
J(print_button).css("width",24);
J(print_button).css("height",24);
J(print_button).css("right",32);
J(print_button).css("bottom",64);
J(print_button).css("z-index",999999);
J(print_button).css("cursor","pointer");
J(print_button).css("position","fixed");
J(print_button).css("margin","0 auto");
J(print_button).css("color","#0593d3");
J(print_button).css("font-size",24);
J(print_button).attr("class","fa fa-print fa-2");
J(print_button).attr("id","printbutton");
var zoom_out_button=document.createElement("div");
J(zoom_out_button).css("width",24);
J(zoom_out_button).css("height",24);
J(zoom_out_button).css("right",32);
J(zoom_out_button).css("bottom",96);
J(zoom_out_button).css("z-index",999999);
J(zoom_out_button).css("cursor","pointer");
J(zoom_out_button).css("position","fixed");
J(zoom_out_button).css("margin","0 auto");
J(zoom_out_button).css("color","#0593d3");
J(zoom_out_button).css("font-size",24);
J(zoom_out_button).attr("class","fa fa-search-minus fa-2");
J(zoom_out_button).attr("id","zoomoutbutton");
var zoom_in_button=document.createElement("div");
J(zoom_in_button).css("width",24);
J(zoom_in_button).css("height",24);
J(zoom_in_button).css("right",32);
J(zoom_in_button).css("bottom",128);
J(zoom_in_button).css("z-index",999999);
J(zoom_in_button).css("cursor","pointer");
J(zoom_in_button).css("position","fixed");
J(zoom_in_button).css("margin","0 auto");
J(zoom_in_button).css("color","#0593d3");
J(zoom_in_button).css("font-size",24);
J(zoom_in_button).attr("class","fa fa-search-plus fa-2");
J(zoom_in_button).attr("id","zoominbutton");
J("body").prepend(read_button);
J("body").prepend(print_button);
J("body").prepend(zoom_in_button);
J("body").prepend(zoom_out_button);
J("#printbutton").hide();
J("#zoominbutton").hide();
J("#zoomoutbutton").hide();
J("#readbutton").click(function(){
var isShow = J(read_button).attr("userdata");
if(isShow == "true")
{
CencelCleanRead();
J("#printbutton").hide();
J("#zoominbutton").hide();
J("#zoomoutbutton").hide();
zoom=0;
}
else
{
CleanRead();
J("#printbutton").show();
J("#zoominbutton").show();
J("#zoomoutbutton").show();
}
});
J("#printbutton").click(function(){
J("#CleanReader").print({
globalStyles: false,
mediaPrint: false,
stylesheet: null,
noPrintSelector: ".no-print",
iframe: true,
append: null,
prepend: null,
manuallyCopyFormValues: true,
deferred: $.Deferred()
});
});
//ESC退出
J(document).keyup(function(){
var isShow = J(read_button).attr("userdata");
if(event.keyCode == 27 && isShow == "true")
{
CencelCleanRead();
J("#printbutton").hide();
J("#zoominbutton").hide();
J("#zoomoutbutton").hide();
zoom=0;
}
});
//放大缩小
var zoom=0;
J("#zoominbutton").click(function(){
zoom+=10;
J("#CleanReader").css("zoom",1+zoom/100);
});
J("#zoomoutbutton").click(function(){
zoom-=10;
J("#CleanReader").css("zoom",1+zoom/100);
});
J(document).keydown(function(){
var isShow = J(read_button).attr("userdata");
if(event.keyCode == 107 || event.keyCode == 187)
{
zoom+=10;
J("#CleanReader").css("zoom",1+zoom/100);
}
else if(event.keyCode == 109 || event.keyCode == 189)
{
zoom-=10;
J("#CleanReader").css("zoom",1+zoom/100);
}
});
function IsContentPage()
{
if(!contents.hasOwnProperty(window.location.host)) return false;
var isContentPage = false;
var tmp1 = contents[window.location.host].content.split("|");
for(var i=0;i<tmp1.length;i++)
{
if (J(tmp1[i]).length > 0)
{
isContentPage = true;
break;
}
}
if(!isContentPage) return false;
return true;
}
function AddTemplateSite()
{
var jsonstr={};
//Discuz
if(J("meta[name='generator'][content]").length > 0 && J("meta[name='generator'][content]").attr("content").indexOf("Discuz") >= 0)
{
jsonstr.title = "#thread_subject";
jsonstr.content = "[id^='postmessage_']:first|.pattl";
contents[window.location.host] = jsonstr;
}
}
function CleanRead()
{
var hostName = window.location.host;
J("html").css("height","100%");
J("body").css("height","100%");
J("body").css("background","#ffffff");
J("body").css("text-align","left");
J("body").css("margin","0 0");
J("body").css("padding","0 0");
J("body").css("overflow-y","hidden");
var CleanReader=document.createElement("div");
J(CleanReader).css("background-color","#ffffff");
J(CleanReader).css("width",1000);
J(CleanReader).css("height","100%");
J(CleanReader).css("margin","0 auto");
J(CleanReader).css("padding","0px 20px");
J(CleanReader).css("overflow-y","auto");
J(CleanReader).attr("id","CleanReader");
var titleSelectors = contents[hostName].title.split("|");
var titleText;
for(var i=0;i<titleSelectors.length;i++)
{
if (J(titleSelectors[i]).length > 0)
{
titleText = J(titleSelectors[i]).text();
break;
}
}
var title = document.createElement("div");
J(title).html(titleText);
J(title).css('font-size', 32);
J(title).css("margin","10px auto");
J(title).css("padding","10px 0px");
J(title).css("text-align","center");
J(CleanReader).append(title);
J(CleanReader).append("<hr/>");
var textSelectors = contents[hostName].content.split("|");
for(var j=0;j<textSelectors.length;j++)
{
J(CleanReader).append(J(textSelectors[j]).clone());
}
J(CleanReader).children().css("margin","0px auto");
var mask=document.createElement("div");
J(mask).css("height","100%");
J(mask).css("width","100%");
J(mask).css("background-color","rgba(0,0,0,0.9)");
J(mask).css("z-index",999997);
J(mask).css("position","fixed");
J(mask).css("margin","0 auto");
J(mask).attr("id","CleanReadermask");
J(mask).append(CleanReader);
J("body").prepend(mask);
var image = J(CleanReader).find("img");
for(var k=0;k<image.length;k++)
{
if( J(image[k]).width() > J(CleanReader).width()-20)
{
J(image[k]).width(J(CleanReader).width()-20);
}
}
J(read_button).attr("userdata","true");
}
function CencelCleanRead()
{
J("#CleanReadermask").remove();
J("html").css("height",html_height);
J("body").css("height",body_height);
J("body").css("background",body_background);
J("body").css("text-align",body_text_align);
J("body").css("margin",body_margin);
J("body").css("padding",body_padding);
J("body").css("overflow-y",body_overflow_y);
J(read_button).attr("userdata","");
}
})();