// ==UserScript== // @name Giggles&Shit (GAS) // @namespace https://github.com/havaianasdestruido/Giggles-Shit // @version 2.3.0 // @description Giggles&Shit emoji/image picker for GitHub // @author havaianasdestruido // @match https://github.com/* // @match https://gist.github.com/* // @icon https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/trollge.jpg // @grant none // @run-at document-idle // ==/UserScript== (() => { 'use strict'; // ============================================================ // CONFIG // ============================================================ const GAS_VERSION = '2.3.0'; const REPO_URL = 'https://github.com/havaianasdestruido/Giggles-Shit/issues/new'; const DEFAULT_GAS = [ { name: '84', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/84.jpeg' }, { name: 'boo', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/boo.gif' }, { name: 'bulleh', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/bulleh.jpg' }, { name: 'crine', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/crine.jpg' }, { name: 'fire', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/fire.jpeg' }, { name: 'hmm', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/hmm.webp' }, { name: 'rose', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/rose.jpg' }, { name: 'skull', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/skull.jpg' }, { name: 'trollge', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/trollge.jpg' }, { name: 'wet', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/wet.webp' }, { name: 'woah', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/woah.webp' }, { name: 'yeah', url: 'https://raw.githubusercontent.com/havaianasdestruido/Giggles-Shit/refs/heads/main/res/img/yeah.webp' } ]; // ============================================================ // STATE // ============================================================ const state = { editors: new Set(), buttons: new Set(), activeEditor: null, picker: null, observer: null, scanTimer: null, initialized: false }; // ============================================================ // LOGGING // ============================================================ function log(...args) { console.log( '%c[GAS]%c', 'font-weight:bold;color:#f85149', 'font-weight:normal', ...args ); } function warn(...args) { console.warn( '%c[GAS]%c', 'font-weight:bold;color:#d29922', 'font-weight:normal', ...args ); } function error(...args) { console.error( '%c[GAS]%c', 'font-weight:bold;color:#ff7b72', 'font-weight:normal', ...args ); } // ============================================================ // STYLES // ============================================================ function installStyles() { if (document.getElementById('gas-styles')) { return; } const style = document.createElement('style'); style.id = 'gas-styles'; style.textContent = ` /* ================================================== GAS TOOLBAR BUTTON ================================================== */ .gas-toolbar-button { appearance: none; border: 0; background: transparent; color: var(--fgColor-default, #f0f6fc); width: 32px; height: 32px; padding: 5px; margin: 0; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background-color 0.12s ease, transform 0.12s ease; } .gas-toolbar-button:hover { background: var( --bgColor-neutral-muted, rgba(177,186,196,.12) ); } .gas-toolbar-button:active { transform: scale(.92); } .gas-toolbar-button img { width: 20px; height: 20px; object-fit: cover; border-radius: 4px; pointer-events: none; } /* ================================================== PICKER ================================================== */ .gas-picker { position: fixed; z-index: 2147483647; width: min( 360px, calc(100vw - 24px) ); max-height: min( 430px, calc(100vh - 24px) ); padding: 10px; background: var( --bgColor-default, #0d1117 ); color: var( --fgColor-default, #f0f6fc ); border: 1px solid var( --borderColor-default, #30363d ); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.2); overflow: auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; display: none; animation: gas-picker-in .12s ease-out; } @keyframes gas-picker-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } } .gas-picker-header { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 10px; margin-bottom: 4px; border-bottom: 1px solid var( --borderColor-muted, #21262d ); } .gas-picker-title { font-size: 13px; font-weight: 600; } .gas-picker-subtitle { margin-top: 2px; font-size: 11px; opacity: .6; } .gas-picker-close { appearance: none; border: 0; background: transparent; width: 28px; height: 28px; color: inherit; cursor: pointer; border-radius: 6px; font-size: 18px; line-height: 1; } .gas-picker-close:hover { background: var( --bgColor-neutral-muted, rgba(177,186,196,.12) ); } .gas-grid { display: grid; grid-template-columns: repeat( auto-fill, minmax(72px, 1fr) ); gap: 7px; } .gas-item { appearance: none; min-width: 0; padding: 6px; border: 1px solid var( --borderColor-default, #30363d ); background: var( --bgColor-neutral-muted, rgba(177,186,196,.05) ); color: inherit; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 5px; transition: background-color .12s ease, border-color .12s ease, transform .12s ease; } .gas-item:hover { background: var( --bgColor-neutral-muted, rgba(177,186,196,.12) ); border-color: var( --borderColor-accent-emphasis, #58a6ff ); transform: translateY(-1px); } .gas-item:active { transform: scale(.95); } .gas-item img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; background: #161b22; display: block; } .gas-item-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 500; } .gas-item-code { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; opacity: .5; } /* ================================================== TOAST ================================================== */ .gas-toast { position: fixed; left: 50%; bottom: 24px; z-index: 2147483647; transform: translateX(-50%); padding: 8px 12px; background: var( --bgColor-neutral-emphasis-plus, #21262d ); color: var( --fgColor-onEmphasis, #ffffff ); border-radius: 7px; font-size: 12px; font-weight: 500; box-shadow: 0 5px 18px rgba(0,0,0,.3); pointer-events: none; animation: gas-toast-in .12s ease-out; } @keyframes gas-toast-in { from { opacity: 0; transform: translateX(-50%) translateY(5px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } } `; document.head.appendChild(style); log('Styles installed.'); } // ============================================================ // UTILITIES // ============================================================ function isVisible(element) { if (!element) { return false; } const rect = element.getBoundingClientRect(); const computed = getComputedStyle(element); return ( rect.width > 0 && rect.height > 0 && computed.display !== 'none' && computed.visibility !== 'hidden' ); } function isEditor(element) { if (!(element instanceof HTMLElement)) { return false; } if ( element.tagName === 'TEXTAREA' ) { const placeholder = element.getAttribute( 'placeholder' ) || ''; const ariaLabel = element.getAttribute( 'aria-label' ) || ''; const name = element.getAttribute( 'name' ) || ''; if ( /description|comment/i.test( placeholder ) || /markdown|comment/i.test( ariaLabel ) || /description|comment|body/i.test( name ) ) { return true; } // Fallback for hosts whose markup doesn't match the // heuristics above (e.g. gist.github.com comment boxes // use different attribute naming than github.com). Comment // editors are always real