one cookie set function, for consistent samesite/path/expires
This commit is contained in:
parent
532dbdc751
commit
e5c8bf7b18
9 changed files with 34 additions and 27 deletions
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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: "/"});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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];
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = '';
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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(""+
|
||||
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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("|"));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -23,14 +23,14 @@ class CustomSetupTheme extends SetupTheme
|
|||
$(\"#$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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -23,14 +23,14 @@ class CustomUserConfigTheme extends UserConfigTheme
|
|||
$(\"#$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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
@ -29,12 +29,12 @@ 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();
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ function toggleDesktop() {
|
|||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if(Cookies.get("ui-desktop") === "true") {
|
||||
if(shm_cookie_get("ui-desktop") === "true") {
|
||||
toggleDesktop();
|
||||
}
|
||||
});
|
||||
|
|
Reference in a new issue