Skip to content

Commit 04088a9

Browse files
committed
feat(popup): show url on lower left corner when hovering over link
closes #18
1 parent 54fb5b0 commit 04088a9

File tree

3 files changed

+61
-23
lines changed

3 files changed

+61
-23
lines changed

background/sources/videos/youtube.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export default {
102102
const videoUrl = 'https://www.youtube.com/watch?v=' + item.videoId;
103103

104104
// YouTube videos sometimes don't have thumbnails loaded until
105-
// the page is scrolle down.
105+
// the page is scrolled down.
106106
const thumbnail = 'https://i.ytimg.com/vi/' + item.videoId +
107107
'/mqdefault.jpg?custom=true&w=196&h=110&stc=true&jpg444=true&' +
108108
'jpgq=90&sp=68';

popup/popup.js

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const renderContent = () => {
126126
if (showTabs) {
127127
const $tab = m('a.tab', {
128128
className: group.selected && 'selected',
129-
onclick: () => {
129+
onclick() {
130130
// Remember the scroll position of the last selected group.
131131
const selectedGroup = groups.filter(group => group.selected)[0];
132132
if (selectedGroup) {
@@ -200,10 +200,29 @@ const renderGroupVideo = (group, video) => {
200200
openVideo(video, inNewTab);
201201
};
202202

203+
const link = (selector, opts, children) => {
204+
if (!opts.href) { return m(selector, { href: '#', ...opts}, children); }
205+
let url = opts.href.replace(/^https?:\/\/(www\.)?/, '');
206+
if (opts.target === '_blank') { url += ' ⇗'; }
207+
let el;
208+
return m(selector, {
209+
onmouseenter() {
210+
el = document.createElement('div');
211+
el.className = 'mouseover-link';
212+
el.textContent = url;
213+
document.body.append(el);
214+
},
215+
onmouseleave() {
216+
if (el) { el.remove(); }
217+
},
218+
...opts
219+
}, children);
220+
};
221+
203222
const userView = (user) => {
204223
if (!user) { return null; }
205-
return m((user.url ? 'a' : 'span') + '.user', {
206-
href: user.url || '#',
224+
return link((user.url ? 'a' : 'span') + '.user', {
225+
href: user.url,
207226
target: '_blank',
208227
}, [
209228
user.image ?
@@ -214,11 +233,26 @@ const renderGroupVideo = (group, video) => {
214233
]);
215234
};
216235

236+
const gameView = (game) => {
237+
// Fallback to Twitch gaming if there is a `game.name`,
238+
// but no `game.url` or `game.thumbnail`.
239+
const url = game.url || 'https://www.twitch.tv/directory/game/' +
240+
encodeURIComponent(game.name) + '/videos/week';
241+
const image = game.image ||
242+
'http://static-cdn.jtvnw.net/ttv-boxart/' +
243+
encodeURIComponent(game.name) + '-138x190.jpg';
244+
return link('a.game', {
245+
href: url,
246+
target: '_blank',
247+
'data-title': game.name,
248+
}, m('img.lazy', { 'data-src': image }));
249+
};
250+
217251
const sourceView = (source) => {
218252
return m('span.source', [
219-
m((source.url ? 'a' : 'span') + '.favicon', {
253+
link((source.url ? 'a' : 'span') + '.favicon', {
220254
className: 'source-' + source.source,
221-
href: source.url || '#',
255+
href: source.url,
222256
target: '_blank',
223257
})
224258
].concat(source.users ?
@@ -232,26 +266,16 @@ const renderGroupVideo = (group, video) => {
232266
if (video.silentQueued) { vidClass += '.silent-queued'; }
233267
if (video.playing) { vidClass += '.playing'; }
234268
const $video = m('li.video' + vidClass, [
235-
m('a.left-side', { href: video.url, disabled: true }, [
269+
link('a.left-side', { href: video.url, disabled: true }, [
236270
m('img.lazy', {
237271
'data-src': video.thumbnail || '',
238272
onclick: open.bind(null, false),
239273
}),
240-
video.game ?
241-
m('a.game', {
242-
href: video.game.url || 'https://www.twitch.tv/directory/game/' +
243-
encodeURIComponent(video.game.name) + '/videos/week',
244-
'data-title': video.game.name,
245-
target: '_blank',
246-
}, m('img.lazy', {
247-
'data-src': video.game.image ||
248-
'http://static-cdn.jtvnw.net/ttv-boxart/' +
249-
encodeURIComponent(video.game.name) + '-138x190.jpg',
250-
})) : null,
274+
video.game ? gameView(video.game) : null,
251275
video.length && m('span.length', formatVideoLength(video.length)),
252276
openedVideo && openedVideo.playing && m('span.queue', {
253277
'data-title': 'Add to Queue',
254-
onclick: () => {
278+
onclick() {
255279
const message = {
256280
tabID: tabID,
257281
video: video,
@@ -309,7 +333,7 @@ const renderGroupVideo = (group, video) => {
309333
group.removable && !video.watched && m('a.close', {
310334
href: '#',
311335
'data-title': 'Mark as Watched',
312-
onclick: (e) => {
336+
onclick(e) {
313337
chrome.runtime.sendMessage({
314338
watched: true,
315339
url: video.url,
@@ -348,7 +372,7 @@ const renderGroupVideo = (group, video) => {
348372
e.preventDefault();
349373
},
350374
}, m.trust('×')),
351-
m('a.title', {
375+
link('a.title', {
352376
href: video.url,
353377
onclick: open.bind(null, false)
354378
}, video.title),
@@ -391,7 +415,7 @@ const renderVideos = (group) => {
391415

392416
group.$queueAll = m('div.queue-all', {
393417
className: openedVideo && openedVideo.playing && 'video-is-playing',
394-
onclick: () => {
418+
onclick() {
395419
if (openedVideo && openedVideo.playing) {
396420
chrome.runtime.sendMessage({
397421
queueAll: true,

popup/style.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ a:hover {
291291
width: 392px;
292292
height: 110px;
293293
margin: 4px 0;
294-
overflow: hidden;
295294
}
296295

297296
.close {
@@ -342,6 +341,10 @@ a:hover {
342341
margin-right: 4px;
343342
}
344343

344+
.source {
345+
position: relative;
346+
}
347+
345348
.favicon.source-youtube {
346349
background-image: url(https://www.youtube.com/favicon.ico);
347350
}
@@ -494,3 +497,14 @@ a.close[data-title]:hover:after {
494497
.queue-all.video-is-playing .play-icon {
495498
display: none;
496499
}
500+
501+
.mouseover-link {
502+
position: absolute;
503+
left: 0;
504+
bottom: 0;
505+
padding: 2px;
506+
background: rgba(25, 25, 25, 0.75);
507+
color: #f3f2e1;
508+
font-size: 14px;
509+
z-index: 99;
510+
}

0 commit comments

Comments
 (0)