Skip to content

Commit

Permalink
one cookie set function, for consistent samesite/path/expires
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 26, 2023
1 parent 532dbdc commit e5c8bf7
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 27 deletions.
6 changes: 3 additions & 3 deletions ext/blotter/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ document.addEventListener('DOMContentLoaded', () => {
$(".shm-blotter2-toggle").click(function() {
$(".shm-blotter2").slideToggle("slow", function() {
if($(".shm-blotter2").is(":hidden")) {
Cookies.set("ui-blotter2-hidden", 'true');
shm_cookie_set("ui-blotter2-hidden", 'true');
}
else {
Cookies.set("ui-blotter2-hidden", 'false');
shm_cookie_set("ui-blotter2-hidden", 'false');
}
});
});
if(Cookies.get("ui-blotter2-hidden") === 'true') {
if(shm_cookie_get("ui-blotter2-hidden") === 'true') {
$(".shm-blotter2").hide();
}
});
8 changes: 4 additions & 4 deletions ext/handle_pixel/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ document.addEventListener('DOMContentLoaded', () => {
$(".shm-zoomer").val(zoom_type);

if (save_cookie) {
Cookies.set("ui-image-zoom", zoom_type, {expires: 365});
shm_cookie_set("ui-image-zoom", zoom_type, {expires: 365, samesite: "lax", path: "/"});
}
}

Expand All @@ -38,13 +38,13 @@ document.addEventListener('DOMContentLoaded', () => {
});

$("img.shm-main-image").click(function(e) {
switch(Cookies.get("ui-image-zoom")) {
switch(shm_cookie_get("ui-image-zoom")) {
case "full": zoom("width"); break;
default: zoom("full"); break;
}
});

if(Cookies.get("ui-image-zoom")) {
zoom(Cookies.get("ui-image-zoom"));
if(shm_cookie_get("ui-image-zoom")) {
zoom(shm_cookie_get("ui-image-zoom"));
}
});
6 changes: 3 additions & 3 deletions ext/index/script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*jshint bitwise:false, curly:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:false, strict:false, browser:true, jquery:true */

document.addEventListener('DOMContentLoaded', () => {
var blocked_tags = (Cookies.get("ui-blocked-tags") || "").split(" ");
var blocked_tags = (shm_cookie_get("ui-blocked-tags") || "").split(" ");
var needs_refresh = false;
for(var i=0; i<blocked_tags.length; i++) {
var tag = blocked_tags[i];
Expand Down Expand Up @@ -49,9 +49,9 @@ document.addEventListener('DOMContentLoaded', () => {
});

function select_blocked_tags() {
var blocked_tags = prompt("Enter tags to ignore", Cookies.get("ui-blocked-tags") || "AI-generated");
var blocked_tags = prompt("Enter tags to ignore", shm_cookie_get("ui-blocked-tags") || "AI-generated");
if(blocked_tags !== null) {
Cookies.set("ui-blocked-tags", blocked_tags.toLowerCase(), {expires: 365});
shm_cookie_set("ui-blocked-tags", blocked_tags.toLowerCase());
location.reload(true);
}
}
2 changes: 1 addition & 1 deletion ext/pools/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
document.addEventListener('DOMContentLoaded', () => {
$('#order_pool').change(function(){
var val = $("#order_pool option:selected").val();
Cookies.set("shm_ui-order-pool", val, {path: '/', expires: 365}); //FIXME: This won't play nice if COOKIE_PREFIX is not "shm_".
shm_cookie_set("shm_ui-order-pool", val); //FIXME: This won't play nice if COOKIE_PREFIX is not "shm_".
window.location.href = '';
});
});
4 changes: 2 additions & 2 deletions ext/rule34/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
document.addEventListener('DOMContentLoaded', () => {
if(Cookies.get("ui-tnc-agreed") !== "true" && window.location.href.indexOf("/wiki/") == -1) {
if(shm_cookie_get("ui-tnc-agreed") !== "true" && window.location.href.indexOf("/wiki/") == -1) {
$("BODY").addClass("censored");
$("BODY").append("<div class='tnc_bg'></div>");
$("BODY").append(""+
Expand All @@ -13,7 +13,7 @@ document.addEventListener('DOMContentLoaded', () => {
});

function tnc_agree() {
Cookies.set("ui-tnc-agreed", "true", {path: '/', expires: 365});
shm_cookie_set("ui-tnc-agreed", "true");
$("BODY").removeClass("censored");
$(".tnc_bg").hide();
$(".tnc").hide();
Expand Down
11 changes: 9 additions & 2 deletions ext/static_files/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/*jshint bitwise:false, curly:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:false, strict:false, browser:true */

function shm_cookie_set(name, value) {
Cookies.set(name, value, {expires: 365, samesite: "lax", path: "/"});
}
function shm_cookie_get(name) {
return Cookies.get(name);
}

document.addEventListener('DOMContentLoaded', () => {
/** Load jQuery extensions **/
//Code via: https://stackoverflow.com/a/13106698
Expand Down Expand Up @@ -32,7 +39,7 @@ document.addEventListener('DOMContentLoaded', () => {
/** Setup sidebar toggle **/
let sidebar_hidden = [];
try {
sidebar_hidden = (Cookies.get("ui-sidebar-hidden") || "").split("|");
sidebar_hidden = (shm_cookie_get("ui-sidebar-hidden") || "").split("|");
for (let i=0; i<sidebar_hidden.length; i++) {
if(sidebar_hidden[i].length > 0) {
$(sidebar_hidden[i]+" .blockbody").hide();
Expand All @@ -55,7 +62,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
}
Cookies.set("ui-sidebar-hidden", sidebar_hidden.join("|"), {expires: 365});
shm_cookie_set("ui-sidebar-hidden", sidebar_hidden.join("|"));
});
});

Expand Down
6 changes: 3 additions & 3 deletions themes/lite/setup.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ protected function sb_to_html(SetupBlock $block): string
$(\"#$i-toggle\").click(function() {
$(\"#$i\").slideToggle(\"slow\", function() {
if($(\"#$i\").is(\":hidden\")) {
Cookies.set(\"$i-hidden\", 'true', {path: '/'});
shm_cookie_set(\"$i-hidden\", 'true');
}
else {
Cookies.set(\"$i-hidden\", 'false', {path: '/'});
shm_cookie_set(\"$i-hidden\", 'false');
}
});
});
if(Cookies.get(\"$i-hidden\") == 'true') {
if(shm_cookie_get(\"$i-hidden\") == 'true') {
$(\"#$i\").hide();
}
});
Expand Down
6 changes: 3 additions & 3 deletions themes/lite/user_config.theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ protected function sb_to_html(SetupBlock $block): string
$(\"#$i-toggle\").click(function() {
$(\"#$i\").slideToggle(\"slow\", function() {
if($(\"#$i\").is(\":hidden\")) {
Cookies.set(\"$i-hidden\", 'true', {path: '/'});
shm_cookie_set(\"$i-hidden\", 'true');
}
else {
Cookies.set(\"$i-hidden\", 'false', {path: '/'});
shm_cookie_set(\"$i-hidden\", 'false');
}
});
});
if(Cookies.get(\"$i-hidden\") == 'true') {
if(shm_cookie_get(\"$i-hidden\") == 'true') {
$(\"#$i\").hide();
}
});
Expand Down
12 changes: 6 additions & 6 deletions themes/rule34v2/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ var navHidden = false;
function toggleNav() {
if(navHidden) {
$('BODY').removeClass('navHidden');
Cookies.set("ui-shownav", "true");
shm_cookie_set("ui-shownav", "true");
}
else {
$('BODY').addClass('navHidden');
Cookies.set("ui-shownav", "false");
shm_cookie_set("ui-shownav", "false");
}
navHidden = !navHidden;
}

document.addEventListener('DOMContentLoaded', () => {
if(Cookies.get("ui-shownav") === "false") {
if(shm_cookie_get("ui-shownav") === "false") {
toggleNav();
}
});
Expand All @@ -29,20 +29,20 @@ function toggleDesktop() {
if(forceDesktop) {
let viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', 'width=512');
Cookies.set("ui-desktop", "false");
shm_cookie_set("ui-desktop", "false");
}
else {
let viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', 'width=1024, initial-scale=0.4');
Cookies.set("ui-desktop", "true");
shm_cookie_set("ui-desktop", "true");
navHidden = true;
toggleNav();
}
forceDesktop = !forceDesktop;
}

document.addEventListener('DOMContentLoaded', () => {
if(Cookies.get("ui-desktop") === "true") {
if(shm_cookie_get("ui-desktop") === "true") {
toggleDesktop();
}
});

0 comments on commit e5c8bf7

Please sign in to comment.