Skip to content

Commit

Permalink
Survey exhortations (#202)
Browse files Browse the repository at this point in the history
* Reworked script, settings

* Survey footer, delayed popup

* Survey footer tweak

* WebKit compatibility fix
  • Loading branch information
meyerweb authored Dec 19, 2023
1 parent 89fc097 commit 1a7a6b9
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1 deletion.
102 changes: 102 additions & 0 deletions _includes/footer.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
<dialog id="splash">
<p>If you’re using WPE WebKit, or are considering doing so, <strong>please take our brief user survey!</strong> Your input will help us make WPE WebKit better for you.</p>
<div>
<button is="dis-misser" id="dismiss-Y">Yes</button>
<button is="dis-misser" id="dismiss-L">Ask again later</button>
<button is="dis-misser" id="dismiss-N">No</button>
</div>
</dialog>
<style>
#splash {max-width: 50%; border-radius: 1em; padding-inline: 2em; outline: 50vmax solid #141316D0; background: #EEE;}
#splash p {font-size: 1.25em; color: inherit;}
#splash img {max-width: 60vw; max-height: 50vh; aspect-ratio: 1.88/1;}
@media (max-width: 600px) {
#splash img {object-fit: contain; object-position: 100% 100%;}
}
#splash div {margin-block: 1em 1.5em; text-align: center; display: flex; gap: 1em; justify-content: center;}
#splash button {font-size: 1.33em; border-radius: 1em; padding-inline: 0.75em; padding-block: 0.2em; border: 0; background: #888; color: #EEE; cursor: pointer;}
#splash button:focus {outline: 0.25em solid black;}
#splash button#dismiss-Y {background: hsl(205deg 84.8% 50%);}
#splash button#dismiss-L {background: hsl(102.5deg 15.2% 50%);}
#splash button#dismiss-N {background: hsl(0deg 84.8% 50%);}
</style>
<footer class="global">
<b></b>
<div>
Expand All @@ -14,3 +36,83 @@
</ul>
</div>
</footer>
<script>
let storedInfo = {};
const flagName = 'survey-splash';

function startup(flagName) {
if (!flagName) {
console.error('Missing flagName');
return;
}
if (storageAvailable("localStorage")) {
let currentTime = Date.now();
let timeOut = 1;
timeOut *= 86400 * 1000;
let localStore = localStorage.getItem(flagName);
if (!localStore) {
storedInfo = {
'status': null,
'datetime': currentTime,
'pageloads' : 0
}
} else {
storedInfo = JSON.parse(localStore);
}
storedInfo.pageloads++;
localStorage.setItem(flagName, JSON.stringify(storedInfo));

if (storedInfo.pageloads < 11) return;
if (storedInfo.status == "Y" || storedInfo.status == "N") return;
if (storedInfo.status && currentTime - storedInfo.datetime < timeOut) return;

splash.showModal();
storedInfo.datetime = currentTime;
}
}

function storageAvailable(type) {
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
let storage;
try {
storage = window[type];
const x = "__storage_test__";
storage.setItem(x, x);
storage.removeItem(x);
return true;
} catch (e) {
return (
e instanceof DOMException &&
// everything except Firefox
(e.code === 22 ||
// Firefox
e.code === 1014 ||
// test name field too, because code might not be present
// everything except Firefox
e.name === "QuotaExceededError" ||
// Firefox
e.name === "NS_ERROR_DOM_QUOTA_REACHED") &&
// acknowledge QuotaExceededError only if there's something already stored
storage &&
storage.length !== 0
);
}
}

function surveyRedirect() {
let surveyURL = "https://docs.google.com/forms/d/e/1FAIpQLSchPgMGzuVc9ry5bdxF2uFnW2q3FcrSSqxJdOM4Fd2BD4s7dg/viewform?usp=pp_url&entry.1179679285=WPEWebKit.org+website";
if (surveyURL) window.location = surveyURL;
}

document.querySelectorAll('button[is="dis-misser"]').forEach(el => {
el.addEventListener("click", () => {
splash.close();
storedInfo.status = el.getAttribute('id').replace('dismiss-','');
console.log(storedInfo);
localStorage.setItem(flagName, JSON.stringify(storedInfo));
if (storedInfo.status == "Y") surveyRedirect();
});
});

window.onload = startup(flagName);
</script>
1 change: 0 additions & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@
})();
</script>
<!-- End Matomo Code -->

</head>
32 changes: 32 additions & 0 deletions _includes/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@

<main>
{{ content }}
<div class="survey">
<p>
If you’re using WPE WebKit, or are considering doing so, <strong><a href="https://docs.google.com/forms/d/e/1FAIpQLSchPgMGzuVc9ry5bdxF2uFnW2q3FcrSSqxJdOM4Fd2BD4s7dg/viewform?usp=pp_url&amp;entry.1179679285=WPEWebKit.org+website">please take our brief user survey</a></strong>. Your input will help us make WPE WebKit better for you!
</p>
</div>
<style>
.survey {
position: relative;
font-size: 1.25em;
--bgrad: linear-gradient(180deg,#00C6 0.25em,#00B4 20%,40%,#00B2);
background: var(--bgrad);
border-image: var(--bgrad) 1;
border-image-outset: 0 50vmax;
border-image-width: 0 50vmax;
}
.survey::before {
content: url(/assets/img/survey.svg);
position: absolute;
top: -1.5em;
left: 0;
right: 0;
margin-inline: auto;
height: 3em;
width: auto;
aspect-ratio: 1/1;
filter: drop-shadow(0.25em 0.33em 0.33em #0006);
}
.survey p {
padding-inline: 1em;
}
</style>

</main>

{% include footer.html %}
Expand Down
25 changes: 25 additions & 0 deletions assets/img/survey.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1a7a6b9

Please sign in to comment.