-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpreviewTile.js
107 lines (91 loc) · 3.65 KB
/
previewTile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
const extensionUrl = chrome.runtime.getURL('');
const emptyScreen = '/img/no_preview_available.png';
const chromeStore = '/img/Chrome-Store-Logo.png';
const extension = '/img/Chrome-Extension.jpg';
// eslint-disable-next-line no-redeclare,no-unused-vars,@typescript-eslint/no-unused-vars
function drawPreviewTile(tile, options) {
let divLine = document.createElement('div');
divLine.classList.add('mx-auto');
divLine.innerHTML =
'<div class="card">\n' +
'<a ' + (!options || !options.noHref ? 'href="' + tile.url + '"' : '') + ' target="_blank" class="card-img-a">' +
` <img class="card-img-top ${options && options.popuped ? 'popuped' : ''}">\n` +
'</a>' +
' <div class="card-body">\n' +
(options && options.close ? ' <img src="/img/Close_Icon_24.png" class="delete-btn" title="Close Tab">' : '') +
(!options || !options.noTitle ? ' <h5 class="card-title">' + '<a href="' + tile.url + '" target="_blank" nativeTabId="' + tile.nativeTabId + '">' + (tile.title ? tile.title : parseUrlParam(tile.url, 'title')) + '</a>' +
'</h5>\n' : '') +
(!options || !options.noUrl ? '<p class="card-text">' +
'<a href="' + tile.url + '" target="_blank" style="color: #999;">' + (tile.url.indexOf(extensionUrl) === 0 ? new URLSearchParams(tile.url).get('url') : tile.url) + '</a>' +
'</p>\n':'') +
(options && options.noTime ? '' : '<p class="card-text time">' + timeConverter(tile.timestamp) + '</p>\n') +
' </div>\n' +
'</div>';
let img = divLine.getElementsByTagName('img')[0];
let tmpF = function(imgElement) {
let timeoutId;
$(imgElement).hover(function() {
//if (imgElement.src.indexOf('chrome-extension://') == 0)
// return;
if (!timeoutId) {
timeoutId = window.setTimeout(function() {
timeoutId = null; // EDIT: added this line
if (!imgElement.classList.contains('clicked'))
imgElement.classList.add('zoom');
}, 1000);
$('.card-img-top').each((_, imgDomElement) => {
if (imgDomElement !== imgElement) {
if (imgDomElement.classList.contains('zoom')) {
imgDomElement.classList.remove('zoom');
imgDomElement.removeAttribute('style');
}
}
});
}
},
function() {
if (timeoutId) {
window.clearTimeout(timeoutId);
timeoutId = null;
} else {
//imgElement.classList.remove('zoom');
}
imgElement.classList.remove('zoom');
imgElement.removeAttribute('style');
});
if (tile.tabId != null && tile.sessionId != null) {
void chrome.runtime.sendMessage({ method: '[TS:getScreen]', tabId: tile.tabId, sessionId: tile.sessionId /*parseUrlParam('sessionId')*/ }).then(({scr}) => {
if (scr != null)
imgElement.src = scr;
else if (tile.url.indexOf('https://chrome.google.com/webstore') === 0)
imgElement.src = chromeStore;
else if (tile.url.indexOf('chrome://extensions') === 0 || tile.url.indexOf('chrome-extension://') === 0)
imgElement.src = extension;
else
imgElement.src = emptyScreen;
});
} else {
imgElement.src = emptyScreen;
}
};
tmpF(img);
return divLine;
}
function timeConverter(UNIX_timestamp) {
let a = new Date(UNIX_timestamp);
let months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
let year = a.getFullYear();
let month = months[a.getMonth()];
let date = a.getDate();
let hour = a.getHours();
let min = a.getMinutes();
let sec = a.getSeconds();
month = (month < 10 ? '0' : '') + month;
date = (date < 10 ? '0' : '') + date;
hour = (hour < 10 ? '0' : '') + hour;
min = (min < 10 ? '0' : '') + min;
sec = (sec < 10 ? '0' : '') + sec;
let time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec;
return time;
}