mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
add a command to accept or reject cookies
This commit is contained in:
parent
a6cfae3762
commit
0aa936525a
1 changed files with 105 additions and 0 deletions
105
clite/user.js
105
clite/user.js
|
|
@ -598,4 +598,109 @@ Options:
|
|||
return main(args);
|
||||
});
|
||||
|
||||
clite.commands.load('cookie',function(args,env,io) {
|
||||
var stdio = io.include('stdio');
|
||||
var stdlib = io.include('stdlib');
|
||||
var clite = io.include('clite');
|
||||
|
||||
var pw = null;
|
||||
|
||||
function help() {
|
||||
stdio.printf(`
|
||||
cookie - set cookie options
|
||||
Usage: login [OPTION]
|
||||
|
||||
Options:
|
||||
-? Print this help information
|
||||
-a Accept all cookies and local storage
|
||||
-r Reject all cookies and local storage
|
||||
-c Check the current state of cookies
|
||||
`);
|
||||
}
|
||||
|
||||
function checkState(str) {
|
||||
if (str == 'no') {
|
||||
clite.setcookiestate(false);
|
||||
io.exit(0);
|
||||
return;
|
||||
}
|
||||
if (str != 'yes') {
|
||||
cookies();
|
||||
return;
|
||||
}
|
||||
|
||||
clite.setcookiestate(true);
|
||||
|
||||
io.exit(0);
|
||||
}
|
||||
|
||||
function cookies() {
|
||||
clite.cookienotice();
|
||||
|
||||
stdio.printf("Enter 'yes' to agree, or 'no' to cancel: ");
|
||||
if (!stdio.read(io.stdin,checkState)) {
|
||||
stdio.write(io.stderr,'internal error\n');
|
||||
io.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function main(args) {
|
||||
let accept = false;
|
||||
let reject = false;
|
||||
let check = false;
|
||||
for (var i=1; i<args.length; i++) {
|
||||
if (args[i][0] == '-') {
|
||||
for (var j=1; j<args[i].length; j++) {
|
||||
switch (args[i][j]) {
|
||||
case '?':
|
||||
help();
|
||||
return 0;
|
||||
break;
|
||||
case 'a':
|
||||
accept = true;
|
||||
break;
|
||||
case 'c':
|
||||
check = true;
|
||||
break;
|
||||
case 'r':
|
||||
reject = true;
|
||||
break;
|
||||
default:
|
||||
stdio.fprintf(io.stderr,'unknown argument: -%c\n',args[i][j]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
stdio.fprintf(io.stderr,'unknown argument: %s\n',args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (reject) {
|
||||
clite.setcookiestate(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (accept) {
|
||||
clite.setcookiestate(true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (check) {
|
||||
let s = clite.getcookiestate();
|
||||
if (s == false) {
|
||||
stdio.write(io.stdout,"Cookies are currently being rejected\n");
|
||||
}else if (s == true) {
|
||||
stdio.write(io.stdout,"Cookies are currently being accepted\n");
|
||||
}else{
|
||||
stdio.write(io.stdout,"You have not set a cookie preference (rejected by default)\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
cookies();
|
||||
return null;
|
||||
}
|
||||
|
||||
return main(args);
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue