// ==UserScript== // @name Hashtag Bundler for X/Twitter and Bluesky (Unified) // @namespace https://codymkw.nekoweb.org/ // @version 2.6.6 // @description Supercharge your hashtag workflow with a unified floating panel for both X and Bluesky. Rename bundles and enjoy a cleaner UI. // @match https://twitter.com/* // @match https://x.com/* // @match https://bsky.app/* // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @license MIT // @downloadURL none // ==/UserScript== (function () { 'use strict'; const PANEL_ID = "universal-hashtag-panel"; const STORAGE_KEY = "universalHashtagBundles"; const COMBINED_KEY = STORAGE_KEY + "_combined"; const COLLAPSED_KEY = STORAGE_KEY + "_collapsed"; const loadData = () => { try { return JSON.parse(GM_getValue(STORAGE_KEY, "{}") || "{}"); } catch { return {}; } }; const saveData = (v) => GM_setValue(STORAGE_KEY, JSON.stringify(v)); const loadCombined = () => { try { return JSON.parse(GM_getValue(COMBINED_KEY, "{}") || "{}"); } catch { return {}; } }; const saveCombined = (v) => GM_setValue(COMBINED_KEY, JSON.stringify(v)); const loadCollapsed = () => { try { return JSON.parse(GM_getValue(COLLAPSED_KEY, "false")); } catch { return false; } }; const saveCollapsed = (v) => GM_setValue(COLLAPSED_KEY, JSON.stringify(Boolean(v))); const el = (tag, props = {}, kids = []) => { const e = document.createElement(tag); for (const k in props) { if (k === "style" && typeof props[k] === "object") Object.assign(e.style, props[k]); else if (k === "html") e.innerHTML = props[k]; else e[k] = props[k]; } kids.forEach(c => e.appendChild(c)); return e; }; function getComposerTarget() { let node = document.querySelector('div[data-testid="tweetTextarea_0"]'); if (node) { const inner = node.querySelector('div[contenteditable="true"], [contenteditable="true"]'); if (inner) return { type: 'contenteditable', node: inner }; } const generic = document.querySelector('div[contenteditable="true"], [contenteditable="true"]'); if (generic) return { type: 'contenteditable', node: generic }; const ta = document.querySelector('textarea'); if (ta) return { type: 'textarea', node: ta }; return null; } function insertTextAtEnd(text) { const target = getComposerTarget(); if (!target) return false; if (target.type === 'textarea') { const ta = target.node; ta.focus(); ta.value = ta.value + text; ta.dispatchEvent(new Event('input', { bubbles: true })); return true; } else if (target.type === 'contenteditable') { const node = target.node; node.focus(); try { document.execCommand('insertText', false, text); return true; } catch (err) { node.textContent = node.textContent + text; return true; } } return false; } const createPanel = () => { if (document.getElementById(PANEL_ID)) return; const panel = el("div", { id: PANEL_ID, style: `position:fixed;right:20px;background:#1f1f1f;color:white;border-radius:12px;padding:10px;font-family:sans-serif;box-shadow:0 4px 14px rgba(0,0,0,0.5);z-index:999999;transition: all 0.2s ease-in-out;` }); const header = el("div", { style: "display:flex;justify-content:space-between;align-items:center;cursor:pointer;" }); const title = el("span", { textContent: "Hashtag Bundles", style: "font-weight:700;" }); const arrow = el("span", { textContent: "▼", style: "font-size:14px;" }); header.append(title, arrow); const container = el("div", { id: "bundle-container", style: "max-height:520px;overflow-y:auto;padding-right:6px;margin-top:8px;" }); panel.append(header, container); document.body.append(panel); let collapsed = loadCollapsed(); const updatePanelLook = (isCollapsed) => { container.style.display = isCollapsed ? "none" : "block"; arrow.textContent = isCollapsed ? "▲" : "▼"; panel.style.bottom = isCollapsed ? "35px" : "20px"; panel.style.width = isCollapsed ? "200px" : "340px"; }; updatePanelLook(collapsed); header.onclick = () => { collapsed = !collapsed; saveCollapsed(collapsed); updatePanelLook(collapsed); }; render(); function render() { container.innerHTML = ""; const data = loadData(); const actionBtn = (txt, bg, fn) => { const b = el("button", { textContent: txt, onclick: fn, style: `width:100%;padding:8px;margin-bottom:8px;border:none;border-radius:6px;background:${bg};color:white;font-weight:700;cursor:pointer;` }); return b; }; container.append(actionBtn("➕ New Bundle", "#5865F2", () => { const name = prompt("Bundle name?"); if (!name) return; const tags = prompt("Enter hashtags separated by spaces:"); if (!tags) return; data[name] = tags.split(/\s+/).filter(Boolean).map(t => t.startsWith("#") ? t : "#" + t); saveData(data); render(); })); container.append(actionBtn("🔗 Combine Bundles", "#9b59b6", openCreateCombinedModal)); container.append(actionBtn("📂 Show Combined", "#8e44ad", openCombinedPopup)); const select = el("select", { style: "width:100%;padding:8px;border-radius:6px;background:#262626;color:#fff;border:none;margin:8px 0;" }); select.append(el("option", { textContent: "-- Select a bundle --", value: "" })); Object.keys(data).sort().forEach(n => select.append(el("option", { textContent: n, value: n }))); container.append(select); const detail = el("div", { style: "background:#262626;border-radius:8px;padding:10px;display:none;" }); container.append(detail); select.onchange = () => { const bundleName = select.value; detail.innerHTML = ""; if (!bundleName) { detail.style.display = "none"; return; } const tagsArr = data[bundleName] || []; detail.append(el("div", { textContent: bundleName, style: "font-weight:700;margin-bottom:4px;" })); detail.append(el("div", { textContent: tagsArr.join(" "), style: "color:#ddd;font-size:12px;margin-bottom:8px;" })); const btns = el("div", { style: "display:flex;gap:4px;" }); const miniBtn = (t, bg, fn) => el("button", { textContent: t, onclick: fn, style: `flex:1;padding:6px 2px;font-size:11px;border:none;border-radius:4px;background:${bg};color:white;cursor:pointer;` }); btns.append(miniBtn("Insert", "#2196F3", () => insertTextAtEnd(tagsArr.join(" ") + " "))); // NEW: Enhanced Edit (Name + Tags) btns.append(miniBtn("Edit", "#555", () => { const newName = prompt("Edit Bundle Name:", bundleName); if (!newName) return; const newTags = prompt("Edit Hashtags:", tagsArr.join(" ")); if (!newTags) return; if (newName !== bundleName) delete data[bundleName]; data[newName] = newTags.split(/\s+/).filter(Boolean).map(t => t.startsWith("#") ? t : "#" + t); saveData(data); render(); })); btns.append(miniBtn("Delete", "#c0392b", () => { if (confirm(`Delete ${bundleName}?`)) { delete data[bundleName]; saveData(data); render(); } })); detail.append(btns); detail.style.display = "block"; }; } }; const openCombinedPopup = () => { const combined = loadCombined(); const keys = Object.keys(combined).sort(); if (!keys.length) return alert("No combined bundles."); const backdrop = el("div", { style: "position:fixed;left:0;top:0;width:100%;height:100%;background:rgba(0,0,0,0.4);z-index:999999;" }); const popup = el("div", { style: "position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);background:#1f1f1f;color:white;width:420px;padding:18px;border-radius:12px;z-index:1000000;" }); document.body.append(backdrop); backdrop.append(popup); popup.append(el("div", { textContent: "Combined Bundles", style: "font-weight:700;margin-bottom:12px;" })); keys.forEach(key => { const combo = combined[key]; // NEW: Stripping "Combined_" from the display label const displayLabel = combo.label.replace(/^Combined_/, ""); const wrap = el("div", { style: "background:#262626;border-radius:8px;padding:10px;margin-bottom:10px;" }); wrap.append(el("div", { textContent: displayLabel, style: "font-weight:700;color:#4CAF50;" })); wrap.append(el("div", { textContent: combo.tags.join(" "), style: "font-size:11px;color:#ccc;margin:4px 0;" })); const ins = el("button", { textContent: "Insert", onclick: () => insertTextAtEnd(combo.tags.join(" ") + " "), style: "padding:6px 12px;background:#2196F3;color:white;border:none;border-radius:4px;cursor:pointer;margin-right:8px;" }); const del = el("button", { textContent: "Delete", onclick: () => { delete combined[key]; saveCombined(combined); wrap.remove(); }, style: "padding:6px 12px;background:#c0392b;color:white;border:none;border-radius:4px;cursor:pointer;" }); wrap.append(ins, del); popup.append(wrap); }); backdrop.onclick = (e) => { if (e.target === backdrop) backdrop.remove(); }; }; const openCreateCombinedModal = () => { const data = loadData(); const bundles = Object.keys(data).sort(); if (!bundles.length) return alert("No bundles available."); const backdrop = el("div", { style: "position:fixed;left:0;top:0;width:100%;height:100%;background:rgba(0,0,0,0.4);z-index:999999;" }); const modal = el("div", { style: "position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);background:#1f1f1f;color:white;width:360px;padding:14px;border-radius:12px;z-index:1000000;" }); document.body.append(backdrop); backdrop.append(modal); modal.append(el("div", { textContent: "Combine Bundles", style: "font-weight:700;margin-bottom:10px;" })); let order = []; const list = el("div", { style: "max-height:200px;overflow:auto;" }); bundles.forEach(n => { const row = el("div", { style: "padding:4px;display:flex;align-items:center;gap:8px;" }); const cb = el("input", { type: "checkbox" }); cb.onchange = () => { if (cb.checked) order.push(n); else order = order.filter(x => x !== n); }; row.append(cb, el("span", { textContent: n })); list.append(row); }); const save = el("button", { textContent: "Create Combined", style: "width:100%;margin-top:10px;padding:8px;background:#27ae60;color:white;border:none;border-radius:6px;cursor:pointer;" }); save.onclick = () => { if (!order.length) return; const ts = Date.now(); const key = `Combined_${ts}`; const combined = loadCombined(); combined[key] = { label: `Combo_${order.join("_").slice(0,10)}_${ts.toString().slice(-4)}`, tags: [...new Set(order.flatMap(n => data[n]))] }; saveCombined(combined); backdrop.remove(); }; modal.append(list, save); backdrop.onclick = (e) => { if (e.target === backdrop) backdrop.remove(); }; }; let panelVisible = false; const observer = new MutationObserver(() => { const c = document.querySelector("textarea, div[contenteditable='true']"); if (c && !panelVisible) { createPanel(); panelVisible = true; } else if (!c && panelVisible) { const p = document.getElementById(PANEL_ID); if (p) p.remove(); panelVisible = false; } }); observer.observe(document.body, { childList: true, subtree: true }); if (document.querySelector("textarea, div[contenteditable='true']")) { createPanel(); panelVisible = true; } })();