Skip to content

Commit 11b1d64

Browse files
committed
Add usage notifications
1 parent d04f7fc commit 11b1d64

6 files changed

+134
-4
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ Open the [PageAccel Chrome Web store link](https://chrome.google.com/webstore/de
2525
* Register simplified and standard domains as pairs, in case they're different.
2626
* This may also alleviate the need for the tld domain list
2727
* Remove unused tabs from storage if not used in last x days
28-
* After either(days active > 2, pages viewed 500), tell user how many pages have been accelerated and show them which ones. If the percentage is high, show them the % of pages, else, just tell them how many pages. Tell them how many seconds / bytes they've saved by using pageaccel.
29-
* Do this at some regular intervals
3028
* Provide stats button in pageaccel so user can see stats anytime.

background.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2016 Taylor Raack.
2+
Copyright 2016,2017 Taylor Raack.
33
44
This file is part of PageAccel.
55
@@ -150,6 +150,40 @@ function buildAmpUrl(status) {
150150
}
151151
}
152152

153+
function recordAmpSwitched() {
154+
getFromStorage('ampSwitched', function(item) {
155+
var newCount = item['count'] + 1;
156+
if (Number.isInteger(Math.log(newCount)/Math.log(5))) {
157+
// display a notification and increase the counter once the user has closed the notification
158+
159+
displayNotification(
160+
newCount == 1 ?
161+
"You're viewing your first PageAccel simplified page!" :
162+
"PageAccel is still simplifying your web browsing experience!",
163+
newCount == 1 ?
164+
"Enjoy!" :
165+
"You've viewed " + newCount + " simplified pages with PageAccel.", function () {
166+
setToStorage('ampSwitched', {'count':newCount}, function() {});
167+
});
168+
} else {
169+
// don't need to show a notification right now, just increase counter
170+
setToStorage('ampSwitched', {'count':newCount}, function() {});
171+
}
172+
});
173+
}
174+
175+
function displayNotification(title, message, onClose) {
176+
chrome.permissions.contains({permissions: ['notifications']}, function(result) {
177+
if (result) {
178+
chrome.notifications.create(
179+
{ type: "basic", title: title, message: message, iconUrl: "amplifier128.png"},
180+
function(notificationId) {
181+
chrome.notifications.onClosed.addListener(onClose);
182+
});
183+
}
184+
});
185+
}
186+
153187
/*
154188
* AMP document discovery (https://www.ampproject.org/docs/reference/spec#amp-document-discovery)
155189
*
@@ -195,6 +229,7 @@ function processTabState(tabId, senderUrl) {
195229
logpa("setting previous url to " + senderUrl, tabId);
196230
setTabStatus(tabStatus, function() {
197231
working = false;
232+
recordAmpSwitched();
198233
chrome.tabs.update(tabId, { url : buildAmpUrl(status) });
199234
});
200235
} else {
@@ -396,7 +431,27 @@ function setUpInstallUninstallActions() {
396431
}
397432
}
398433

434+
function primeAmpSwitchedCount() {
435+
getFromStorage('ampSwitched', function(item) {
436+
if (!('count' in item)) {
437+
setToStorage('ampSwitched', {'count':0}, function() {});
438+
}
439+
});
440+
}
441+
442+
function verifyNotificationPermissions() {
443+
chrome.permissions.contains({permissions: ['notifications']}, function(result) {
444+
if (!result) {
445+
chrome.tabs.create({
446+
url: chrome.extension.getURL("nonavigation.html")
447+
});
448+
}
449+
});
450+
}
451+
399452
primePublicSuffixList();
400453

401454
setUpInstallUninstallActions();
402455
showSplashScreenOnFirstRun();
456+
primeAmpSwitchedCount();
457+
verifyNotificationPermissions();

compress.sh

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ firstRun2.html \
1111
firstRun.js \
1212
LICENSE \
1313
manifest.json \
14+
nonavigation.html \
1415
popup.html \
1516
popup.js \
1617
publicsuffixlist.js \

firstRun.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2016 Taylor Raack <[email protected]>.
2+
Copyright 2016,2017 Taylor Raack <[email protected]>.
33
44
This file is part of PageAccel.
55
@@ -38,4 +38,12 @@ $( document ).ready(function() {
3838
$('#instructions3').removeClass("hidden");
3939
});
4040
});
41+
42+
$("#promptForNavigation").click(function() {
43+
chrome.permissions.request({permissions: ['notifications']}, function(granted) {
44+
if (granted) {
45+
window.close();
46+
}
47+
});
48+
});
4149
});

manifest.json

+3
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@
3030
"activeTab",
3131
"webNavigation"
3232
],
33+
"optional_permissions": [
34+
"notifications"
35+
],
3336
"content_security_policy": "script-src 'self' https://ajax.googleapis.com https://maxcdn.bootstrapcdn.com; object-src 'self'"
3437
}

nonavigation.html

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE html>
2+
3+
<!--
4+
5+
Copyright 2017 Taylor Raack.
6+
7+
This file is part of PageAccel.
8+
9+
PageAccel is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
PageAccel is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with PageAccel. If not, see <http://www.gnu.org/licenses/>.
21+
-->
22+
23+
<html lang="en">
24+
<head>
25+
<meta charset="utf-8">
26+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
27+
<meta name="viewport" content="width=device-width, initial-scale=1">
28+
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
29+
<title>PageAccel - New Permission needed</title>
30+
31+
<!-- Bootstrap -->
32+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
33+
<link rel="stylesheet" href="style.css" />
34+
<link rel="stylesheet" href="colors.css" />
35+
</head>
36+
<body>
37+
<div class="container">
38+
<div class="row row-margin mediumbg">
39+
<div class="col-md-12 text-center">
40+
<img src="amplifier128.png" class="img-responsive center-block" alt="PageAccel logo" /><br />
41+
<h1 style="color: #000"><strong>PageAccel needs a new permission</strong></h1>
42+
</div>
43+
</div>
44+
<div class="row row-margin vlightbg">
45+
<div class="col-md-12 text-center lead">
46+
We hope you are enjoying <strong>PageAccel</strong>. In order to continue displaying streamlined, accelerated, easy-to-use web pages, PageAccel needs a new Chrome permission.
47+
</div>
48+
</div>
49+
<div class="row row-margin vlightbg">
50+
<div class="col-md-12 text-center">
51+
<div class="lead">
52+
<button id="promptForNavigation">Click here to re-enable PageAccel</button>
53+
</div>
54+
</div>
55+
</div>
56+
</div>
57+
58+
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
59+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
60+
<!-- Include all compiled plugins (below), or include individual files as needed -->
61+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
62+
63+
<script src="firstRun.js"></script>
64+
</body>
65+
</html>

0 commit comments

Comments
 (0)