Skip to content

Add banner to warn about scams #1604

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

Merged
merged 1 commit into from
Mar 5, 2024
Merged
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
1 change: 1 addition & 0 deletions _data/messages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scam-banner: "**⚠️ Beware of Scams**: since Feb 2024, scammers are using [fake Scala websites to sell courses](https://www.scala-lang.org/blog/2024/03/01/fake-scala-courses.html), please check you are using an official source."
6 changes: 6 additions & 0 deletions _includes/alert-banner-inner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% comment %}use the variable 'message' to include markdown text to display in the alert.{% endcomment %}

<div class="new-on-the-blog alert-warning" data-message_id="{{include.message_id}}">
<p>{{include.message|markdownify}}</p>
<span class="hide-alert"><i class="fa fa-close"></i></span>
</div>
5 changes: 5 additions & 0 deletions _includes/alert-banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% comment %}use the variable 'message' to include markdown text to display in the alert.{% endcomment %}

<header id="site-header" class="header-home">
{% include alert-banner-inner.html message=include.message message_id=include.message_id %}
</header>
1 change: 1 addition & 0 deletions _includes/navbar-inner.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<header id="site-header">
{% include alert-banner.html message=site.data.messages.scam-banner message_id='scam-courses-feb-2024' %}
<div class="wrap">
<nav class="navigation" role="menu">
<a href="/" class="navigation-bdand">
Expand Down
1 change: 1 addition & 0 deletions _layouts/frontpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!-- Header -->
<header id="site-header" class="header-home">
<div class="header-background">
{% include alert-banner-inner.html message=site.data.messages.scam-banner message_id='scam-courses-feb-2024' %}
<div class="new-on-the-blog">
<p>New on the blog:
{% assign newPost = site.posts.first %}
Expand Down
17 changes: 17 additions & 0 deletions _sass/layout/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
padding: 10px 40px;
}

&.alert-warning {
background: $warning-bg;
color: $warning-text;

a {
color: $warning-link;
font-weight: bold;
text-decoration: underline;

&:active,
&:focus,
&:hover {
text-decoration: none;
}
}
}

span {
position: absolute;
right: 20px;
Expand Down
4 changes: 4 additions & 0 deletions _sass/utils/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ $apple-blue: #6dccf5;
$std-link: #23aad1;
$gray-heading: rgb(134, 161, 166);

$warning-bg: #FFA500;
$warning-link: #185eb3;
$warning-text: #000;

// $header-bg: #266270;
$header-bg: #22525e;
$banner-notice-bg: $gray-darkest;
Expand Down
67 changes: 66 additions & 1 deletion resources/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(document).ready(function() {

// Show Blog
$(".hide").click(function() {
$(".new-on-the-blog").hide();
$(this).parent().hide(); // hide only the parent element of this button
updatePointer();
});

Expand Down Expand Up @@ -219,6 +219,71 @@ $(document).ready(function() {
}
});

// Browser Storage Support (https://stackoverflow.com/a/41462752/2538602)
function storageAvailable(type) {
try {
var storage = window[type],
x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
}
catch (e) {
return false;
}
}

// Store preferences in local storage and use them
$(document).ready(function () {

const Storage = (namespace) => {
return ({
getPreference(key, defaultValue) {
const res = localStorage.getItem(`${namespace}.${key}`);
return res === null ? defaultValue : res;
},
setPreference(key, value, onChange) {
const old = this.getPreference(key, null);
if (old !== value) { // activate effect only if value changed.
localStorage.setItem(`${namespace}.${key}`, value);
onChange(old);
}
}
});
};

function setupAlertCancel(alert, storage) {
const messageId = alert.data('message_id');
let onHide = () => { };
if (messageId) {
const key = `alert.${messageId}`;
const isHidden = storage.getPreference(key, 'show') === 'hidden';
if (isHidden) {
alert.hide();
}
onHide = () => storage.setPreference(key, 'hidden', _ => { });
}


alert.find('.hide-alert').click(function () {
alert.hide(), onHide();
});
}

function setupAllAlertCancels(storage) {
var alertBanners = $(".new-on-the-blog.alert-warning");
if (alertBanners.length) {
setupAlertCancel(alertBanners, storage);
}
}

if (storageAvailable('localStorage')) {
const PreferenceStorage = Storage('org.scala-lang.preferences');
setupAllAlertCancels(PreferenceStorage);
}

});

// OS detection
function getOS() {
var osname = "linux";
Expand Down