forked from sciooga/v2ex-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv2ex_tab.js
More file actions
132 lines (116 loc) · 6.58 KB
/
v2ex_tab.js
File metadata and controls
132 lines (116 loc) · 6.58 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
//——————————————————————————————————新窗口浏览主题——————————————————————————————————
var nwe_window;
chrome.storage.sync.get(function(response) {
if ( response.newWindow ){
$(".item_title a").attr("target", "_blank");
$(".item_hot_topic_title a").attr("target", "_blank");
nwe_window = "target='_blank'";
}
});
//——————————————————————————————————新窗口浏览主题——————————————————————————————————
//——————————————————————————————————预览及忽略功能——————————————————————————————————
chrome.storage.sync.get(function(response) {
if (!response.preview)
return;
$("div#Main > div:nth-of-type(2) .cell").each(function(){
if($(this).find(".fade").text().indexOf("...")!=-1){
return ;
}
$(this).find(".topic_info, .fade").append(" • <span class='preview'>预览</span> • <span class='pass'>忽略</span>");
});
$(".pass").click(function(){
var _this = $(this);
var url = _this.parents(".cell").find(".item_title a").attr("href");
if (confirm("确定不想再看到这个主题?")) {
url = url.replace("/t/", "/ignore/topic/");
var once = /signout\?once=([0-9]+)/.exec($("#Top").html())[1];
url = url.replace("#", "?once=" + once + "#");
location.href = url;
}
});
var btn_id = 0;
$(".preview").click(function(){
var _this = $(this);
var _cell = _this.parents(".cell");
if (_this.text() == "预览"){
_this.text("加载中...");
_cell.after("<div class='previewWindow'></div>");
var _href = _cell.find(".item_title a").attr("href");
_href = location.origin + _href;
$.get(_href, function(data){
var _previewWindow = _cell.next(".previewWindow");
data = data.substr(data.indexOf("header")+8);
//当匹配不到topic_conten时返回-1 substring 按0处理,既显示整个标题头部
data = data.substring(data.indexOf("<div class=\"topic_content\">"), data.indexOf("<div class=\"topic_buttons\">"));
data = data.replace("hljs.initHighlightingOnLoad();", "");
_this.addClass("btn_id"+btn_id);
_previewWindow.html(data+"<p class='previewWindowEnd'>\
<a class='item_node' href='"+ _href +"' "+ nwe_window +">详细</a>\
<span class='item_node' onclick='\
$(\".btn_id"+ btn_id +"\").click();$(\"html, body\").animate({scrollTop: ($(\".btn_id"+ btn_id++ +"\").offset().top-200)}, 600);'>收起\
</span>\
</p>");
var _next_cell = _previewWindow.next();
_next_cell.css("borderTop", _next_cell.css("borderBottom"));
_this.text("收起");
_previewWindow.slideDown(300);
});
}else{
_this.text("预览");
var _previewWindow = _cell.next(".previewWindow");
setTimeout(function(){
_previewWindow.next().css("borderTop", "none");
_previewWindow.remove();
},800);
_previewWindow.slideUp(300);
}
});
});
//——————————————————————————————————预览及忽略功能——————————————————————————————————
//——————————————————————————————————一键领取登陆奖励——————————————————————————————————
var _mission_btn = $("div#Rightbar > div:nth-of-type(4) a");
$.get(location.origin + "/mission/daily/redeem", function(checkResult) {
if (checkResult.indexOf("每日登录奖励已领取") == -1 && _mission_btn.text() == "领取今日的登录奖励") {
_mission_btn.html("一键领取今日的登录奖励 by vPlus<br/>Take your passion and make it come true. ");
$(".sep20:nth-child(5) , #Rightbar .box:nth-child(4) .inner").css("display","block");
}
});
//Enable Gift ClickOnce Feature from v2excellent.js
//Standalone MIT License from https://gist.github.com/VitoVan/bf00ce496b44c56417a675c521fe67e8
$("a[href=\"/mission/daily\"]")
.attr("id", "gift_v2excellent")
.attr("href", "#")
.click(function() {
$("#gift_v2excellent").text("正在领取......");
var giftLink = (location.origin + "/mission/daily/redeem" + RegExp("/signout(\\?once=[0-9]+)").exec($("div#Top").html())[1]);
$.get(giftLink, function(checkResult) {
var $output = $("<output>").append($.parseHTML(checkResult));
var okSign = $output.find("li.fa.fa-ok-sign");
var keepDays = $output.text().match(/已连续登录 (\d+?) 天/)[0];
//console.log(keepDays);
if (okSign.length > 0) {
$.get(location.origin + "/balance", function(result) {
var amount = $("<output>")
.append($.parseHTML(result))
.find("table>tbody>tr:contains(\"每日登录\"):first>td:nth(2)")
.text();
$("#gift_v2excellent").html(
"成功领取 <strong>" + amount + "</strong> 铜币," + keepDays
);
refreshMoney();
});
}
});
return false;
});
// refresh money方法,来自V2EX源码中的v2ex.js文件
function refreshMoney() {
$.post(location.origin + "/ajax/money", function(data) {
$("#money").html(data);
setTimeout(function() {
$("#Rightbar>.sep20:nth(1)").remove();
$("#Rightbar>.box:nth(1)").remove();
}, 2000);
});
}
//——————————————————————————————————一键领取登陆奖励——————————————————————————————————