Skip to content

Commit 8a8f705

Browse files
committed
Add NSFW warning infobox on first visit
Fixes #1450 Add a warning infobox for NSFW content when first visiting the Atlas. * Modify `web/index.html` to include a modal warning infobox about NSFW content that appears on the first visit, with a general disclaimer and a tickbox to accept the warning. * Change `web/_js/main/main.js` to add functions for checking if the user has previously dismissed the NSFW warning, showing the NSFW warning infobox, and preventing loading the data until the popup has been accepted. * Modify `web/_js/config.js` to add a configuration option for displaying the NSFW warning infobox. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/placeAtlas/atlas-2023/issues/1450?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 8a0979b commit 8a8f705

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

web/_js/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ const externalLinksConfig = [
428428
},
429429
];
430430

431+
const nsfwWarningConfig = {
432+
showWarning: true
433+
};
434+
window.nsfwWarningConfig = nsfwWarningConfig;
435+
431436
console.info(`%cThe 2023 r/place Atlas
432437
%cCopyright (c) 2017 Roland Rytz <[email protected]>
433438
Copyright (c) 2023 Place Atlas Initiative and contributors

web/_js/main/main.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ window.atlasAll = atlasAll
7777

7878
if (document.location.host !== prodDomain) document.body.dataset.dev = ""
7979

80-
init()
81-
8280
async function init() {
8381

8482
const args = window.location.search
@@ -555,3 +553,30 @@ noticeEl.querySelector('[role=button]').addEventListener('click', () => {
555553
window.removeEventListener('resize', resizeGlobalTopPadding)
556554
document.body.style.setProperty("--global-top-padding", null)
557555
})
556+
557+
// Function to check if the user has previously dismissed the NSFW warning infobox
558+
function hasDismissedNsfwWarning() {
559+
return localStorage.getItem('nsfwWarningDismissed') === 'true';
560+
}
561+
562+
// Show the NSFW warning infobox if the user has not previously dismissed it
563+
function showNsfwWarning() {
564+
const nsfwWarningModal = new bootstrap.Modal(document.getElementById('nsfwWarningModal'), {
565+
backdrop: 'static',
566+
keyboard: false
567+
});
568+
nsfwWarningModal.show();
569+
570+
document.getElementById('acceptNsfwWarning').addEventListener('click', () => {
571+
localStorage.setItem('nsfwWarningDismissed', 'true');
572+
nsfwWarningModal.hide();
573+
init();
574+
});
575+
}
576+
577+
// Prevent loading the data (atlas.json) until the popup has been accepted
578+
if (nsfwWarningConfig.showWarning && !hasDismissedNsfwWarning()) {
579+
showNsfwWarning();
580+
} else {
581+
init();
582+
}

web/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,30 @@ <h5 class="modal-title" id="donateModalLabel">Donation Links</h5>
468468
</div>
469469
</template>
470470

471+
<!-- NSFW Warning Modal -->
472+
<div class="modal fade" id="nsfwWarningModal" tabindex="-1" aria-labelledby="nsfwWarningModalLabel" aria-hidden="true">
473+
<div class="modal-dialog modal-dialog-centered">
474+
<div class="modal-content">
475+
<div class="modal-header">
476+
<h5 class="modal-title" id="nsfwWarningModalLabel">NSFW Content Warning</h5>
477+
</div>
478+
<div class="modal-body">
479+
<p>This website contains user-submitted content that may be NSFW (Not Safe For Work) and could be intended for users aged 18 and above. Please proceed with caution.</p>
480+
<p>General Disclaimer:</p>
481+
<ul>
482+
<li>This website is not affiliated with Reddit.</li>
483+
<li>Entries are user-submitted and may not be accurate.</li>
484+
<li>Place Atlas has no affiliation with all entries.</li>
485+
<li>Spoiler alert for games and entertainment media.</li>
486+
</ul>
487+
</div>
488+
<div class="modal-footer">
489+
<button type="button" class="btn btn-primary" id="acceptNsfwWarning">I Understand</button>
490+
</div>
491+
</div>
492+
</div>
493+
</div>
494+
471495
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
472496
<script src="./_js/lib/pointInPolygon.js"></script>
473497
<script src="./_js/lib/polylabel.js"></script>

0 commit comments

Comments
 (0)