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

Change behavior of tab napping notification #101

Open
wants to merge 3 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
6 changes: 3 additions & 3 deletions html/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ <h4>Help make Snoozz better</h4>
<div class="input-container flex">
<div>
<h4>Manage Snoozz Data</h4>
<p>Import or Export tabs from this device.</p>
<p>Import or Export settings tabs from this device.</p>
<p>No data will be deleted when you peform this action.</p>
<p>Any duplicate tabs will be intelligently combined with your existing data.</p>
</div>
Expand Down Expand Up @@ -341,8 +341,8 @@ <h2><span>About</span></h2>
</div>
</div>
<div class="copied">Copied to clipboard</div>
<div class="import-success">Succesfully imported tabs from <span></span>.</div>
<div class="import-fail">Unable to import tabs from this file.<br>Please select another one.</div>
<div class="import-success">Succesfully imported data from <span></span>.</div>
<div class="import-fail">Unable to import data from this file.<br>Please select another one.</div>
<script type="text/javascript" src="../scripts/dayjs.min.js"></script>
<script type="text/javascript" src="../scripts/common.js"></script>
<script type="text/javascript" src="../scripts/settings.js"></script>
Expand Down
9 changes: 6 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "Snoozz - Snooze Tabs & Windows for later",
"name": "MY Snoozz - Snooze Tabs & Windows for later",
"short_name": "Snoozz",
"description": "Declutter your browser by snoozing tabs and windows until you actually need them.",
"version": "2.5.1",
"version": "2.5.8",

"icons": {
"128": "icons/ext-icon-128.png",
Expand All @@ -15,7 +15,7 @@
"browser_action": {
"default_popup": "html/popup.html"
},
"author": "Rohan Bhansali",
"author": "Sari Louis (forked from original by Rohan Bhansali)",
"options_ui": {
"page": "html/settings.html",
"open_in_tab": true
Expand All @@ -36,6 +36,9 @@
}],

"commands": {
"_execute_browser_action": {
"description": "Open the Snoozz popup"
},
"nap-room": {
"description": "Show me my sleeping tabs"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function snoozeInBackground(item, tab) {
var snoozed = await snoozeTab(item.menuItemId === 'startup' ? 'startup' : snoozeTime.valueOf(), assembledTab);

var msg = `${!isHref ? tab.title : getHostname(url)} will wake up ${formatSnoozedUntil(assembledTab)}.`
createNotification(snoozed.tabDBId, 'A new tab is now napping :)', 'icons/logo.svg', msg, true);
createNotification(snoozed.tabDBId, 'A new tab is now napping :)', 'icons/logo.svg', msg);

if (!isHref) await chrome.tabs.remove(tab.id);
await chrome.runtime.sendMessage({updateDash: true});
Expand Down
57 changes: 33 additions & 24 deletions scripts/common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var colours = window.gradientSteps ? gradientSteps('#F3B845', '#DF4E76', 100) : [];
function getBrowser() {
if (!!navigator.userAgent.match(/safari/i) && !navigator.userAgent.match(/chrome/i) && typeof document.body.style.webkitFilter !== 'undefined') return 'safari';
if (!!window.sidebar) return 'firefox';
//if (!!window.sidebar) return 'firefox';
if (!!navigator.userAgent.match(/firefox/i)) return 'firefox';
return 'chrome';
}
/* ASYNCHRONOUS FUNCTIONS */
Expand Down Expand Up @@ -146,6 +147,8 @@ async function openExtensionTab(url) {
}

async function openTab(tab, windowId, automatic = false) {
if (tab.url.startsWith("about:reader"))
tab.url = decodeURIComponent(tab.url.substr(tab.url.lastIndexOf("url=") + 4));
var windows = await getAllWindows();
if (!windows || !windows.length) {
await new Promise(r => chrome.windows.create({url: tab.url}, r));
Expand Down Expand Up @@ -350,8 +353,8 @@ async function getChoices(which) {
if (typeof config.morning === 'number' || typeof config.evening === 'number') config = upgradeSettings(config);
var all = {
'startup': {
label: 'On Next Startup',
repeatLabel: 'Every Browser Startup',
label: '1. On Next Startup',
repeatLabel: '1. Every Browser Startup',
startUp: true,
time: NOW.add(20, 'y'),
timeString: '',
Expand All @@ -361,8 +364,8 @@ async function getChoices(which) {
menuLabel: 'till next startup'
},
'in-an-hour': {
label: 'In One Hour',
repeatLabel: 'Every hour',
label: '2. In One Hour',
repeatLabel: '2. Every hour',
time: NOW.add(1, 'h'),
timeString: NOW.add(1, 'h').dayOfYear() == NOW.dayOfYear() ? 'Today' : 'Tomorrow',
repeatTime: NOW.add(1, 'h').format(getHourFormat(true)),
Expand All @@ -371,7 +374,7 @@ async function getChoices(which) {
menuLabel: 'for an hour'
},
'today-morning': {
label: 'This Morning',
label: '3. This Morning',
repeatLabel: '',
time: NOW.startOf('d').add(config.morning[0], 'h').add(config.morning[1], 'm'),
timeString: 'Today',
Expand All @@ -382,8 +385,8 @@ async function getChoices(which) {
repeatDisabled: true,
},
'today-evening': {
label: getEveningLabel(config.evening[0]),
repeatLabel: `Everyday, Now`,
label: '4. ' + getEveningLabel(config.evening[0]),
repeatLabel: '4. Everyday, Now',
time: NOW.startOf('d').add(config.evening[0], 'h').add(config.evening[1], 'm'),
timeString: 'Today',
repeatTime: NOW.format(getHourFormat(true)),
Expand All @@ -393,8 +396,8 @@ async function getChoices(which) {
disabled: NOW.startOf('d').add(config.evening[0], 'h').add(config.evening[1], 'm').valueOf() < dayjs(),
},
'tom-morning': {
label: 'Tomorrow Morning',
repeatLabel: 'Every Morning',
label: '5. Tomorrow Morning',
repeatLabel: '5. Every Morning',
time: NOW.startOf('d').add(1,'d').add(config.morning[0], 'h').add(config.morning[1], 'm'),
timeString: NOW.add(1,'d').format('ddd, D MMM'),
repeatTime: NOW.startOf('d').add(config.morning[0], 'h').add(config.morning[1], 'm').format(getHourFormat(true)),
Expand All @@ -403,8 +406,8 @@ async function getChoices(which) {
menuLabel: 'till tomorrow morning'
},
'tom-evening': {
label: getEveningLabel(config.evening[0], 'tomorrow'),
repeatLabel: getEveningLabel(config.evening[0], 'everyday'),
label: '6. ' + getEveningLabel(config.evening[0], 'tomorrow'),
repeatLabel: '6. ' + getEveningLabel(config.evening[0], 'everyday'),
time: NOW.startOf('d').add(1,'d').add(config.evening[0], 'h').add(config.evening[1], 'm'),
timeString: NOW.add(1,'d').format('ddd, D MMM'),
repeatTime: NOW.startOf('d').add(config.evening[0], 'h').add(config.evening[1], 'm').format(getHourFormat(true)),
Expand All @@ -413,8 +416,8 @@ async function getChoices(which) {
menuLabel: 'till tomorrow evening'
},
'weekend': {
label: 'Saturday',
repeatLabel: 'Every Saturday',
label: '7. Saturday',
repeatLabel: '7. Every Saturday',
time: NOW.startOf('d').weekday(6),
timeString: NOW.weekday(6).format('ddd, D MMM'),
repeatTime: NOW.startOf('d').format(getHourFormat(true)),
Expand All @@ -424,8 +427,8 @@ async function getChoices(which) {
// disabled: NOW.day() === 6,
},
'monday': {
label: 'Next Monday',
repeatLabel: 'Every Monday',
label: '8. Next Monday',
repeatLabel: '8. Every Monday',
time: NOW.startOf('d').weekday(NOW.startOf('d') < dayjs().startOf('d').weekday(1) ? 1 : 8),
timeString: NOW.weekday(NOW.startOf('d') < dayjs().startOf('d').weekday(1) ? 1 : 8).format('ddd, D MMM'),
repeatTime: NOW.startOf('d').format(getHourFormat(true)),
Expand All @@ -434,8 +437,8 @@ async function getChoices(which) {
menuLabel: 'till next Monday'
},
'week': {
label: 'Next Week',
repeatLabel: 'Every ' + NOW.format('dddd'),
label: '9. Next Week',
repeatLabel: '9. Every ' + NOW.format('dddd'),
time: NOW.startOf('d').add(1, 'week'),
timeString: NOW.startOf('d').add(1, 'week').format('ddd, D MMM'),
repeatTime: NOW.format(getHourFormat(true)),
Expand All @@ -446,8 +449,8 @@ async function getChoices(which) {
// repeatDisabled: NOW.day() === 1 || NOW.day() === 6,
},
'month': {
label: 'Next Month',
repeatLabel: 'Every Month',
label: '0. Next Month',
repeatLabel: '0. Every Month',
time: NOW.startOf('d').add(1, 'M'),
timeString: NOW.startOf('d').add(1, 'M').format('ddd, D MMM'),
repeatTime: NOW.format(getHourFormat(true)),
Expand Down Expand Up @@ -484,7 +487,13 @@ async function calculateNextSnoozeTime(data) {
days = nextWeek.concat(thisWeek).map(day => dayjs().startOf('w').add(day, 'd').hour(HOUR).minute(MINUTE));
} else if (data.monthly) {
var thisMonth = data.monthly.filter(d => d <= dayjs().daysInMonth()).map(d => dayjs().startOf('M').date(d).hour(HOUR).minute(MINUTE));
if (thisMonth.length === 0) {
thisMonth = data.monthly.map(d => dayjs().endOf('M').hour(HOUR).minute(MINUTE));
}
var nextMonth = data.monthly.filter(d => d <= dayjs().add(1, 'M').daysInMonth()).map(d => dayjs().startOf('M').add(1, 'M').date(d).hour(HOUR).minute(MINUTE));
if (nextMonth.length === 0) {
nextMonth = data.monthly.map(d => dayjs().startOf('M').add(1, 'M').endOf('M').hour(HOUR).minute(MINUTE));
}
days = nextMonth.concat(thisMonth);
}
return days.filter(d => d > NOW).pop().valueOf();
Expand All @@ -496,8 +505,8 @@ async function calculateNextSnoozeTime(data) {
var getFaviconUrl = url => {
if (url.indexOf('file://') === 0) return '../icons/file.svg'
// return `https://icons.duckduckgo.com/ip3/${getHostname(url)}.ico`
// return `https://www.google.com/s2/favicons?sz=64&domain_url=${getHostname(url)}`;
return `https://besticon.herokuapp.com/icon?url=${getHostname(url)}&size=32..48..64&fallback_icon_color=${getColorForUrl(getHostname(url)).replace('#', '')}`;
return `https://www.google.com/s2/favicons?sz=64&domain_url=${getHostname(url)}`;
//return `https://besticon.herokuapp.com/icon?url=${getHostname(url)}&size=32..48..64&fallback_icon_color=${getColorForUrl(getHostname(url)).replace('#', '')}`;
}
var getColorForUrl = (url = 'snoozz.me') => colours[url.split('').map(c => c.charCodeAt(0)).reduce((a, b) => a + b) % 100];

Expand Down Expand Up @@ -535,8 +544,8 @@ var today = tabs => tabs.filter(t => t.wakeUpTime && dayjs(t.wakeUpTime).dayOfYe
var isDefault = tabs => tabs.title && ['nap room | snoozz', 'settings | snoozz', 'rise and shine | snoozz', 'New Tab', 'Start Page'].includes(tabs.title);

var isValid = tabs => {
var validProtocols = ['http', 'https', 'ftp', 'chrome-extension', 'web-extension', 'moz-extension', 'extension'];
if (getBrowser() == 'chrome') validProtocols.push('file');
var validProtocols = ['http', 'https', 'ftp', 'chrome-extension', 'web-extension', 'moz-extension', 'extension', 'read', 'file', 'about'];
//if (getBrowser() == 'chrome') validProtocols.push('file');
return tabs.url && validProtocols.includes(tabs.url.substring(0, tabs.url.indexOf(':')));
}

Expand Down
Loading