hatjitsu Admin Manager

Grant and revoke admin rights for the hatjitsu tool.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        hatjitsu Admin Manager
// @namespace   Violentmonkey Scripts
// @icon        data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABX0lEQVQ4T72QPUsDQRCG39nLmUsuiQhCggpaCGLQQhS0MIraWfiL7AR7SxsFO1EQ7EMKxcYioBLBz1hENB9qcUYwt7eyK7dGSQJB8Wl2hp15ZnbpML0j8AvozwWDyTEd+1zlsjr+yTdBo2afZhItaNXs00jyv4K3qoNC/lJPl7S1wUuliPJjQeeStgQt/yBkR5HoHUAmnUGHGcDM/Jxfo+Cui9uLU537aMHZ+R36ehIgRvC4B845plLTqqhZs0QJSmUHxBisoIlajYOIIIQACOjqtHRxI2h1ZVmMJofURMaYOg3DUJtwlwPEcH2Tx+TEsG6qh/a2N4UnpwFgRGoTeapLRhDe5132JIeF2XEV10P7u1tCrmyaBoqlJ8RiUTivVdghS8s8z1NbyWfdPxQxMtz/JdhYXxORSBjvNRce5wiYAQQMA45TRTzejUrlGbYdhmUF1ZPkMMnB0TGWFlP4AHefpMF5BmMVAAAAAElFTkSuQmCC
// @license MIT
// @version     1.0.0
//
// @match       https://hatjitsu.toolforge.org/*
// @grant       GM.cookie
// @grant       GM.registerMenuCommand
//
// @author      kleinph
// @description Grant and revoke admin rights for the hatjitsu tool.
// ==/UserScript==

const id = window.location.pathname?.replace('/', '');
const cookieName = `admin-${id}`;

GM.cookie.list({ name: cookieName }).then(cookies => {
  if (cookies.length > 0) {
    GM.registerMenuCommand('User', removeAdmin, { title: 'Revoke admin privileges', icon: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIxLjc1IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPgogIDxwYXRoIGQ9Ik0xMiAyIEwyMCA1IFYxMSBDMjAgMTYgMTYuNSAyMC41IDEyIDIyIEM3LjUgMjAuNSA0IDE2IDQgMTEgVjUgWiIvPgogIDxwYXRoIGQ9Ik0zIDMgTDIxIDIxIi8+Cjwvc3ZnPgo=' });
  } else {
    GM.registerMenuCommand('Admin', makeAdmin, { title: 'Grant admin privileges', icon: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0Ij4KICA8cGF0aCBkPSJNMTIgMiBMMjAgNSBWMTEgQzIwIDE2IDE2LjUgMjAuNSAxMiAyMiBDNy41IDIwLjUgNCAxNiA0IDExIFY1IFoiIGZpbGw9ImN1cnJlbnRDb2xvciIgc3Ryb2tlPSJjdXJyZW50Q29sb3IiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+Cjwvc3ZnPgo=' });
  }
});


function makeAdmin() {
  GM.cookie.set({ name: cookieName, value: 'false' })
    .then(() => window.location.reload())
    .catch(error => console.log('Making Admin failed:', error));
}

function removeAdmin() {
  GM.cookie.delete({ name: cookieName })
    .then(() => window.location.reload())
    .catch(error => console.log('Losing Admin failed:', error));
}