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-toggle").click(function() {
|
||||||
$(".shm-blotter2").slideToggle("slow", function() {
|
$(".shm-blotter2").slideToggle("slow", function() {
|
||||||
if($(".shm-blotter2").is(":hidden")) {
|
if($(".shm-blotter2").is(":hidden")) {
|
||||||
Cookies.set("ui-blotter2-hidden", 'true');
|
shm_cookie_set("ui-blotter2-hidden", 'true');
|
||||||
}
|
}
|
||||||
else {
|
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();
|
$(".shm-blotter2").hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,7 +24,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
$(".shm-zoomer").val(zoom_type);
|
$(".shm-zoomer").val(zoom_type);
|
||||||
|
|
||||||
if (save_cookie) {
|
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) {
|
$("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;
|
case "full": zoom("width"); break;
|
||||||
default: zoom("full"); break;
|
default: zoom("full"); break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(Cookies.get("ui-image-zoom")) {
|
if(shm_cookie_get("ui-image-zoom")) {
|
||||||
zoom(Cookies.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 */
|
/*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', () => {
|
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;
|
var needs_refresh = false;
|
||||||
for(var i=0; i<blocked_tags.length; i++) {
|
for(var i=0; i<blocked_tags.length; i++) {
|
||||||
var tag = blocked_tags[i];
|
var tag = blocked_tags[i];
|
||||||
|
@ -49,9 +49,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function select_blocked_tags() {
|
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) {
|
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);
|
location.reload(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
$('#order_pool').change(function(){
|
$('#order_pool').change(function(){
|
||||||
var val = $("#order_pool option:selected").val();
|
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 = '';
|
window.location.href = '';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
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").addClass("censored");
|
||||||
$("BODY").append("<div class='tnc_bg'></div>");
|
$("BODY").append("<div class='tnc_bg'></div>");
|
||||||
$("BODY").append(""+
|
$("BODY").append(""+
|
||||||
|
@ -13,7 +13,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function tnc_agree() {
|
function tnc_agree() {
|
||||||
Cookies.set("ui-tnc-agreed", "true", {path: '/', expires: 365});
|
shm_cookie_set("ui-tnc-agreed", "true");
|
||||||
$("BODY").removeClass("censored");
|
$("BODY").removeClass("censored");
|
||||||
$(".tnc_bg").hide();
|
$(".tnc_bg").hide();
|
||||||
$(".tnc").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 */
|
/*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', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
/** Load jQuery extensions **/
|
/** Load jQuery extensions **/
|
||||||
//Code via: https://stackoverflow.com/a/13106698
|
//Code via: https://stackoverflow.com/a/13106698
|
||||||
|
@ -32,7 +39,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
/** Setup sidebar toggle **/
|
/** Setup sidebar toggle **/
|
||||||
let sidebar_hidden = [];
|
let sidebar_hidden = [];
|
||||||
try {
|
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++) {
|
for (let i=0; i<sidebar_hidden.length; i++) {
|
||||||
if(sidebar_hidden[i].length > 0) {
|
if(sidebar_hidden[i].length > 0) {
|
||||||
$(sidebar_hidden[i]+" .blockbody").hide();
|
$(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-toggle\").click(function() {
|
||||||
$(\"#$i\").slideToggle(\"slow\", function() {
|
$(\"#$i\").slideToggle(\"slow\", function() {
|
||||||
if($(\"#$i\").is(\":hidden\")) {
|
if($(\"#$i\").is(\":hidden\")) {
|
||||||
Cookies.set(\"$i-hidden\", 'true', {path: '/'});
|
shm_cookie_set(\"$i-hidden\", 'true');
|
||||||
}
|
}
|
||||||
else {
|
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();
|
$(\"#$i\").hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,14 +23,14 @@ class CustomUserConfigTheme extends UserConfigTheme
|
||||||
$(\"#$i-toggle\").click(function() {
|
$(\"#$i-toggle\").click(function() {
|
||||||
$(\"#$i\").slideToggle(\"slow\", function() {
|
$(\"#$i\").slideToggle(\"slow\", function() {
|
||||||
if($(\"#$i\").is(\":hidden\")) {
|
if($(\"#$i\").is(\":hidden\")) {
|
||||||
Cookies.set(\"$i-hidden\", 'true', {path: '/'});
|
shm_cookie_set(\"$i-hidden\", 'true');
|
||||||
}
|
}
|
||||||
else {
|
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();
|
$(\"#$i\").hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,17 +8,17 @@ var navHidden = false;
|
||||||
function toggleNav() {
|
function toggleNav() {
|
||||||
if(navHidden) {
|
if(navHidden) {
|
||||||
$('BODY').removeClass('navHidden');
|
$('BODY').removeClass('navHidden');
|
||||||
Cookies.set("ui-shownav", "true");
|
shm_cookie_set("ui-shownav", "true");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('BODY').addClass('navHidden');
|
$('BODY').addClass('navHidden');
|
||||||
Cookies.set("ui-shownav", "false");
|
shm_cookie_set("ui-shownav", "false");
|
||||||
}
|
}
|
||||||
navHidden = !navHidden;
|
navHidden = !navHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
if(Cookies.get("ui-shownav") === "false") {
|
if(shm_cookie_get("ui-shownav") === "false") {
|
||||||
toggleNav();
|
toggleNav();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -29,12 +29,12 @@ function toggleDesktop() {
|
||||||
if(forceDesktop) {
|
if(forceDesktop) {
|
||||||
let viewport = document.querySelector("meta[name=viewport]");
|
let viewport = document.querySelector("meta[name=viewport]");
|
||||||
viewport.setAttribute('content', 'width=512');
|
viewport.setAttribute('content', 'width=512');
|
||||||
Cookies.set("ui-desktop", "false");
|
shm_cookie_set("ui-desktop", "false");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let viewport = document.querySelector("meta[name=viewport]");
|
let viewport = document.querySelector("meta[name=viewport]");
|
||||||
viewport.setAttribute('content', 'width=1024, initial-scale=0.4');
|
viewport.setAttribute('content', 'width=1024, initial-scale=0.4');
|
||||||
Cookies.set("ui-desktop", "true");
|
shm_cookie_set("ui-desktop", "true");
|
||||||
navHidden = true;
|
navHidden = true;
|
||||||
toggleNav();
|
toggleNav();
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ function toggleDesktop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
if(Cookies.get("ui-desktop") === "true") {
|
if(shm_cookie_get("ui-desktop") === "true") {
|
||||||
toggleDesktop();
|
toggleDesktop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue