Skip to content

Commit 4860956

Browse files
committed
修改文件夹结构
1 parent 0cece40 commit 4860956

File tree

7 files changed

+175
-0
lines changed

7 files changed

+175
-0
lines changed

css/page.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ymlInfo{
2+
background-color: #FFFF99;
3+
padding: 5px;
4+
padding-left:10px;
5+
font-size: 20px;
6+
}

files/attention.mp3

173 KB
Binary file not shown.

images/eye.png

1.52 KB
Loading

scripts/background.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+

2+
var hasInject=false;
3+
4+
chrome.extension.onMessage.addListener(
5+
function(request, sender, sendResponse) {
6+
7+
if(request.message=="btStart_click")
8+
{
9+
stopTimer();
10+
chrome.tabs.insertCSS(null,{file:"css/page.css"});
11+
chrome.tabs.executeScript(null,{file:"scripts/jquery-1.12.1.min.js"});
12+
chrome.tabs.executeScript(null,{file:"scripts/page.js"});
13+
hasInject=true;
14+
}
15+
16+
if(request.message=="PageChangedEvent")
17+
{
18+
chrome.storage.sync.get('emailAddress',function(data){
19+
sendMail(data.emailAddress,'您监控的网页发生了改变','您监控的网页发生了改变,网页地址:'+request.url);
20+
});
21+
22+
playNotification();
23+
}
24+
25+
if(request.message=="btStop_click")
26+
{
27+
stopTimer();
28+
}
29+
30+
});
31+
32+
function stopTimer(){
33+
if(hasInject) //如果之前未注入gs.js,会报错
34+
chrome.tabs.executeScript(null,{code:"stopTimer();"});
35+
}
36+
37+
this.audio=null;
38+
function playNotification(){
39+
if(this.audio==null){
40+
this.audio=new Audio('files/attention.mp3');
41+
this.audio.loop=true;
42+
this.audio.play();
43+
}
44+
45+
var options={
46+
lang: "utf-8",
47+
icon: "eye.png",
48+
body: "您监控的网页内容发生了改变!"
49+
};
50+
var n = new Notification("网页监控助手提醒!", options);
51+
n.onclose=function(d){
52+
if(window.audio!=null)
53+
{
54+
window.audio.pause();
55+
window.audio=null;
56+
}
57+
};
58+
}
59+
60+
function sendMail(receiver,subject,message){
61+
$.post('http://mail.liyumeng.me/SendMail','token=7F830C40B1594B05901779C1D24E2940&receivers='+receiver+'&subject='+subject+'&message='+message,function(dat){console.log(dat);});
62+
}

scripts/jquery-1.12.1.min.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/page.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//todo:判断是否已经添加过ymlInfo
2+
3+
if($('#ymlInfo').length==0)
4+
{
5+
$('body').prepend("<div id='ymlInfo'>网页监听助手准备运行,正在读取配置数据</div>");
6+
}
7+
else{
8+
$('#ymlInfo').html("网页监听助手准备运行,正在读取配置数据");
9+
}
10+
11+
var timer=null;
12+
13+
var timeInterval=600;//刷新的时间间隔
14+
var second=0; //当前经历的秒数
15+
var content="网页监听助手准备运行";
16+
var source=''; //初始网页的内容
17+
var timerCount=0; //目前的抓取次数
18+
var isRunning=false;
19+
20+
chrome.storage.sync.get('timeInterval',function(data){
21+
timeInterval=data.timeInterval;
22+
startTimer();
23+
});
24+
25+
function timeTick(){
26+
var time;
27+
if(second<60){
28+
time=second+"秒";
29+
}
30+
else if(second>=60 && second<3600){
31+
time=(parseInt)(second/60)+"分"+second%60+"秒";
32+
}else if(second>=3600){
33+
time=(parseInt)(second/3600)+"时"+(parseInt)((second%3600)/60)+"分"+(second%3600)%60+"秒";
34+
}
35+
content="网页监听助手已运行"+time+",共刷新"+timerCount+"次,每"+timeInterval+"秒刷新一次。";
36+
$('#ymlInfo').html(content);
37+
if(second%timeInterval==0)
38+
{
39+
$.get(location.href,function(data){
40+
data=data.replace(/<!--[\s\S]+?-->/g,'');
41+
42+
if(source==''){
43+
source=data;
44+
}else if(source.localeCompare(data)!=0){
45+
chrome.extension.sendMessage({message:'PageChangedEvent',url:location.href});
46+
stopTimer();
47+
location.reload();
48+
}
49+
timerCount++;
50+
});
51+
}
52+
second++;
53+
}
54+
function startTimer(){
55+
isRunning=true;
56+
window.onbeforeunload = function(event){
57+
return '当前正在监听网页,确认立即退出?';
58+
};
59+
timer=setInterval(timeTick,1000); //读取时间配置数据
60+
window.scrollTo(0,0);
61+
}
62+
function stopTimer(){
63+
clearInterval(timer);
64+
isRunning=false;
65+
window.onbeforeunload='';
66+
}
67+
68+

scripts/popup.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+

2+
window.onload=function(){
3+
4+
chrome.storage.sync.get('emailAddress',function(data){
5+
document.getElementById('emailAddress').value=data.emailAddress;
6+
});
7+
8+
chrome.storage.sync.get('timeInterval',function(data){
9+
if(data==undefined||data==null)
10+
data='';
11+
document.getElementById('timeInterval').value=data.timeInterval;
12+
});
13+
14+
document.getElementById('btStart').onclick=function(){
15+
chrome.storage.sync.set({timeInterval:document.getElementById('timeInterval').value});
16+
var myemail=document.getElementById("emailAddress").value;
17+
if(fcheckMail(myemail)!==true){
18+
alert('邮箱格式不正确!');
19+
}else{
20+
chrome.storage.sync.set({emailAddress:document.getElementById('emailAddress').value});
21+
chrome.extension.sendMessage({message:'btStart_click'});
22+
}
23+
};
24+
25+
document.getElementById('btStop').onclick=function(){
26+
chrome.extension.sendMessage({message:'btStop_click'});
27+
};
28+
29+
function fcheckMail(myemail){
30+
var reg=/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,5}$/;
31+
var check=reg.test(myemail);
32+
return check;
33+
}
34+
};

0 commit comments

Comments
 (0)