Insert 0-width into Tweet

Prevent your tweet from searching

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

  1. // ==UserScript==
  2. // @name Insert 0-width 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. let elms_ns = elms.map(x=>x.tagName);
  38. if (elms.length === 0 || [...new Set(elms_ns.flat(1))] === ["BR"]) {
  39. // do nothing
  40. } else if (elms_ns.includes("SPAN") &&
  41. elms[elms.length-1].tagName !== "BR"
  42. ) {
  43. alert(
  44. "Put a new line at the end of your tweet!"
  45. );
  46. } else {
  47. elms.forEach((e) => {
  48. e.innerText = e.innerText
  49. .replaceAll("​", "")
  50. .replaceAll(/(.)/g, "$1​");
  51. });
  52. console.log("inserted!");
  53. }
  54. };
  55. const qs =
  56. "div.css-1dbjc4n.r-1iusvr4.r-16y2uox.r-1777fci" +
  57. ".r-1h8ys4a.r-1bylmt5.r-13tjlyg.r-7qyjyx.r-1ftll1t" +
  58. "> div:nth-child(3) > div > div > div:nth-child(1)";
  59. checkElement(qs).then((e) => {
  60. console.info(e);
  61. e.appendChild(btn);
  62. });
  63. console.log("loaded!");
  64. };

QingJ © 2025

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