Modified ad display and cookie tracking systems.

This commit is contained in:
00Fjongl 2024-07-08 01:26:03 -05:00
parent 9c124f085f
commit 3dc8e0cb9b
4 changed files with 68 additions and 98 deletions

View file

@ -11,13 +11,12 @@ export { insertText, paintSource, tryReadFile };
// stringOrFunctionToGenerateNewText); // stringOrFunctionToGenerateNewText);
*/ */
const insertText = (lis, str, newText) => { const insertText = (lis, str, newText) => {
// The lis argument should be a list of strings containing placeholders.
// This will put other relevant argument types, like a string, into a list.
lis = [].concat(lis);
let position; let position;
// Loop through each of the placeholder strings.
for (let placeholder of lis) { // The lis argument should be a list of strings containing placeholders.
// Ensure lis is formatted as a list, and loop through each of the
// placeholder strings.
for (let placeholder of [].concat(lis)) {
// Find all matches of a placeholder string and insert new text there. // Find all matches of a placeholder string and insert new text there.
while ((position = str.indexOf(placeholder)) >= 0) while ((position = str.indexOf(placeholder)) >= 0)
str = str.slice(0, position) str = str.slice(0, position)

View file

@ -1016,7 +1016,7 @@ details[open] summary {
height: 100%; height: 100%;
background-color: var(--nord1); background-color: var(--nord1);
overflow: hidden; overflow: hidden;
display: block; display: none;
z-index: 1; z-index: 1;
} }

View file

@ -4,133 +4,104 @@
/* Settings Menu /* Settings Menu
/* ----------------------------------------------- */ /* ----------------------------------------------- */
(function() {
let date = new Date(); let date = new Date();
date.setFullYear(date.getFullYear() + 100); date.setFullYear(date.getFullYear() + 100);
date = date.toUTCString(); date = date.toUTCString();
let csel = document.getElementById("csel"); const setCookie = (name, value) => {
document.cookie = name + `=${encodeURIComponent(value)}; expires=${date}; SameSite=None; Secure`;
};
function setCookie(name, value) { const removeCookie = name => {
document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + date + "; ";
}
function removeCookie(name) {
document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT; "; document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT; ";
} };
async function readCookie(name) { const readCookie = async name => {
let cookie = document.cookie.split("; "); for (let cookie of document.cookie.split("; "))
let cookies = {}; if (!cookie.indexOf(name + "="))
for (let i = 0; i < cookie.length; i++) { return decodeURIComponent(cookie.slice(name.length + 1));
let p = cookie[i].split("="); };
cookies[p[0]] = p[1];
}
return decodeURIComponent(cookies[name]);
}
function pageTitle(value) { const pageTitle = value => {
let tag = document.getElementsByTagName("title")[0] || document.createElement("title"); let tag = document.getElementsByTagName("title")[0] || document.createElement("title");
tag.innerHTML = value; tag.innerHTML = value;
document.head.appendChild(tag); document.head.appendChild(tag);
} }
function pageIcon(value) { const pageIcon = value => {
let tag = document.querySelector("link[rel*='icon']") || document.createElement("link"); let tag = document.querySelector("link[rel*='icon']") || document.createElement("link");
tag.rel = "icon"; tag.rel = "icon";
tag.href = value; tag.href = value;
document.head.appendChild(tag); document.head.appendChild(tag);
} }
function setTitle(value) {
pageTitle(value);
setCookie("HBTitle", value);
}
function setIcon(value) {
pageIcon(value);
setCookie("HBIcon", value);
}
function pageHideAds() { function pageHideAds() {
document.querySelectorAll(".ad").forEach(n => n.style.display = "none"); (document.getElementById('advertising')||new Text()).remove();
} }
function pageShowAds() { function pageShowAds() {
document.querySelectorAll(".ad").forEach(n => n.style.display = "block"); let advertising = document.createElement('style');
advertising.id = "advertising";
advertising.innerText = `.ad { display:block; }`;
document.appendChild.bind(document.head || document.body || document.documentElement || document)(advertising);
} }
function hideAds() { readCookie("HBTitle").then(s => (s != undefined) && pageTitle(s));
pageHideAds(); readCookie("HBIcon").then(s => (s != undefined) && pageIcon(s));
setCookie("HBHideAds", "true");
}
// Ghetto Default Disable Ads readCookie("HBHideAds").then(s => (s != "false") ? pageHideAds() : pageShowAds((document.getElementById("hideads") || {}).checked = 0));
setCookie("HBHideAds", "true");
function showAds() { if (document.getElementById('csel')) {
pageShowAds(); document.getElementById("titleform").addEventListener("submit", e => {
removeCookie("HBHideAds");
}
readCookie("HBTitle").then(s => (s != "undefined") && pageTitle(s));
readCookie("HBIcon").then(s => (s != "undefined") && pageIcon(s));
readCookie("HBHideAds").then(s => (s != "undefined") &&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WUlM0QlMjJBcHBseSUyMiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0NpbnB1dCUyMGlkJTNEJTIyY3NlbHJlc2V0JTIyJTIwY2xhc3MlM0QlMjJjc2VsYnV0dG9uJTIyJTIwdHlwZSUzRCUyMmJ1dHRvbiUyMiUyMHZhbHVlJTNEJTIyUmVzZXQlMjIlM0UlMEElM0NpbnB1dCUyMGlkJTNEJTIyY3NlbGFiJTIyJTIwY2xhc3MlM0QlMjJjc2VsYnV0dG9uJTIyJTIwdHlwZSUzRCUyMmJ1dHRvbiUyMiUyMHZhbHVlJTNEJTIyYWJvdXQlM0FibGFuayUyMiUzRSUwQSUzQ3AlMjBjbGFzcyUzRCUyMmNzZWxsYWJlbCUyMiUzRSUwQSUyMCUyMCUyMCUyMCUzQ2lucHV0JTIwaWQlM0QlMjJoaWRlYWRzJTIyJTIwdHlwZSUzRCUyMmNoZWNrYm94JTIyJTNFJTBBJTIwJTIwJTIwJTIwJTNDc3BhbiUzRUhpZGUlMjBBZHMlM0MlMkZzcGFuJTNFJTBBJTNDJTJGcCUzRSUwQSUzQ3AlM0VBZHMlMjBoZWxwJTIwc3VwcG9ydCUyMEglMjYlMjMxNzMlM0JvJTI2JTIzMTczJTNCbHklMjBVJTI2JTIzMTczJTNCbmIlMjYlMjMxNzMlM0Jsb2NrJTI2JTIzMTczJTNCZXIhJTNDJTJGcCUzRQ=="));
document.getElementById("titleform").addEventListener("submit", function(e) {
e.preventDefault(); e.preventDefault();
if (this.firstElementChild.value) { e = this.firstElementChild;
setTitle(this.firstElementChild.value); if (e.value) {
this.firstElementChild.value = ""; pageTitle(e.value);
setCookie("HBTitle", e.value);
e.value = "";
} else { } else {
alert("Please provide a title."); alert("Please provide a title.");
} }
}, false); }, false);
document.getElementById("iconform").addEventListener("submit", function(e) { document.getElementById("iconform").addEventListener("submit", e => {
e.preventDefault(); e.preventDefault();
if (this.firstElementChild.value) { e = this.firstElementChild;
setIcon(this.firstElementChild.value); if (e.value) {
this.firstElementChild.value = ""; pageIcon(e.value);
setCookie("HBIcon", e.value);
e.value = "";
} else { } else {
alert("Please provide an icon URL."); alert("Please provide an icon URL.");
} }
}, false); }, false);
document.getElementById("cselreset").addEventListener("click", function() { document.getElementById("cselreset").addEventListener("click", () => {
if (confirm("Reset the title and icon to default?")) { if (confirm("Reset the title and icon to default?")) {
removeCookie("HBTitle"); removeCookie("HBTitle");
removeCookie("HBIcon"); removeCookie("HBIcon");
pageTitle("H&shy;o&shy;ly Un&shy;blo&shy;ck&shy;er"); pageTitle("Holy Unblocker");
pageIcon("assets/img/icon.png"); pageIcon("assets/img/icon.png");
} }
}, false); }, false);
document.getElementById("cselab").addEventListener("click", function () { document.getElementById("cselab").addEventListener("click", () => {
var win = window.open() let win = window.open();
var url = `${window.location.href}` let iframe = win.document.createElement('iframe');
var iframe = win.document.createElement('iframe') iframe.style = "width: 100%; height: 100%; border: none; overflow: hidden; margin: 0; padding: 0; position: fixed; top: 0; left: 0";
iframe.style.width = "100%"; iframe.src = location.href;
iframe.style.height = "100%"; win.document.body.appendChild(iframe);
iframe.style.border = "none";
iframe.style.overflow = "hidden";
iframe.style.margin = "0";
iframe.style.padding = "0";
iframe.style.position = "fixed";
iframe.style.top = "0";
iframe.style.bottom = "0";
iframe.style.left = "0";
iframe.style.right = "0";
iframe.src = url;
win.document.body.appendChild(iframe)
}); });
document.getElementById("hideads").addEventListener("change", function(e) { document.getElementById("hideads").addEventListener("change", e => {
e.target.checked ? hideAds() : showAds(); if (e.target.checked) {
pageHideAds();
setCookie("HBHideAds", "true");
} else {
pageShowAds();
setCookie("HBHideAds", "false");
}
}, false); }, false);
} }
})();

View file

@ -1,16 +1,16 @@
<p class="cseltitle">Tab Cloak</p> <p class=cseltitle>Tab Cloak</p>
<p class="csellabel">Change the title:</p> <p class=csellabel>Change the title:</p>
<form class="cselform" id="titleform"> <form class=cselform id=titleform>
<input type="text" placeholder="Tab Title" spellcheck="false"><input class="cselbutton" type="submit" value="Apply"> <input type=text placeholder=Tab Title spellcheck=false><input class=cselbutton type=submit value=Apply>
</form> </form>
<p class="csellabel">Change the <a href="/?i">icon</a>:</p> <p class=csellabel>Change the <a href=/?i>icon</a>:</p>
<form class="cselform" id="iconform"> <form class=cselform id=iconform>
<input type="text" placeholder="Icon URL" spellcheck="false"><input class="cselbutton" type="submit" value="Apply"> <input type=text placeholder=Icon URL spellcheck=false><input class=cselbutton type=submit value=Apply>
</form> </form>
<input id="cselreset" class="cselbutton" type="button" value="Reset"> <input id=cselreset class=cselbutton type=button value=Reset>
<input id="cselab" class="cselbutton" type="button" value="about:blank"> <input id=cselab class=cselbutton type=button value=about:blank>
<p class="csellabel"> <p class=csellabel>
<input id="hideads" type="checkbox"> <input id=hideads type=checkbox checked>
<span>Hide Ads</span> <span>Hide Ads</span>
</p> </p>
<p>Ads are disabled forever.</p> <p>Ads are disabled forever.</p>