hatjitsu Admin Manager

Grant and revoke admin rights for the hatjitsu tool.

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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));
}