TODO:
1. 需要改为一个Chrome一个任务. 因为有全局的cookie. 如果开相同的网站会导致cookie混乱.
This commit is contained in:
parent
32fcc9deb3
commit
fa568b53c4
14
background/boss.js
Normal file
14
background/boss.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
console.log("login start")
|
||||||
|
|
||||||
|
|
||||||
|
console.log(window.location.hostname, window.location.pathname);
|
||||||
|
|
||||||
|
if(window.location.hostname === "signup.zhipin.com") {
|
||||||
|
console.log("登录操作", document.getElementsByClassName("link-signin"));
|
||||||
|
document.getElementsByClassName("link-signin")[1].click();
|
||||||
|
|
||||||
|
|
||||||
|
// https://www.zhipin.com/web/geek/recommend
|
||||||
|
} else if ( window.location.pathname == "web/geek/recommend" ) {
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,13 @@ console.log("background");
|
||||||
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
||||||
console.log(msg, sender)
|
console.log(msg, sender)
|
||||||
if(msg.name === "boss") { // boss
|
if(msg.name === "boss") { // boss
|
||||||
chrome.tabs.cre // 创建一个tab 然后注入脚本
|
|
||||||
|
// 创建一个tab 然后注入脚本
|
||||||
|
chrome.tabs.create({ url: "https://signup.zhipin.com/" }, function (tab) {
|
||||||
|
chrome.tabs.executeScript(tab.id, { runAt: "document_end", file: "background/boss.js" });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// sendResponse({});
|
// sendResponse({});
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,8 @@ if( window.location.href === "http://localhost:12203/start") {
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = function(evt) {
|
ws.onmessage = function(evt) {
|
||||||
|
|
||||||
console.log("Received Message: ", JSON.parse(evt.data));
|
console.log("Received Message: ", JSON.parse(evt.data));
|
||||||
|
|
||||||
// if (window.location.hostname !== "www.zhipin.com") {
|
|
||||||
// var handler = window.open("https://www.zhipin.com/")
|
|
||||||
// }
|
|
||||||
chrome.runtime.sendMessage(JSON.parse(evt.data))
|
chrome.runtime.sendMessage(JSON.parse(evt.data))
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = function(evt) {
|
ws.onclose = function(evt) {
|
||||||
|
@ -29,34 +22,7 @@ if( window.location.href === "http://localhost:12203/start") {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// setInterval(function name() {
|
|
||||||
// chrome.runtime.sendMessage({say: "Hello"})
|
|
||||||
|
|
||||||
// fetch("http://localhost:12203/api").then((response)=>{
|
|
||||||
// console.log(response);
|
|
||||||
// console.log(response.json())
|
|
||||||
// })
|
|
||||||
// }, 10000)
|
|
||||||
|
|
||||||
// if(href.startsWith(Host)) {
|
|
||||||
// setInterval(function(){
|
|
||||||
// GetTask();
|
|
||||||
// }, 1);
|
|
||||||
// } else {
|
|
||||||
// setTimeout(function(){
|
|
||||||
// chrome.runtime.sendMessage({ type: BackgroundMsgType.CLOSETAB })
|
|
||||||
// }, 15000)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// function GetTask() {
|
|
||||||
// try {
|
|
||||||
// chrome.runtime.sendMessage({ type: BackgroundMsgType.GETTASK }, function(){});
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log(error);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,6 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
var upGrader = websocket.Upgrader{
|
|
||||||
CheckOrigin: func(r *http.Request) bool {
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var RemoteAddress = ":12203"
|
var RemoteAddress = ":12203"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -34,6 +28,12 @@ func main() {
|
||||||
eg.POST("queue", PostPushQueue)
|
eg.POST("queue", PostPushQueue)
|
||||||
|
|
||||||
eg.GET("task", func(c *gin.Context) {
|
eg.GET("task", func(c *gin.Context) {
|
||||||
|
|
||||||
|
var upGrader = websocket.Upgrader{
|
||||||
|
CheckOrigin: func(r *http.Request) bool {
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}
|
||||||
//升级get请求为webSocket协议
|
//升级get请求为webSocket协议
|
||||||
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -54,7 +54,7 @@ func main() {
|
||||||
//读取ws中的数据
|
//读取ws中的数据
|
||||||
|
|
||||||
log.Println(
|
log.Println(
|
||||||
"123",
|
"start task",
|
||||||
)
|
)
|
||||||
|
|
||||||
task := taskQueue.PopBlock()
|
task := taskQueue.PopBlock()
|
||||||
|
|
|
@ -87,3 +87,21 @@ func TestTaskPostPushQueue(t *testing.T) {
|
||||||
}
|
}
|
||||||
log.Println(string(resp.Content()))
|
log.Println(string(resp.Content()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBoss(t *testing.T) {
|
||||||
|
temp := requests.NewSession().Post("http://localhost" + RemoteAddress + "/queue")
|
||||||
|
task := &Task{
|
||||||
|
Name: "boss",
|
||||||
|
Type: 1,
|
||||||
|
CreateAt: time.Now(),
|
||||||
|
Info: gin.H{
|
||||||
|
"data": "boss",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
temp.SetBodyAuto(task)
|
||||||
|
resp, err := temp.Execute()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
log.Println(string(resp.Content()))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user