Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name 8chan Keybinds
- // @namespace alleyesonus
- // @version 2025-04-16
- // @description Add keybinds to format text on 8chan.moe
- // @author Anko
- // @match https://8chan.moe/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // Function to wrap selected text with the appropriate tag
- function wrapSelection(tag) {
- const textarea = document.activeElement;
- if (textarea && textarea.tagName === 'TEXTAREA') {
- const start = textarea.selectionStart;
- const end = textarea.selectionEnd;
- const selectedText = textarea.value.substring(start, end);
- if (selectedText) {
- // Split selected text into lines and wrap each line (skip empty lines)
- const lines = selectedText.split('\n');
- const wrappedLines = lines.map(line => {
- // Skip empty lines
- if (line.trim() === '') return '';
- switch (tag) {
- case 'spoiler':
- return `[spoiler]${line}[/spoiler]`;
- case 'greenText':
- return `>${line}`;
- case 'pinktext':
- return `<${line}`;
- case 'doom':
- return `[doom]${line}[/doom]`;
- case 'bizniz':
- return `==${line}==`;
- case 'moe':
- return `[moe]${line}[/moe]`;
- default:
- return line;
- }
- });
- const wrappedText = wrappedLines.join('\n');
- // Insert the wrapped text back into the textarea
- const beforeText = textarea.value.substring(0, start);
- const afterText = textarea.value.substring(end);
- textarea.value = beforeText + wrappedText + afterText;
- }
- }
- }
- // Event listener for keydown events to capture keybinds
- document.addEventListener('keydown', function(event) {
- const textarea = document.activeElement;
- // Only respond if a textarea is focused
- if (!textarea || textarea.tagName !== 'TEXTAREA') return;
- if (event.ctrlKey) {
- let tag = null;
- switch (event.key) {
- case 's':
- tag = 'spoiler';
- break;
- case 'p':
- tag = 'pinktext';
- break;
- case 'm':
- tag = 'moe';
- break;
- case 'd':
- tag = 'doom';
- break;
- case 'b':
- tag = 'bizniz';
- break;
- case 'g':
- tag = 'greenText';
- break;
- default:
- return;
- }
- event.preventDefault();
- wrapSelection(tag);
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment