NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name ShikiCSSComments
// @namespace http://tampermonkey.net/
// @version 2024-08-28
// @description Comment your css code!
// @author Dedonych
// @match https://shikimori.one/*
// @updateURL https://openuserjs.org/meta/Dedonych/ShikiMirror_comments.meta.js
// @downloadURL https://openuserjs.org/install/Dedonych/ShikiMirror_comments.user.js
// @icon https://www.google.com/s2/favicons?sz=64&domain=shikimori.one
// @license MIT
// @grant none
// ==/UserScript==
addEventListener("keydown", (e) => {
if (e.ctrlKey && e.code == "Slash") {
const cmtmp = document.querySelector(".p-profiles-edit .CodeMirror");
// if not CodeMirror = return
if (!cmtmp) return;
const cm = cmtmp.CodeMirror;
// get value of textarea
const value = cm.getValue().split("\n");
// get selected ranges
const selectedArray = cm.listSelections();
for (const r of selectedArray) {
//get lines
const {
anchor,
head
} = r;
// sort lines number;
const [x, y] = [anchor.line, head.line].sort((a, b) => a - b);
// defime has a comments
if (value[x].startsWith("/*") && value[y].endsWith("*/")) {
// define spaces;
const [s_x, s_y] = [
value[x][2] == " " ? 3 : 2,
value[y][(value[y].length -= 3)] == " " ? -3 : -2,
];
value[x] = value[x].slice(s_x);
value[y] = value[y].slice(0, s_y);
}
else {
value[x] = "/* " + value[x];
value[y] = value[y] + " */";
}
cm.setValue(value.join("\n"));
// wait for load
setTimeout(() => {
cm.setCursor(head);
cm.setSelection(anchor, head);
}, 0);
}
}
});