Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
修改匹配及注入方式,添加设定选项方便自行添加需要启用的网站
  • Loading branch information
ckx000 authored Sep 5, 2021
1 parent 7d1c567 commit 643b07e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 19 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
# 使用注意
整个代码打包下载回去,使用chrome扩展 加载已解压的扩展程序来使用

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

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

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

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

# 其他
不知道原代码出处和作者,有知情者请联系我
不知道原代码出处和作者,有知情者请联系我,感谢不知名大佬的代码
2 changes: 1 addition & 1 deletion _locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"message": "Cookies获取助手"
},
"description": {
"message": "帮助开发者方便的获取到HTTP ONLY的Cookies"
"message": "帮助开发者方便的获取到供私有签到平台上使用的Cookies"
}
}
29 changes: 26 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
var listurlarr,format=function(a){
var b = (a||"192.168.0.111");
listurlarr=b.split(/[\s\n]/);
console.log("init",listurlarr);
},urlcheck=function(a){
for(var l in listurlarr){
if(a.indexOf(listurlarr[l])>=0){
console.log(true);
return true
}
}
return false
};
chrome.storage.sync.get('targeturl',function (a){
format(a.targeturl);
});
chrome.storage.onChanged.addListener(function(changes, areaName){
if(changes.hasOwnProperty("targeturl")){
format(changes.targeturl.newValue);
//console.log("true");
}
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {//tab页面刷新事件
//console.log(tab);
//if (changeInfo.status === 'loading' && (tab.url.indexOf("在下方填写自己的平台ip地址") != -1 ||tab.url.indexOf("或者是域名地址") != -1)) {
if (changeInfo.status === 'loading' && (tab.url.indexOf("192.168.0.229") != -1 ||tab.url.indexOf("abc.myds.me") != -1)) {
if (changeInfo.status === 'loading' && urlcheck(tab.url)) {
console.log(tab);
chrome.tabs.executeScript({file: "js/cookie.js"});
if (!chrome.runtime.onConnect.hasListeners()) {
chrome.runtime.onConnect.addListener(function(port) {
console.assert(port.name == "get_cookie");
Expand Down
7 changes: 4 additions & 3 deletions js/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ function onload(func) {
}

onload(function() {
console.log("onload");
console.log("getcookieload");
document.body.setAttribute("get-cookie", "true");
window.postMessage("start", "*");
window.postMessage("start", "*");//预传递,测试自动填入功能
window.addEventListener('click', function(event) {
var export_btn = event.target;
var port = chrome.runtime.connect({name: "get_cookie"});
Expand All @@ -22,7 +22,8 @@ onload(function() {
port.onMessage.addListener(function(msg) {
if (window.confirm('你确定要此网站获取你' + site + '的Cookies么?')) {
export_btn.setAttribute("data-cookie", JSON.stringify(msg));
window.postMessage(msg, "*");
//console.log(msg);
window.postMessage(msg, "*");//传递给页面消息,让网页填上cookies数据
} else {
return false;
}
Expand Down
16 changes: 9 additions & 7 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [ {
"js": ["js/cookie.js" ],
"matches": [ "http://192.168.0.229/*","http://abc.myds.me/*"]
} ],
"default_locale": "en",
"default_locale": "zh_CN",
"description": "__MSG_description__",
"icons": {
"32": "images/logo32.png",
"16": "images/logo16.png",
"48": "images/logo48.png",
"128": "images/logo128.png"
},
"options_ui":{
"page": "options/options.html",
"open_in_tab": false,
"chrome_style": true
},
"manifest_version": 2,
"permissions": [ "cookies", "tabs", "http://*/*", "https://*/*"],
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyqfMOCKmBFCyUDyIA2BKpJJhZnwYd4xBvu3B9ppdOQ98LYtK8pEcSGLpyhuzyiwtmlm9faAimQbCjelk1NGs/rkOTQFeC+X4TI4soujKA3v4vW1+QACchIiLCVel3nIJzU2Xq1vdbgP74wMWZ766xUqP4y6nNnGOaFvAWK+CuXPXOlNxbQ5ipNGUDR3MLz+PuLh1HtaMjtXWeJ5ailm8Rhuax9wAo1FcE/DwiRTbv11et/2MTda7Xo/3Z8S7Sc1gDbwHGFYRT931A3a+FUTTwiEDPP4LZmjBxgyknaBnj1Zh46kNYdaN1LFq3/0HloHq/E6B8rHXozqVHucaob+oMwIDAQAB",
"permissions": [ "cookies", "storage", "tabs", "\u003Call_urls>"],
"name": "__MSG_appName__",
"version": "0.1.0"
"version": "1.0.0"
}
16 changes: 16 additions & 0 deletions options/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>设定匹配地址</title></head>
<body>

<p>填入需要加载插件的域名或ip地址: 一行一个</p>
<p>例如:只用ip访问的自己家内网的nas输入 192.168.0.111<br />
或者用域名访问的签到平台 qiandao.today</p>
<textarea id="tgurl" rows="6">
</textarea>
<div><button id="save">Save</button><span id="status"></span></div>
<button id="reset" style="display: none;">Reset</button>

<script src="options.js"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions options/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 通过 chrome.storage 保存
function saveOptions() {
var tgurl = document.getElementById('tgurl').value;
//console.log(tgurl,typeof tgurl);
chrome.storage.sync.set({
targeturl: tgurl,
}, () => {
// 更新状态文本
var status = document.getElementById('status');
status.textContent = '已保存';
// 隐藏状态文本
setTimeout(() => {
status.textContent = '';
}, 500);
})
}
function resetOptions() {
chrome.storage.sync.remove('targeturl',() => {
var status = document.getElementById('status');
status.textContent = '已重置';
setTimeout(() => {
status.textContent = '';
}, 500);
})
}
// 加载数据
function loadOptions() {
chrome.storage.sync.get(
'targeturl',(items) => {
document.getElementById('tgurl').value = (items.targeturl||"192.168.0.111");//console.log(items.targeturl,typeof items.targeturl);
});
}
document.addEventListener('DOMContentLoaded', loadOptions);
document.getElementById('save').addEventListener('click', saveOptions);
document.getElementById('reset').addEventListener('click', resetOptions);

0 comments on commit 643b07e

Please sign in to comment.