链接自动跳转

访问分享链接时自动跳转至下载页面或验证页面

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
// ==UserScript==
// @name        链接自动跳转
// @author      billypon
// @description 访问分享链接时自动跳转至下载页面或验证页面
// @version     1.13.4
// @namespace   http://www.canaansky.com/
// @match       *://www.123wzwp.com/*
// @match       *://158pan.cn/*
// @match       *://www.678pan.net/*
// @match       *://pan.789xz.com/*
// @match       *://www.88pan.cc/*
// @match       *://*.dfpan.com/*
// @match       *://www.feemoo.com/*
// @match       *://www.fxpan.com/*
// @match       *://hiyp.cc/*
// @match       *://www.pipipan.com/*
// @match       *://www.sju.wang/*
// @match       *://www.wwp5.com/*
// @match       *://www.yousuwp.com/*
// @run-at      document-idle
// @grant       none
// ==/UserScript==

var domain = location.hostname.match(/\w+\.\w+$/)[0], path=location.pathname;
console.debug("domain", domain);

function ajax(url, callback) {
	console.debug("ajax request", url);
	var request = new XML*Request();
	request.onreadystatechange = function (event) {
		var target = event.currentTarget;
		if (target.readyState != 4)
			return;
		if (target.status == 200)
			callback(target.responseText);
		else
			console.error("ajax response", target.status, target.responseText);
	};
	request.open("GET", url);
	request.send();
}

function jump(final, replace, search) {
	if (!final && final !== null)
		final = "download";
	if (!replace)
		replace = "down";
	if (!search)
		search = "file";
	var url = path.replace(search, replace);
	if (final) {
		ajax(url, function() {
			jumpFromLink(newLink(url.replace(replace, final)));
		});
	} else {
		jumpFromLink(newLink(url));
	}
}

function getLink(selector) {
	var link = document.querySelector(selector);
	console.debug("link", link);
	return link;
}

function newLink(url) {
	var body = document.body, link = document.createElement("a");
	link.textContent = "download";
	link.href = url;
	body.insertBefore(link, body.children[0]);
	return link;
}

function jumpFromLink(link, click) {
	if (typeof link == "string") {
		link = getLink(link);
		if (!link)
			return;
	}
	if (click)
		link.click();
	else
		location = link.href;
}

function startsWith(search, string) {
	search = search || "/file-";
	return (string || path).slice(0, search.length) == search;
}

switch (domain) {
	case "158pan.cn":
		if (startsWith()) {
			jump();
		}
		break;
	case "123wzwp.com":
	case "678pan.net":
	case "789xz.com":
	case "88pan.cc":
	case "hiyp.cc":
	case "sju.wang":
	case "wwp5.com":
	case "yousuwp.com":
		if (startsWith()) {
			jump(null);
		}
		break;
	case "dfpan.com":
		if (startsWith("/file/down/")) {
			downSubmit(1);
		} else if (startsWith("/fs/") || startsWith("/file/")) {
			dialog_Open2 = function () { };
			show_vcode();
		}
		break;
	case "feemoo.com":
		if (startsWith()) {
			jumpFromLink(document.querySelectorAll(".down_six_main_b a")[1]);
		} else if (startsWith("/fmdown.php")) {
			var button = document.querySelector("#combtn");
			console.debug("button", button);
			if (button)
				button.click();
		}
		break;
	case "fxpan.com":
		if (startsWith("/share/")) {
			var button = document.querySelector("#popup-submit");
			console.debug("button", button);
			if (button)
				setTimeout(function () { button.click() }, 1000);
		} else if (startsWith("/downhtml/")) {
			jumpFromLink(".d3 a");
		} else if (startsWith("/down.php")) {
			var time = document.querySelector("#time");
			console.debug("time", time);
			if (time)
				time.innerHTML = 0;
		}
		break;
	case "pipipan.com":
		[].forEach.call(document.querySelectorAll("body > a"), function (x) {
			if (x.href.indexOf("popjump.php") > 0)
				x.remove();
		});
		if (startsWith("/fs/")) {
			var link = document.querySelector("#free_down_link");
			console.debug("link", link);
			if (link)
				link.click();
		}
		break;
}