-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_script.js
More file actions
103 lines (85 loc) · 3.15 KB
/
content_script.js
File metadata and controls
103 lines (85 loc) · 3.15 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
function requestUnlockPage(key, unlock_url_regexp) {
console.log("key : " + key);
console.log("unlock url : " + unlock_url_regexp);
chrome.extension.sendMessage(null, { action:"request_unlock_page", key:key, unlock_url_regexp:unlock_url_regexp }, function(response) {
console.log("unlock response : " + response);
});
};
function requestRapPass(key, rapPassMethod) {
console.log("base url for rap : " + key);
chrome.extension.sendMessage(null, { action:"request_fetch_rap_pass", key:key }, function(response) {
console.log("fetched rap pass : " + response);
rapPassMethod(response);
});
};
/************************************************
* Util
************************************************/
function getParamsFromUrl(str) {
var p = new Object();
var hashes = (str.indexOf('?')<0) ? new Array(): ((str.split('?'))[1].split('#'))[0].split('&');
for(var i = 0; i <hashes.length; i++) {
var hash = (hashes[i].indexOf('=')<0) ? new Array(hashes[i],'') : hashes[i].split('=');
p[hash[0]] = hash[1];
}
return p;
};
/************************************************
* www.exploader.net and 2dbook.com
************************************************/
function exploaderKey() {
var params_ = getParamsFromUrl(unescape($("div#acces a").first()[0].href));
var key_ = params_["url"];
return key_;
}
function exploaderRapPass() {
var key_ = exploaderKey();
var location_ = document.location.href;
if($("div#acces a").first().text() == "URLロック元に戻る") {
requestRapPass(key_, function(pass){ $("input[name='exp_password']").val(pass); });
} else if($("input.dlkey").is("*")) {
requestRapPass(key_, function(pass){ $("input[name='exp_password']").val(pass); });
} else if(document.location.href.indexOf("www.exploader.net/download") != -1) {
requestUnlockPage(key_, location_+"\\?session=[\\w]+");
}
}
function twodbookKey() {
var key_ = $("div.info a[target='_blank']").first()[0].href;
return key_;
}
function twodbookRapPass() {
var key_ = twodbookKey();
var location_ = document.location.href;
if($("p.status").text() == "データはロックされていません") {
requestRapPass(key_, function(pass){ $("input#dlkey").val(pass); });
} else if(document.location.href.indexOf("2dbook.com/books") != -1) {
requestUnlockPage(key_, location_+"/[\\w.]+");
}
}
$(function() {
if(document.domain == "www.exploader.net") {
exploaderRapPass();
} else if (document.domain == "2dbook.com") {
twodbookRapPass();
}
});
/************************************************
* Listener
************************************************/
function onMessageListener(message, sender, sendResponse) {
switch (message.action) {
case "get_key_url":
var key_url_ = "";
if(document.domain == "www.exploader.net") {
key_url_ = exploaderKey();
} else if (document.domain == "2dbook.com") {
key_url_ = twodbookKey();
}
sendResponse(key_url_);
return;
default:
break;
}
sendResponse("uncatch action onMessageListener : " + message.action);
};
chrome.extension.onMessage.addListener(onMessageListener);