Skip to content

Commit 643b07e

Browse files
authored
v1.0.0
修改匹配及注入方式,添加设定选项方便自行添加需要启用的网站
1 parent 7d1c567 commit 643b07e

File tree

7 files changed

+96
-19
lines changed

7 files changed

+96
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
# 使用注意
1212
整个代码打包下载回去,使用chrome扩展 加载已解压的扩展程序来使用
1313

14-
注意!使用前请自己打开background.js和manifest.json文件,
14+
或者去Releases下载打包好的crx文件。(然而还是无法直接使用,因为付不起5刀),将crx扩展名改为zip。解压、同上使用
1515

16-
` "matches": [ "http://192.168.0.229/*","http://abc.myds.me/*"]`
16+
注意!使用前请打开扩展详情里打开扩展设置“扩展程序选项”,根据提示填入ip或域名
1717

18-
替换修改其中的ip字串符和域名字串为需要使用的签到平台的(任意即可)
1918

20-
以后有时间(能力)的话会写成扩展里填写的参数。现在咕咕咕
19+
# 更新
20+
v1.0.0 修改匹配及注入方式,添加设定选项方便自行添加需要启用的网站
2121

2222
# 其他
23-
不知道原代码出处和作者,有知情者请联系我
23+
不知道原代码出处和作者,有知情者请联系我,感谢不知名大佬的代码

_locales/zh_CN/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"message": "Cookies获取助手"
44
},
55
"description": {
6-
"message": "帮助开发者方便的获取到HTTP ONLY的Cookies"
6+
"message": "帮助开发者方便的获取到供私有签到平台上使用的Cookies"
77
}
88
}

background.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1-
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
1+
var listurlarr,format=function(a){
2+
var b = (a||"192.168.0.111");
3+
listurlarr=b.split(/[\s\n]/);
4+
console.log("init",listurlarr);
5+
},urlcheck=function(a){
6+
for(var l in listurlarr){
7+
if(a.indexOf(listurlarr[l])>=0){
8+
console.log(true);
9+
return true
10+
}
11+
}
12+
return false
13+
};
14+
chrome.storage.sync.get('targeturl',function (a){
15+
format(a.targeturl);
16+
});
17+
chrome.storage.onChanged.addListener(function(changes, areaName){
18+
if(changes.hasOwnProperty("targeturl")){
19+
format(changes.targeturl.newValue);
20+
//console.log("true");
21+
}
22+
});
23+
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {//tab页面刷新事件
224
//console.log(tab);
3-
//if (changeInfo.status === 'loading' && (tab.url.indexOf("在下方填写自己的平台ip地址") != -1 ||tab.url.indexOf("或者是域名地址") != -1)) {
4-
if (changeInfo.status === 'loading' && (tab.url.indexOf("192.168.0.229") != -1 ||tab.url.indexOf("abc.myds.me") != -1)) {
25+
if (changeInfo.status === 'loading' && urlcheck(tab.url)) {
26+
console.log(tab);
27+
chrome.tabs.executeScript({file: "js/cookie.js"});
528
if (!chrome.runtime.onConnect.hasListeners()) {
629
chrome.runtime.onConnect.addListener(function(port) {
730
console.assert(port.name == "get_cookie");

js/cookie.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ function onload(func) {
77
}
88

99
onload(function() {
10-
console.log("onload");
10+
console.log("getcookieload");
1111
document.body.setAttribute("get-cookie", "true");
12-
window.postMessage("start", "*");
12+
window.postMessage("start", "*");//预传递,测试自动填入功能
1313
window.addEventListener('click', function(event) {
1414
var export_btn = event.target;
1515
var port = chrome.runtime.connect({name: "get_cookie"});
@@ -22,7 +22,8 @@ onload(function() {
2222
port.onMessage.addListener(function(msg) {
2323
if (window.confirm('你确定要此网站获取你' + site + '的Cookies么?')) {
2424
export_btn.setAttribute("data-cookie", JSON.stringify(msg));
25-
window.postMessage(msg, "*");
25+
//console.log(msg);
26+
window.postMessage(msg, "*");//传递给页面消息,让网页填上cookies数据
2627
} else {
2728
return false;
2829
}

manifest.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
"scripts": ["background.js"],
44
"persistent": false
55
},
6-
"content_scripts": [ {
7-
"js": ["js/cookie.js" ],
8-
"matches": [ "http://192.168.0.229/*","http://abc.myds.me/*"]
9-
} ],
10-
"default_locale": "en",
6+
"default_locale": "zh_CN",
117
"description": "__MSG_description__",
128
"icons": {
139
"32": "images/logo32.png",
1410
"16": "images/logo16.png",
1511
"48": "images/logo48.png",
1612
"128": "images/logo128.png"
1713
},
14+
"options_ui":{
15+
"page": "options/options.html",
16+
"open_in_tab": false,
17+
"chrome_style": true
18+
},
1819
"manifest_version": 2,
19-
"permissions": [ "cookies", "tabs", "http://*/*", "https://*/*"],
20+
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyqfMOCKmBFCyUDyIA2BKpJJhZnwYd4xBvu3B9ppdOQ98LYtK8pEcSGLpyhuzyiwtmlm9faAimQbCjelk1NGs/rkOTQFeC+X4TI4soujKA3v4vW1+QACchIiLCVel3nIJzU2Xq1vdbgP74wMWZ766xUqP4y6nNnGOaFvAWK+CuXPXOlNxbQ5ipNGUDR3MLz+PuLh1HtaMjtXWeJ5ailm8Rhuax9wAo1FcE/DwiRTbv11et/2MTda7Xo/3Z8S7Sc1gDbwHGFYRT931A3a+FUTTwiEDPP4LZmjBxgyknaBnj1Zh46kNYdaN1LFq3/0HloHq/E6B8rHXozqVHucaob+oMwIDAQAB",
21+
"permissions": [ "cookies", "storage", "tabs", "\u003Call_urls>"],
2022
"name": "__MSG_appName__",
21-
"version": "0.1.0"
23+
"version": "1.0.0"
2224
}

options/options.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head><meta charset="UTF-8"><title>设定匹配地址</title></head>
4+
<body>
5+
6+
<p>填入需要加载插件的域名或ip地址: 一行一个</p>
7+
<p>例如:只用ip访问的自己家内网的nas输入 192.168.0.111<br />
8+
或者用域名访问的签到平台 qiandao.today</p>
9+
<textarea id="tgurl" rows="6">
10+
</textarea>
11+
<div><button id="save">Save</button><span id="status"></span></div>
12+
<button id="reset" style="display: none;">Reset</button>
13+
14+
<script src="options.js"></script>
15+
</body>
16+
</html>

options/options.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// 通过 chrome.storage 保存
2+
function saveOptions() {
3+
var tgurl = document.getElementById('tgurl').value;
4+
//console.log(tgurl,typeof tgurl);
5+
chrome.storage.sync.set({
6+
targeturl: tgurl,
7+
}, () => {
8+
// 更新状态文本
9+
var status = document.getElementById('status');
10+
status.textContent = '已保存';
11+
// 隐藏状态文本
12+
setTimeout(() => {
13+
status.textContent = '';
14+
}, 500);
15+
})
16+
}
17+
function resetOptions() {
18+
chrome.storage.sync.remove('targeturl',() => {
19+
var status = document.getElementById('status');
20+
status.textContent = '已重置';
21+
setTimeout(() => {
22+
status.textContent = '';
23+
}, 500);
24+
})
25+
}
26+
// 加载数据
27+
function loadOptions() {
28+
chrome.storage.sync.get(
29+
'targeturl',(items) => {
30+
document.getElementById('tgurl').value = (items.targeturl||"192.168.0.111");//console.log(items.targeturl,typeof items.targeturl);
31+
});
32+
}
33+
document.addEventListener('DOMContentLoaded', loadOptions);
34+
document.getElementById('save').addEventListener('click', saveOptions);
35+
document.getElementById('reset').addEventListener('click', resetOptions);

0 commit comments

Comments
 (0)