Insert 0-witdh into Tweet

Prevent your tweet from searching

当前为 2021-09-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Insert 0-witdh into Tweet
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Prevent your tweet from searching
  6. // @author eggplants
  7. // @homepage https://github.com/eggplants
  8. // @match https://twitter.com/compose/tweet
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. /*jshint esversion: 8 */
  13.  
  14. function rafAsync() {
  15. return new Promise(resolve => {
  16. requestAnimationFrame(resolve);
  17. });
  18. }
  19.  
  20. async function checkElement(selector) {
  21. let q = null;
  22. while (q === null) {
  23. await rafAsync();
  24. q = document.querySelector(selector);
  25. }
  26. return q;
  27. }
  28.  
  29. window.onload = function () {
  30. "use strict";
  31. let btn = document.createElement("button");
  32. btn.innerHTML = "Insert 0-width space";
  33. btn.onclick = function () {
  34. let elms = Array.from(
  35. document.querySelectorAll('span[data-text="true"],br[data-text="true"]')
  36. );
  37. if (elms.length === 0) {
  38. // do nothing
  39. } else if (elms.length === 1) {
  40. alert(
  41. "Put a new line and atleast one space at the end of your tweet!"
  42. );
  43. } else {
  44. elms.forEach((e) => {
  45. e.innerText = e.innerText
  46. .replaceAll("​", "")
  47. .replaceAll(/(.)/g, "$1​");
  48. });
  49. console.log("inserted!");
  50. }
  51. };
  52. const qs =
  53. "div.css-1dbjc4n.r-1iusvr4.r-16y2uox.r-1777fci" +
  54. ".r-1h8ys4a.r-1bylmt5.r-13tjlyg.r-7qyjyx.r-1ftll1t" +
  55. "> div:nth-child(3) > div > div > div:nth-child(1)";
  56. checkElement(qs).then((e) => {
  57. console.info(e);
  58. e.appendChild(btn);
  59. });
  60. console.log("loaded!");
  61. };

QingJ © 2025

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