Skip to content

Commit 33e3282

Browse files
author
why2fly
committed
新增2个论坛的盖楼脚本
1 parent 897ee2b commit 33e3282

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

V2EX帖子盖楼显示.user.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// ==UserScript==
2+
// @name V2EX帖子盖楼显示
3+
// @namespace http://tampermonkey.net/
4+
// @version 0.4
5+
// @description V2EX帖子盖楼,浏览帖子更直观!
6+
7+
// @match *://www.v2ex.com/*
8+
// @icon http://www.v2ex.com/favicon.ico
9+
// @grant none
10+
// ==/UserScript==
11+
12+
(function() {
13+
'use strict';
14+
15+
// Your code here...
16+
var xuhao = $('div.cell > table > tbody > tr > td:nth-child(3) > div.fr > span').get().map(i=>i.innerHTML);/*楼层序号a[20]*/
17+
var content = $('div.cell > table > tbody > tr > td:nth-child(3) > div.reply_content').get().map(i=>i.innerHTML);/*每层内容b[20]*/
18+
var name = $('div.cell > table > tbody > tr > td:nth-child(3) > strong > a').get().map(i=>i.innerHTML);/*层主名称c[20]*/
19+
20+
var d = $('div.cell > table > tbody > tr > td:nth-child(3) > div.reply_content');/*每层内容obj*/
21+
var m = $('#Main > div:nth-child(4) > div[id].cell');/*楼层obj*/
22+
23+
var name_obj = $('div.cell > table > tbody > tr > td:nth-child(3) > strong > a');/*层主名称obj*/
24+
var louzhu = $('#Main > div:nth-child(2) > div.header > small > a')[0].innerHTML;/*楼主名称*/
25+
var youname = $('#Rightbar > div:nth-child(2) > div:nth-child(1) > table:nth-child(1) > tbody > tr > td:nth-child(3) > span > a');/*当前用户名称*/
26+
youname = youname.length?youname[0].innerHTML :null ;
27+
var guanzhu = "why2fly";/*特别关注的人*/
28+
29+
var deep = new Array(m.length).fill(0); /*每层的深度,默认0,如移动一级则深度加1 */ /*主要解决深度太大导致显示面太小的问题*/
30+
var maxdeep = 4;/*支持的最大堆叠深度,超过后将只右移一点点距离,可修改*/
31+
var allsamll = false;/*全部只右移一点点距离,默认关闭*/
32+
33+
function change_color(i,name,color)
34+
{
35+
if( name[i] == name )
36+
{
37+
name_obj[i].setAttribute('style',color);/*当前层主为楼主,标记为蓝色*/
38+
}
39+
}
40+
41+
/*将i层移到j层下面*/
42+
function gailou_with_deep(i,j)
43+
{
44+
if(deep[j] >= maxdeep-1)
45+
{
46+
console.log(xuhao[j]+" deep = "+ deep[j]);
47+
d[j].parentNode.parentNode.parentNode.parentNode.parentNode.append(m[i]);
48+
deep[i] = deep[j];
49+
}
50+
else
51+
{
52+
allsamll ? d[j].parentNode.parentNode.parentNode.parentNode.parentNode.append(m[i]) : d[j].append(m[i]);
53+
deep[i] = deep[j]+1;
54+
}
55+
}
56+
57+
var i = 1;/*从第二层开始*/
58+
while(i< m.length)
59+
{
60+
change_color(i,louzhu, 'color:blue');/*当前层主为楼主,标记为蓝色*/
61+
change_color(i,louzhu, 'color:red');/*当前层主你自己,标记为红色*/
62+
change_color(i,louzhu, 'color:yellow');/*当前层主为特别关注的人,标记为黄色*/
63+
64+
if(content[i].match("楼上"))
65+
{
66+
console.log(xuhao[i]+" have @楼上 #"+i);
67+
gailou_with_deep(i,i-1);
68+
i++;continue;
69+
}
70+
71+
var num = content[i].search(/#\d+ /);/*内容包含 #14 xxxx ,脚本认为是回复14楼的,移过去*/
72+
if(num != -1)
73+
{
74+
num = parseInt(content[i].slice(num+1));
75+
console.log(xuhao[i]+" have @ #"+num);
76+
gailou_with_deep(i,num-1);
77+
i++;continue;
78+
}
79+
80+
/*从当前层i往前开始逆序匹配名称,成功则移动当前层i移动到目标j层的下面 */
81+
for(var j=i-1;j>=0;j--){
82+
if(content[i].match(name[j]))
83+
{
84+
console.log(xuhao[i]+" have @"+name[j] + " #"+(j+1));
85+
gailou_with_deep(i,j);
86+
break;
87+
}
88+
}
89+
i++;
90+
}
91+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// ==UserScript==
2+
// @name 过早客(原光谷社区)楼层排版优化
3+
// @namespace http://tampermonkey.net/
4+
// @version 0.2
5+
// @description 将过早客(原光谷社区)楼层排版优化 ,使回帖看起来更直观
6+
// @author jackson<[email protected]>
7+
// @match *://www.guozaoke.com/*
8+
// @grant none
9+
// ==/UserScript==
10+
11+
(function() {
12+
'use strict';
13+
14+
// Your code here...
15+
var a = $('.reply-item span:nth-child(3)').get().map(i=>i.innerHTML);/*楼层序号a[20]*/
16+
var b = $('.reply-item .content').get().map(i=>i.innerHTML);/*每层内容b[20]*/
17+
var c = $('.reply-item .username').get().map(i=>i.innerHTML);/*层主名称c[20]*/
18+
var d = $('.reply-item .content');/*每层内容obj*/
19+
var m = $('.reply-item');/*楼层obj*/
20+
var e = $('.reply-item .username');/*层主名称obj*/
21+
var x = $('.ui-header .username a')[0].innerHTML;/*楼主名称*/
22+
var y = $('.ui-header .username')[1].innerHTML;/*当前用户名称*/
23+
var z = "jackson";
24+
var i = 1;/*从第二层开始*/
25+
while(i< m.length){
26+
/*当前层主为楼主,标记为蓝色*/
27+
if( c[i] == x )
28+
{
29+
e[i].setAttribute('style','color:blue');
30+
}
31+
/*当前层主为当前用户,标记为红色*/
32+
else if( c[i] == y )
33+
{
34+
e[i].setAttribute('style','color:red');
35+
}
36+
/*当前层主为作者,标记为黄色*/
37+
else if( c[i] == z )
38+
{
39+
e[i].setAttribute('style','color:yellow');
40+
}
41+
/*当前层内容匹配“楼上”,将本层obj做为子obj添加到上层obj*/
42+
if(b[i].match("楼上"))
43+
{
44+
//console.log(a[i]+" have @楼上 #"+i);
45+
d[i-1].append(m[i]);
46+
}
47+
/*从上层开始逆序匹配名称,成功则移动 */
48+
for(var j=i-1;j>=0;j--){
49+
if(b[i].match(c[j])){
50+
//console.log(a[i]+" have @"+c[j] + " #"+(j+1));
51+
d[j].append(m[i]);
52+
break;
53+
}
54+
}
55+
i++;
56+
}
57+
})();

0 commit comments

Comments
 (0)