Skip to content

Commit

Permalink
feat: make vera invite id invisible
Browse files Browse the repository at this point in the history
vera 邀请链接中的ID改为隐式传参
  • Loading branch information
zerosoul committed Mar 30, 2021
1 parent 06ac3f0 commit adb2d30
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
29 changes: 29 additions & 0 deletions public/crx/assets/option.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
chrome.storage.sync.get(null, function (items) {
// Notify that we saved.
console.log('all local items', items);
if (items) {
let fragments = document.createDocumentFragment();
Object.keys(items).forEach((key) => {
let item = document.createElement('li');
item.classList.add('item');
item.setAttribute('data-key', key);
item.style.cursor = 'pointer';
item.title = 'Click to remove';
item.innerHTML = items[key];
item.addEventListener('click', (evt) => {
console.log(evt.target);
let currItemEle = evt.target;
let key = currItemEle.dataset.key;
if (key) {
chrome.storage.sync.remove(key, (resp) => {
console.log('remove', resp);
currItemEle.remove();
});
}
});
fragments.appendChild(item);
});
let localList = document.querySelector('.locals');
localList.appendChild(fragments);
}
});
6 changes: 5 additions & 1 deletion public/crx/option.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<title>Portal Option</title>
</head>
<body>
Portal Option Page
<h1>Portal Option Page</h1>
<section>
<ul class="locals"></ul>
</section>
</body>
<script src="./assets/option.js"></script>
</html>
13 changes: 13 additions & 0 deletions public/crx/vera/catch.invite.id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
console.log('catch invite id');
let url = new URL(location.href);
let paths = url.pathname.split('/');
let decodedUrl = decodeURIComponent(paths[paths.length - 1]);
console.log('decodedUrl', decodedUrl);
let id = new URLSearchParams(new URL(decodedUrl).search).get('portal-vera-id');
console.log('catch the id', id);
if (id) {
chrome.storage.sync.set({ pvid: id }, function () {
// Notify that we saved.
console.log('pvid saved', id);
});
}
2 changes: 1 addition & 1 deletion public/crx/vera/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
// const peerObj = await import(peerSrc);
// console.log({ peerObj });
const contentScript = await import(src);
contentScript.main(/* chrome: no need to pass it */);
await contentScript.main(/* chrome: no need to pass it */);
})();
25 changes: 19 additions & 6 deletions public/crx/vera/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Widget from './models/Widget.js';
import Panel from './models/Panel.js';
import { peerKey, installCheckKey } from './models/config.js';
// 初始化挂件
export function main() {
const { pvid } = init();
export async function main() {
const pvid = await init();
const widget = new Widget(pvid);
const inviteHandler = () => {
console.log('portal vera id', pvid);
Expand All @@ -28,8 +28,21 @@ export function main() {
widget.show();
}
const init = () => {
// localStorage.getItem()
document.documentElement.setAttribute(installCheckKey, 1);
let pvid = new URLSearchParams(location.search).get(peerKey) || null;
return { pvid };
return new Promise((resolve) => {
chrome.storage.sync.get(['pvid'], function (res) {
// Notify that we saved.
console.log('pvid from storage', res.pvid);
if (res.pvid) {
chrome.storage.sync.remove('pvid', () => {
console.log('pvid removed');
});
resolve(res.pvid);
} else {
resolve(null);
}
});
});
// document.documentElement.setAttribute(installCheckKey, 1);
// let pvid = new URLSearchParams(location.search).get(peerKey) || null;
// return { pvid };
};
8 changes: 7 additions & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Portal - Home of Your Web Apps",
"short_name": "Portal",
"description": "像积木一样自由组建你的浏览器主页!",
"version": "1.8.22",
"version": "1.9.0",
"manifest_version": 2,
"homepage_url": "https://nicegoodthings.com/",
"permissions": ["tabs", "identity", "history", "storage"],
Expand All @@ -27,6 +27,7 @@
"content_scripts": [
{
"matches": ["<all_urls>"],
"exclude_matches": ["https://nicegoodthings.com/transfer/*"],
"js": [
"crx/vera/assets/authing.min.js",
"crx/vera/assets/tf.min.js",
Expand All @@ -37,6 +38,11 @@
],
"css": ["crx/vera/style.css"],
"run_at": "document_idle"
},
{
"matches": ["https://nicegoodthings.com/transfer/*"],
"js": ["crx/vera/catch.invite.id.js"],
"run_at": "document_idle"
}
],
"web_accessible_resources": ["crx/vera/*"],
Expand Down

0 comments on commit adb2d30

Please sign in to comment.