Skip to content

Commit

Permalink
toggle AK_FORCE_ORIGIN cookie value
Browse files Browse the repository at this point in the history
  • Loading branch information
cvazac committed Sep 28, 2017
1 parent 4fdf9d5 commit 24f1e81
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions perfbar.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,40 @@ var UW = unsafeWindow;
}

function toggleDisableEdgeCache() {
const cookieName = 'AK_FORCE_ORIGIN'
var force = readCookie(cookieName)
if (force === 'true') {
return createCookie(cookieName, '', -1);
}
createCookie(cookieName, 'true', 1)
}

function toggleShowCacheStatus() {
setState("cacheStatus", getState("cacheStatus") ? false : true);
}

function init() {
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}

function createCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + value + expires + "; path=/";
}

function init() {
if (!UW.jQuery || !UW.jQuery.contextMenu) {
setTimeout(init, 100);
return;
Expand Down Expand Up @@ -600,7 +627,8 @@ var UW = unsafeWindow;
"disableEdgeCache": {
name: "Disable Edge Cache",
type: "checkbox",
events: { click: toggleDisableEdgeCache }
events: { click: toggleDisableEdgeCache },
selected: readCookie('AK_FORCE_ORIGIN') === 'true'
},
"showCacheStatus": {
name: "Show Cache Status",
Expand Down

0 comments on commit 24f1e81

Please sign in to comment.