Greasy Fork镜像 支持简体中文。

BSKY EZ HASHTAGS

Add pre-defined tags easily!

  1. // ==UserScript==
  2. // @name BSKY EZ HASHTAGS
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Add pre-defined tags easily!
  6. // @author minnie
  7. // @match https://bsky.app/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=bsky.app
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. const tags = {
  17. "myTags": "#add #your #tags"
  18. };
  19.  
  20. const styleEZ = document.createElement('style');
  21. styleEZ.innerHTML = `
  22. :root { color-scheme: light dark; }
  23. .light { color-scheme: light; }
  24. .dark { color-scheme: dark; }
  25. .EZOptions {
  26. display: none;
  27. position: relative;
  28. background-color: light-dark(#D8DFF2, #0F1B27);
  29. color: light-dark(#ffffff, #000000);
  30. border: 1px solid light-dark(#7B8EBF, #344F95);
  31. border-radius: 8px;
  32. padding: 10px;
  33. z-index: 100000000;
  34. box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  35. }
  36. .EZOptions.EZvisible { display: block; }
  37. `;
  38. document.head.appendChild(styleEZ);
  39.  
  40. document.addEventListener("DOMContentLoaded", () => {
  41. const htmlElement = document.documentElement;
  42. htmlElement.classList.add("light");
  43. });
  44.  
  45. const createTagButton = () => {
  46. const actionBtns = document.querySelector(".r-1xfd6ze > div:nth-child(1) > div:nth-child(1) > div:nth-child(4) > div:nth-child(1)");
  47. if (actionBtns && !document.querySelector(".custom-button")) {
  48. const newBtn = document.createElement("button");
  49. newBtn.setAttribute("aria-label", "Tags");
  50. newBtn.className = "css-175oi2r r-1loqt21 r-1otgn73 custom-button";
  51. newBtn.style.flexDirection = "row";
  52. newBtn.style.alignItems = "center";
  53. newBtn.style.justifyContent = "center";
  54. newBtn.style.borderRadius = "999px";
  55. newBtn.style.padding = "8px";
  56. newBtn.style.position = "relative";
  57. newBtn.innerHTML = `
  58. <svg class="w-6 h-6 text-gray-800 custom-button dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 24 24">
  59. <path fill="hsl(211, 99%, 53%)" d="M18.045 3.007 12.31 3a1.965 1.965 0 0 0-1.4.585l-7.33 7.394a2 2 0 0 0 0 2.805l6.573 6.631a1.957 1.957 0 0 0 1.4.585 1.965 1.965 0 0 0 1.4-.585l7.409-7.477A2 2 0 0 0 21 11.479v-5.5a2.972 2.972 0 0 0-2.955-2.972Zm-2.452 6.438a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"/>
  60. </svg>
  61. `;
  62. actionBtns.append(newBtn);
  63.  
  64. const options = document.createElement("div");
  65. options.classList.add("EZOptions");
  66. newBtn.appendChild(options);
  67.  
  68. for (const [key, value] of Object.entries(tags)) {
  69. const option = document.createElement("button");
  70. option.textContent = key;
  71. option.style.margin = "5px";
  72. option.style.padding = "5px 10px";
  73. option.style.border = "1px solid light-dark(#1471D5, #1471D5)";
  74. option.style.borderRadius = "4px";
  75. option.style.cursor = "pointer";
  76. option.style.backgroundColor = "light-dark(#1471D5, #000000)";
  77. option.style.color = "light-dark(#ffffff, #ffffff)";
  78.  
  79. option.addEventListener("click", () => {
  80. const textBox = document.querySelector(".tiptap");
  81. if (textBox) {
  82. textBox.focus();
  83. const range = document.createRange();
  84. range.selectNodeContents(textBox);
  85. range.collapse(false);
  86.  
  87. const selectedTags = tags[key];
  88. const textNode = document.createTextNode(`${selectedTags} `);
  89. range.insertNode(textNode);
  90.  
  91. range.setStartAfter(textNode);
  92. range.setEndAfter(textNode);
  93. const selection = window.getSelection();
  94. selection.removeAllRanges();
  95. selection.addRange(range);
  96.  
  97. textBox.dispatchEvent(new Event("input", { bubbles: true }));
  98. } else {
  99. console.log("TEXT BOX NOT FOUND");
  100. }
  101. });
  102.  
  103. options.appendChild(option);
  104. }
  105.  
  106. newBtn.addEventListener("click", (e) => {
  107. e.stopPropagation();
  108. options.classList.toggle("EZvisible");
  109. });
  110.  
  111. document.body.addEventListener("click", () => {
  112. options.classList.remove("EZvisible");
  113. });
  114. }
  115. };
  116.  
  117. const observer = new MutationObserver(() => {
  118. createTagButton();
  119. });
  120.  
  121. observer.observe(document.body, {
  122. childList: true,
  123. subtree: true
  124. });
  125. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址