Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Candinya committed Jul 31, 2021
2 parents 113916a + ea1d87a commit e16f0b3
Show file tree
Hide file tree
Showing 34 changed files with 891 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build test pack

on:
push:
branches: [develop]
branches: [develop, release/*]
pull_request:
branches: [develop]

Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "re-id",
"version": "0.2.1",
"version": "0.2.2",
"description": "The first step to own your own data.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -42,31 +42,31 @@
"vue-moment": "4.1.0"
},
"devDependencies": {
"@babel/core": "7.14.6",
"@babel/preset-env": "7.14.7",
"@babel/core": "7.14.8",
"@babel/preset-env": "7.14.8",
"@types/chrome": "0.0.148",
"@types/lodash": "4.14.171",
"@vue/compiler-sfc": "3.1.5",
"autoprefixer": "10.3.1",
"babel-loader": "8.2.2",
"copy-webpack-plugin": "9.0.1",
"css-loader": "6.1.0",
"cssnano": "5.0.6",
"css-loader": "6.2.0",
"cssnano": "5.0.7",
"html-webpack-plugin": "5.3.2",
"husky": "7.0.1",
"less-loader": "10.0.1",
"lint-staged": "11.0.1",
"postcss": "8.3.5",
"lint-staged": "11.1.1",
"postcss": "8.3.6",
"postcss-loader": "6.1.1",
"prettier": "2.3.2",
"tailwindcss": "2.2.4",
"tailwindcss": "2.2.7",
"terser-webpack-plugin": "5.1.4",
"ts-loader": "9.2.3",
"ts-loader": "9.2.4",
"url-loader": "4.1.1",
"vue-loader": "16.3.1",
"vue-loader": "16.3.3",
"vue-router": "4.0.10",
"vue-style-loader": "4.1.3",
"webpack": "5.45.1",
"webpack": "5.46.0",
"webpack-cli": "4.7.2"
}
}
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Re: ID",
"version": "0.2.1",
"version": "0.2.2",

"action": {
"default_popup": "popup.html",
Expand Down
4 changes: 2 additions & 2 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const supportedHost = ['twitter.com'];

function setIcon(url: string) {
const host = new URL(url).host;
if (supportedHost.indexOf(host) !== -1) {
const host = new URL(url);
if (host.host === chrome.runtime.id || supportedHost.includes(host.host)) {
chrome.action.setIcon({
path: {
'16': 'images/icon16a.png',
Expand Down
38 changes: 38 additions & 0 deletions src/common/multi-accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export type UserAccount = {
avatar: string;
name: string;
address: string;
privateKey?: string;
};

async function GetAccounts() {
return new Promise<UserAccount[] | null>((resolve) => {
chrome.storage.sync.get(['rss3accounts'], (accountsShowList) => {
if (accountsShowList?.['rss3accounts']) {
resolve(<UserAccount[]>accountsShowList['rss3accounts']);
} else {
resolve(null);
}
});
});
}

export default {
get: GetAccounts,
set: async (account: UserAccount) => {
const accountsList: UserAccount[] = (await GetAccounts()) || [];
const userIndex = accountsList.findIndex((user) => {
return user.privateKey === account.privateKey;
});
if (userIndex === -1) {
// Do not exist
accountsList.push(account);
} else {
// Update user info
accountsList[userIndex] = account;
}
await chrome.storage.sync.set({
rss3accounts: accountsList,
});
},
};
2 changes: 1 addition & 1 deletion src/components/ItemList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Vue, Options } from 'vue-class-component';
viewType: String,
},
})
export default class CollapseMenu extends Vue {}
export default class ItemList extends Vue {}
</script>

<style lang="postcss">
Expand Down
112 changes: 112 additions & 0 deletions src/components/SingleUser.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<template>
<div class="user-container" :class="$props.viewType">
<div class="user">
<img class="avatar" :src="$props.user.avatar" />
<span class="username">{{ $props.user.name }}</span>
</div>
<div class="address">
<span>
{{
$props.viewType === 'popup'
? `${$props.user.address.substring(0, 3)}***${$props.user.address.substring(
$props.user.address.length - 3,
)}`
: $props.user.address
}}
</span>
</div>
</div>
</template>

<script lang="ts">
import { Vue, Options } from 'vue-class-component';
@Options({
props: {
viewType: String,
user: {
avatar: String,
name: String,
address: String,
},
},
})
export default class SingleUser extends Vue {}
</script>

<style scoped lang="postcss">
@layer components {
.user-container {
@apply duration-200 relative cursor-pointer;
&:hover {
@apply bg-gray-bg;
}
> * {
@apply inline-block;
> * {
@apply inline-flex items-center;
}
}
> .user {
> span.username {
@apply font-semibold;
}
}
> .address {
@apply absolute right-4 text-gray-700;
&::after {
@apply ml-1 text-primary fill-current;
content: '\279C';
}
}
&.popup {
@apply p-2 text-xs;
img.avatar {
@apply w-10 h-10 rounded;
}
> .user {
> span.username {
@apply ml-2;
}
}
> .address {
@apply text-xs;
> span {
@apply h-10;
}
}
}
&.options {
@apply p-4 text-lg;
img.avatar {
@apply w-14 h-14 rounded;
}
> .user {
> span.username {
@apply ml-4;
}
}
> .address {
@apply text-xs;
> span {
@apply h-14;
}
}
}
}
}
</style>
38 changes: 38 additions & 0 deletions src/components/UserList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<div
class="user-list"
:class="{
popup: $props.viewType === 'popup',
options: $props.viewType === 'options',
}"
>
<slot />
</div>
</template>

<script lang="ts">
import { Vue, Options } from 'vue-class-component';
@Options({
props: {
viewType: String,
},
})
export default class UserList extends Vue {}
</script>

<style lang="postcss">
@layer components {
.user-list {
@apply flex flex-col divide-y divide-black divide-opacity-10 overflow-y-scroll;
&.popup {
@apply w-55 h-60;
}
&.options {
@apply w-180 h-160;
}
}
}
</style>
88 changes: 48 additions & 40 deletions src/content-script/handlers/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,51 @@ async function getRSS3BindAddress(username: string): Promise<string | undefined>
}

async function mountRSS3FollowButton(ele: Element) {
let followStatus = false;
function updateFollowButtonStatus(fostat: boolean) {
const twiBtnFoUut = document.getElementById('reid-follow');
if (twiBtnFoUut !== null) {
if (fostat) {
twiBtnFoUut.classList.add('active');
} else {
twiBtnFoUut.classList.remove('active');
}
}
}

async function updateFollowStatus(status: boolean) {
if (typeof userAddr !== 'undefined') {
if (status) {
await rss3?.link.post('following', userAddr);
} else {
await rss3?.link.delete('following', userAddr);
}
}

updateFollowButtonStatus(status);

await rss3?.persona.sync();
}

const followToggleButton = ele.querySelector('[data-testid$=follow]');
let followOnTwitterStatus = followToggleButton?.getAttribute('data-testid')?.includes('-unfollow') || false;

const rss3 = await RSS3.get();

let userAddr = await getRSS3BindAddress(window.location.pathname.replace('/', ''));
if (rss3 && typeof userAddr !== 'undefined') {
let followOnRSS3Status = false;

// User has joined and bind username

let followList = await rss3.links.get(rss3.persona.id, 'following');
console.log(followList);

if (typeof followList === 'undefined') {
followList = await rss3.links.post({
type: 'following',
});
}
if (followList?.list?.includes(userAddr)) {
followStatus = true;
followOnRSS3Status = true;
}

if (document.getElementById('reid-follow-button-toggle') === null) {
Expand All @@ -171,47 +198,28 @@ async function mountRSS3FollowButton(ele: Element) {

ele.insertAdjacentHTML('beforebegin', TwitterButtonFollow);

{
// Listen events

function updateFollowStatusClass(fostat: boolean) {
const twiBtnFoUut = document.getElementById('reid-follow');
if (twiBtnFoUut !== null) {
if (fostat) {
twiBtnFoUut.classList.add('active');
} else {
twiBtnFoUut.classList.remove('active');
}
}
}

async function toggleFollowStatus() {
followStatus = !followStatus;

if (typeof userAddr !== 'undefined') {
if (followStatus) {
await rss3?.link.post('following', userAddr);
} else {
await rss3?.link.delete('following', userAddr);
}
}
console.log(followList);
// Listen events

await rss3?.persona.sync();
const twiBtnFoToUut = document.getElementById('reid-follow-button-toggle');
twiBtnFoToUut?.addEventListener('click', async () => {
followOnRSS3Status = !followOnRSS3Status;
await updateFollowStatus(followOnRSS3Status);
});

updateFollowStatusClass(followStatus);
}
// Sync follow / unfollow
followToggleButton?.addEventListener('click', async () => {
followOnTwitterStatus = !followOnTwitterStatus;
followOnRSS3Status = !followOnRSS3Status;
await updateFollowStatus(followOnRSS3Status);
});

const twiBtnFoToUut = document.getElementById('reid-follow-button-toggle');
if (twiBtnFoToUut !== null) {
twiBtnFoToUut.addEventListener('click', () => {
toggleFollowStatus();
});
}
setTimeout(() => {
updateFollowStatusClass(followStatus);
}, 0);
if (followOnTwitterStatus !== followOnRSS3Status) {
// Sync follow on RSS3
followOnRSS3Status = followOnTwitterStatus;
await updateFollowStatus(followOnRSS3Status);
}

updateFollowButtonStatus(followOnRSS3Status);
}
}
}
Expand Down

0 comments on commit e16f0b3

Please sign in to comment.