Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental: Recently Closed Tabs #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"OtherBookmarks": {
"message": "Other Bookmarks"
},
"RecentlyClosed": {
"message": "Recently closed tabs"
},
"optionBgDefault": {
"message": "Default"
},
Expand Down
4 changes: 3 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
},
"permissions": [
"bookmarks",
"storage"
"storage",
"sessions",
"tabs"
],
"options_ui": {
"page": "options.html"
Expand Down
18 changes: 12 additions & 6 deletions newTab.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ a {
.window .border .create_button {
float: left;
}
#win_recentlyClosed .border {
padding-left: 20px;
}
#win_recentlyClosed .border .create_button {
display: none;
}
.window .border .close_button {
float: right;
}
Expand All @@ -136,7 +142,7 @@ a {
margin: 15px;
border-radius: 5px;
height: 16px;
vertical-align: top;
vertical-align: middle;
}
.desktopFolder:hover {
box-shadow: 0 0 0 5px var(--hi);
Expand All @@ -145,20 +151,20 @@ a {
box-shadow: 0 0 0 5px var(--hi-click);
}
.window main .desktopFolder {
overflow: hidden;
overflow: hidden;
height: 40px;
}

.desktopLink {
display: inline-block;
display: inline-block;
text-decoration: none;
padding: 15px;
border-radius: 5px;
}
.desktopLink img {
margin-right: 4px;
vertical-align: middle;
image-rendering: optimizespeed;
vertical-align: bottom;
image-rendering: optimizeSpeed;
}
.desktopLink:hover {
background: var(--hi);
Expand All @@ -179,7 +185,6 @@ a {
.window main .desktopLink img {
display: block;
margin: auto;
image-rendering: optimizeSpeed;
}

#secureDrag {
Expand All @@ -195,6 +200,7 @@ a {
text-align: center;
fill: var(--color);
cursor: pointer;
min-width: 0;
}

#delete_vortex {
Expand Down
2 changes: 1 addition & 1 deletion newTab.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<path d="M8.6 16H7.4a1.6 1.6 0 0 1-1.6-1.2l-.4-1.4a6 6 0 0 1-.8-.5l-1.4.4a1.6 1.6 0 0 1-1.8-.8l-.6-1a1.6 1.6 0 0 1 .2-2l1-1A3.3 3.3 0 0 1 2 8v-.5l-1-1a1.6 1.6 0 0 1-.2-2l.6-1a1.6 1.6 0 0 1 1.8-.8l1.4.3.8-.4.4-1.4A1.6 1.6 0 0 1 7.4 0h1.2c.8 0 1.4.5 1.6 1.2l.4 1.4.8.4 1.4-.3a1.6 1.6 0 0 1 1.8.8l.7 1c.3.7.2 1.5-.3 2l-1 1a3.7 3.7 0 0 1 0 1l1 1c.5.5.6 1.3.2 2l-.6 1a1.6 1.6 0 0 1-1.8.8l-1.4-.4a6 6 0 0 1-.8.5l-.4 1.4A1.6 1.6 0 0 1 8.6 16zm-4-4.3h.5a4.7 4.7 0 0 0 1 .7l.4.4.5 1.7.4.2h1.2a.4.4 0 0 0 .4-.2l.5-1.7.3-.4a5 5 0 0 0 1-.6l.6-.1 1.7.4a.4.4 0 0 0 .4-.2l.6-1a.4.4 0 0 0 0-.5L12.8 9l-.1-.5V7.4l.2-.5L14 5.6a.4.4 0 0 0 0-.4L13.6 4a.4.4 0 0 0-.4-.2l-1.8.4h-.5a4.7 4.7 0 0 0-1-.7l-.3-.4L9 1.5a.4.4 0 0 0-.4-.3H7.4a.4.4 0 0 0-.4.3l-.5 1.7-.3.4a4.7 4.7 0 0 0-1 .6l-.6.1L3 4a.4.4 0 0 0-.4.2l-.7 1a.4.4 0 0 0 .1.5L3.1 7l.2.5v.2a3 3 0 0 0 0 .4V8.6l-.2.5L2 10.4a.4.4 0 0 0 0 .4l.6 1.1a.4.4 0 0 0 .4.2l1.7-.4z"/>
<path d="M8 6.25a1.75 1.75 0 110 3.5 1.75 1.75 0 010-3.5M8 5a3 3 0 100 6 3 3 0 000-6z"/>
</svg>
</div><data value="BookmarksMenu" class="desktopFolder" id="menu________"></data><data value="MobileBookmarks" class="desktopFolder" id="mobile______"></data><data value="OtherBookmarks" class="desktopFolder" id="unfiled_____"></data><data value="BookmarksToolbar" class="desktopFolder" id="toolbar_____"></data>
</div><data value="BookmarksMenu" class="desktopFolder" id="menu________"></data><data value="MobileBookmarks" class="desktopFolder" id="mobile______"></data><data value="OtherBookmarks" class="desktopFolder" id="unfiled_____"></data><data value="BookmarksToolbar" class="desktopFolder" id="toolbar_____"></data><data value="RecentlyClosed" class="desktopFolder" id="recentlyClosed"></data>

<div id="tip_container">
<section>
Expand Down
116 changes: 88 additions & 28 deletions newTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ chrome.storage.local.get(null, function(options) {
if (options.toolbar_as_folder) {
registerFolder('toolbar_____');
} else {
document.body.style.maxWidth = '1280px';
document.getElementById('toolbar_____').outerHTML = null;
chrome.bookmarks.getChildren('toolbar_____', function (bms) {
for (let i = 0; i < bms.length; ++i) {
if (bms[i].type === 'bookmark') {
Expand All @@ -32,8 +34,6 @@ chrome.storage.local.get(null, function(options) {
}
}
});
document.body.style.maxWidth = '1280px';
document.getElementById('toolbar_____').outerHTML = null;
}

if (options.show_search_tips) {
Expand Down Expand Up @@ -121,6 +121,10 @@ function drawWindow(id, title, x, y, w, h, z) {
x = 0;
}

if (id === 'recentlyClosed') {
title = browser.i18n.getMessage('RecentlyClosed');
}

// draw
document.body.insertAdjacentHTML(
'beforeend',
Expand All @@ -139,37 +143,42 @@ function drawWindow(id, title, x, y, w, h, z) {
let win = document.getElementById('win_'+id);

// populate
chrome.bookmarks.getChildren(id, function(e) {
let elements = '';
let foldersIds = [];
let linksIds = [];

for (let i = 0; i < e.length; ++i) {
let el = e[i];
if (el.type === 'bookmark') {
if (el.title === '') {
el.title = el.url;
if (id === 'recentlyClosed') {
populateRecentlyClosed();
browser.sessions.onChanged.addListener(populateRecentlyClosed);
} else {
chrome.bookmarks.getChildren(id, function(e) {
let elements = '';
let foldersIds = [];
let linksIds = [];

for (let i = 0; i < e.length; ++i) {
let el = e[i];
if (el.type === 'bookmark') {
if (el.title === '') {
el.title = el.url;
}

elements += '<a class="desktopLink" id="'+el.id+'" title="'+el.title+'" href="'+el.url+'"><img loading="lazy" width="16px" height="16px" src="https://s2.googleusercontent.com/s2/favicons?domain_url='+el.url+'"/>'+el.title+'</a>';
linksIds.push(el.id);
} else if (el.type === 'folder') {
elements += '<div class="desktopFolder" id="'+el.id+'" title="'+el.title+'" draggable="true">'+el.title+'</div>';
foldersIds.push(el.id);
}

elements += '<a class="desktopLink" id="'+el.id+'" title="'+el.title+'" href="'+el.url+'"><img loading="lazy" width="16px" height="16px" src="https://s2.googleusercontent.com/s2/favicons?domain_url='+el.url+'"/>'+el.title+'</a>';
linksIds.push(el.id);
} else if (el.type === 'folder') {
elements += '<div class="desktopFolder" id="'+el.id+'" title="'+el.title+'" draggable="true">'+el.title+'</div>';
foldersIds.push(el.id);
}
}

win.childNodes[1].innerHTML = elements; // may be faster, or may not
win.childNodes[1].innerHTML = elements; // may be faster, or may not

for (let i = 0; i < foldersIds.length; i++) {
registerFolder(foldersIds[i]);
dragonPrepare(foldersIds[i]);
}
for (let i = 0; i < foldersIds.length; i++) {
registerFolder(foldersIds[i]);
dragonPrepare(foldersIds[i]);
}

for (let i = 0; i < linksIds.length; i++) {
dragonPrepare(linksIds[i]);
}
});
for (let i = 0; i < linksIds.length; i++) {
dragonPrepare(linksIds[i]);
}
});
}

// move
win.childNodes[0].addEventListener('mousedown', function(e) {
Expand Down Expand Up @@ -268,6 +277,43 @@ function drawWindow(id, title, x, y, w, h, z) {
});
}

function populateRecentlyClosed() {
var div = document.getElementById('win_recentlyClosed').childNodes[1];

if (!div) {
return;
}

browser.sessions.getRecentlyClosed().then(function (e) {
var seen = [];
var dom = '';

for (let i = 0; i < e.length; ++i) {
let tab = e[i].tab;

if (
!tab ||
seen[tab.url] ||
tab.title.startsWith('moz-extension://') ||
tab.url.startsWith('about:')
) {
continue;
}

if (!tab.favIconUrl) {
img = '';
} else {
img = '<img height="16px" width="16px" src="'+tab.favIconUrl+'"/>';
}

dom += '<a class="desktopLink" href="'+tab.url+'">'+img + sanitize(tab.title)+'</a>';
seen[tab.url] = true;
}

div.innerHTML = dom;
});
}

// translations
ToTranslate = document.getElementsByTagName('data');
for (let i = 0; i < ToTranslate.length; ++i) {
Expand Down Expand Up @@ -369,6 +415,7 @@ document.addEventListener('dragend', function() {
registerFolder('menu________');
registerFolder('mobile______');
registerFolder('unfiled_____');
registerFolder('recentlyClosed');

document.getElementById('options').addEventListener("mousedown", function() {
chrome.runtime.openOptionsPage();
Expand Down Expand Up @@ -413,3 +460,16 @@ document.addEventListener('keydown', function (e) {
location.reload();
}
});

function sanitize(string) {
const map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
"/": '&#x2F;',
};
const reg = /[&<>"'/]/ig;
return string.replace(reg, (match)=>(map[match]));
}