Skip to content

Commit

Permalink
add adsense, option to disable ads, etc.
Browse files Browse the repository at this point in the history
- added adsense.
- added option to disable ads in the settings manager.
- updated settings to display their description underneath their label.
- updated announcements.
  • Loading branch information
SethClydesdale committed Dec 14, 2024
1 parent 2b380f7 commit 647b553
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 4 deletions.
13 changes: 13 additions & 0 deletions resources/css/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,14 @@ ruby rt {
width:120px;
max-width:100%;
}

.label[title]:after {
content:attr(title);
font-size:13px;
font-weight:normal;
display:block;
}

.sm-label { width:80px; }
.med-label { width:200px; }
.big-label { width:300px; }
Expand Down Expand Up @@ -2978,6 +2986,11 @@ input:checked + .genki_pseudo_checkbox:after { font-size:14px; }
line-height:22px;
}*/

/* ADS */
.ad-container {
text-align:center;
margin:25px 0;
}

/* RESPONSIVENESS */
@media (max-width:1000px) {
Expand Down
2 changes: 1 addition & 1 deletion resources/css/stylesheet.min.css

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions resources/javascript/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
// content: message body for the announcement; write your announcements here!
// [NOT USED CURRENTLY; GSR remnant] edition: [OPTIONAL] restricts the announcement to a specific edition, possible values are: 3rd || 2nd, announcements are global by default
msg : [
{
date : '12/14/24',
content : "I've been slowly rolling out ads on my website recently. They're optional for this project, however, so please <a href=\"https://ko-fi.com/post/Statement-Regarding-Ads-V7V717GGS6\" target=\"_blank\">click here</a> to learn more about this update."
},

{
date : '10/26/24',
content : '<a href="https://ko-fi.com/post/GenkiTobira-Recent-Updates-Future-Plans-Z8Z6158OWB" target="_blank">Click here</a> to learn about the recent updates made to the website as well as my future plans.'
Expand Down
2 changes: 1 addition & 1 deletion resources/javascript/all.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 59 additions & 1 deletion resources/javascript/ga.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Google Analytics
// Google Analytics/Adsense
// disabled if used locally or on another host
if (window.location.hostname == 'sethclydesdale.github.io') {
// Analytics
(function (window, document, id) {
var gtag = document.createElement('SCRIPT');
gtag.async = true;
Expand All @@ -15,4 +16,61 @@ if (window.location.hostname == 'sethclydesdale.github.io') {

document.head.appendChild(gtag);
}(window, document, 'G-N4GW3V4S0S'));


// Adsense
(function (window, document, id) {
// exclusions and preferences
if (storageOK && localStorage.adverts == 'off' || /\/donate\/|\/download\//.test(window.location.pathname)) return false;

var adsense = document.createElement('SCRIPT');
adsense.async = true;
adsense.crossorigin = 'anonymous';
adsense.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=' + id;
document.head.appendChild(adsense);

// function for inserting ads into document
var insertAds = function() {
var content = document.getElementById('content'), ad;

if (content) {

// mobile ads
if (window.screen.width < 728) {
// ad format
ad = '<ins class="adsbygoogle" style="display:inline-block;width:300px;height:250px" data-ad-client="' + id + '" data-ad-slot="{SLOT}"></ins>';

// top page ad
content.insertAdjacentHTML('afterbegin', '<div class="ad-container ad-top">' + ad.replace('{SLOT}', '8249052960') + '</div>');
(adsbygoogle = window.adsbygoogle || []).push({});

// bottom page ad
content.insertAdjacentHTML('beforeend', '<div class="ad-container ad-bottom">' + ad.replace('{SLOT}', '4309807952') + '</div>');
(adsbygoogle = window.adsbygoogle || []).push({});
}

// standard ads
else {
// ad format
ad = '<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="' + id + '" data-ad-slot="{SLOT}"></ins>';

// top page ad
content.insertAdjacentHTML('afterbegin', '<div class="ad-container ad-top">' + ad.replace('{SLOT}', '6877660342') + '</div>');
(adsbygoogle = window.adsbygoogle || []).push({});

// bottom page ad
content.insertAdjacentHTML('beforeend', '<div class="ad-container ad-bottom">' + ad.replace('{SLOT}', '4757999122') + '</div>');
(adsbygoogle = window.adsbygoogle || []).push({});
}
}
};

// wait until DOM loaded to insert ads
if (document.readyState !== 'loading') {
insertAds();
} else {
document.addEventListener('DOMContentLoaded', insertAds);
}

}(window, document, 'ca-pub-2159011770843378'));
}
29 changes: 29 additions & 0 deletions resources/javascript/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
var fontSize = +localStorage.genkiFontSize || 100,
pageWidth = +localStorage.genkiPageWidth || 100,
darkMode = localStorage.darkMode || 'off',
adverts = localStorage.adverts || 'on',
customCSS = localStorage.genkiCustomCSS || '',
furigana = localStorage.furiganaVisible || 'true',
spoilerMode = localStorage.spoilerMode || 'false',
Expand Down Expand Up @@ -206,6 +207,11 @@
'<button id="settings-dark-mode" class="button' + (darkMode == 'on' ? '' : ' opt-off') + '" onclick="GenkiSettings.updateDarkMode(this);">' + (darkMode == 'on' ? 'ON' : 'OFF') + '</button>'+
'</li>'+

(window.location.protocol == 'file:' ? '' : '<li>'+
'<span class="label" title="Enable or disable Ads.\nAds help support the developer, but if they\'re annoying or distracting, you can turn them off with this option.">Ads:</span>'+
'<button id="settings-dark-mode" class="button' + (adverts == 'on' ? '' : ' opt-off') + '" onclick="GenkiSettings.updateAdverts(this);">' + (adverts == 'on' ? 'ON' : 'OFF') + '</button>'+
'</li>')+

'<li>'+
'<span class="label" title="Use your own CSS to customize the design of the site to your liking.">Custom CSS:<br><a href="https://www.w3schools.com/css/css_intro.asp" target="_blank" style="font-weight:normal;"><small>What is CSS?</small></a></span>'+
'<textarea id="page-custom-css" oninput="GenkiSettings.updateCustomCSS(this, true);">' + customCSS + '</textarea>'+
Expand Down Expand Up @@ -518,6 +524,29 @@
},


// updates adverts state
updateAdverts : function (caller) {
GenkiSettings.updateButton(caller, function (state) {
localStorage.adverts = state == 'ON' ? 'on' : 'off';

GenkiModal.open({
title : 'Reload Required',
content : 'The page needs to be reloaded for this setting to take effect. Do you want to reload now?',
buttonText : 'Reload',
closeButtonText : 'Return to Settings',

callback : function () {
window.location.reload();
},

closeCallback : function () {
setTimeout(GenkiSettings.manager, 10);
}
});
});
},


// updates custom css
updateCustomCSS : function (caller, updateCSS) {
// update the CSS
Expand Down
2 changes: 1 addition & 1 deletion resources/javascript/head.min.js

Large diffs are not rendered by default.

0 comments on commit 647b553

Please sign in to comment.