Skip to content

Commit c2f5717

Browse files
committed
Track time on local files
1 parent 990d2ba commit c2f5717

File tree

4 files changed

+81
-26
lines changed

4 files changed

+81
-26
lines changed

src/assets/css/general.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@
3232
select{
3333
border-color: #ccc;
3434
border-radius: 5px;
35+
}
36+
.w-100{
37+
width: 100%;
38+
}
39+
.w-85{
40+
width: 85%;
3541
}

src/components/TabItem.vue

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
<Favicon :favicon="item.favicon" />
44
<div class="ml-10 flex-grow-2">
55
<div class="first-block">
6-
<p class="url" @click="openUrl(item.url)">{{ item.url }}</p>
6+
<div class="w-85">
7+
<p class="url" @click="openUrl(item.url)">{{ url }}</p>
8+
<div class="d-inline-block" v-html="getBadgeIcon()"></div>
9+
</div>
710
<p class="text-right time">{{ summaryTimeForTab }}</p>
811
</div>
12+
<p v-if="showWarningMessage" class="warning-message">
13+
You cannot open a local file due to security rules
14+
</p>
915
<div class="second-block">
1016
<div class="progress-bar">
1117
<div :style="styleForProgressBar"></div>
@@ -14,7 +20,6 @@
1420
</div>
1521
<p class="sessions">{{ sessions }}</p>
1622
</div>
17-
<div></div>
1823
</div>
1924
</template>
2025

@@ -25,7 +30,7 @@ export default {
2530
</script>
2631

2732
<script lang="ts" setup>
28-
import { computed } from 'vue';
33+
import { computed, ref } from 'vue';
2934
import Favicon from './Favicon.vue';
3035
import { convertSummaryTimeToString } from '../utils/converter';
3136
import { getPercentage } from '../utils/common';
@@ -35,6 +40,21 @@ const props = defineProps<{
3540
item: CurrentTabItem;
3641
}>();
3742
43+
enum TypeOfUrl {
44+
WebSite,
45+
Document,
46+
}
47+
48+
const typeOfUrl = computed(() =>
49+
props.item.url.startsWith('file:') ? TypeOfUrl.Document : TypeOfUrl.WebSite,
50+
);
51+
52+
const url = computed(() =>
53+
typeOfUrl.value == TypeOfUrl.Document
54+
? encodeURI(props.item.url.split('///')[1])
55+
: props.item.url,
56+
);
57+
3858
const sessions = computed(() => {
3959
if (props.item.sessions == 0) return '0 session';
4060
if (props.item.sessions > 1) return `${props.item.sessions} sessions`;
@@ -51,8 +71,16 @@ const percent = computed(() =>
5171
const styleForProgressBar = computed(() => `width: ${percent.value}%`);
5272
5373
function openUrl(url: string) {
54-
if (!url.startsWith('http')) url = `https://${url}`;
55-
window.open(url, '_blank');
74+
if (typeOfUrl.value != TypeOfUrl.Document && !url.startsWith('http')) {
75+
url = `https://${url}`;
76+
window.open(url, '_blank');
77+
} else showWarningMessage.value = true;
78+
}
79+
80+
const showWarningMessage = ref<boolean>();
81+
82+
function getBadgeIcon() {
83+
if (typeOfUrl.value == TypeOfUrl.Document) return `<span class="badge-document">Document</span>`;
5684
}
5785
</script>
5886

@@ -73,6 +101,9 @@ function openUrl(url: string) {
73101
font-size: 15px;
74102
font-weight: 600;
75103
cursor: pointer;
104+
overflow-wrap: anywhere;
105+
max-width: 80%;
106+
display: inline-block;
76107
}
77108
.tab-item .url:hover {
78109
color: #1a0dab;
@@ -113,4 +144,15 @@ function openUrl(url: string) {
113144
.tab-item .sessions {
114145
margin: 0 0 0 5px;
115146
}
147+
.tab-item ::v-deep span.badge-document {
148+
border-radius: 6px;
149+
background-color: #0043ff9e;
150+
padding: 3px 7px;
151+
font-size: 11px;
152+
color: white;
153+
font-weight: 600;
154+
}
155+
.tab-item .warning-message {
156+
color: grey;
157+
}
116158
</style>
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
export function extractHostname(url:string | undefined):string {
2-
let hostname;
3-
if (url == undefined) return '';
1+
export function extractHostname(url: string | undefined): string {
2+
let hostname;
3+
if (url == undefined) return '';
44

5-
if (url.indexOf("//") > -1) {
6-
hostname = url.split('/')[2];
7-
}
8-
else {
9-
hostname = url.split('/')[0];
10-
}
5+
if (url.startsWith('file:')) {
6+
return url;
7+
}
118

12-
hostname = hostname.split(':')[0];
13-
hostname = hostname.split('?')[0];
9+
if (url.indexOf('//') > -1) {
10+
hostname = url.split('/')[2];
11+
} else {
12+
hostname = url.split('/')[0];
13+
}
1414

15-
return hostname;
16-
}
15+
hostname = hostname.split(':')[0];
16+
hostname = hostname.split('?')[0];
17+
18+
return hostname;
19+
}

src/compositions/valid-page.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import Browser from 'webextension-polyfill';
22

3-
export function isValidPage(tab: Browser.Tabs.Tab | undefined): boolean{
4-
if (tab == null || tab == undefined || !tab.url || !tab.id) return false;
3+
export function isValidPage(tab: Browser.Tabs.Tab | undefined): boolean {
4+
if (tab == null || tab == undefined || !tab.url || !tab.id) return false;
55

6-
if ((!tab.url.startsWith('http:') && !tab.url.startsWith('https:'))
7-
|| tab.url.startsWith('chrome://')
8-
|| tab.url.startsWith('chrome-extension://'))
9-
return false;
10-
return true;
11-
}
6+
if (
7+
(!tab.url.startsWith('http:') &&
8+
!tab.url.startsWith('https:') &&
9+
!tab.url.startsWith('file:')) ||
10+
tab.url.startsWith('chrome://') ||
11+
tab.url.startsWith('chrome-extension://')
12+
)
13+
return false;
14+
return true;
15+
}

0 commit comments

Comments
 (0)