BlueskyTranslateDeepL

Blueskyの「Translate...」をDeepLで開くようにする

  1. // ==UserScript==
  2. // @name BlueskyTranslateDeepL
  3. // @namespace https://nigauri.me/
  4. // @version 0.6
  5. // @description Blueskyの「Translate...」をDeepLで開くようにする
  6. // @author nigauri
  7. // @match https://staging.bsky.app/*
  8. // @match https://bsky.app/*
  9. // @icon https://bsky.app/static/apple-touch-icon.png
  10. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. const parentBlockCSSFeed = "div.css-175oi2r.r-18u37iz.r-1cvj4g8:visible";
  15. const parentBlockCSSSearch = "div.css-175oi2r.r-5kkj8d.r-1sp51qo.r-ry3cjt:visible";
  16. const parentBlockCSSPostThreadMain = "div.css-175oi2r.r-5kkj8d.r-1ss6j8a.r-1qortcd.r-vmopo1:visible";
  17. const parentBlockCSSPostThreadOther1 = "div.css-175oi2r.r-5kkj8d.r-1hfyk0a:visible";
  18. const parentBlockCSSPostThreadOther2 = "div.css-175oi2r.r-1hfyk0a.r-13yce4e:visible";
  19.  
  20. const postUrlLinkCSS = "a.css-1rynq56.r-19gegkz.r-1loqt21:visible";
  21.  
  22. const postTextCSSFeed = "div.css-175oi2r.r-1awozwy.r-18u37iz.r-1w6e6rj.r-iphfwy > div:visible";
  23. const postTextCSSSearch = "div.css-175oi2r.r-1awozwy.r-18u37iz.r-1w6e6rj.r-xd6kpl > div:visible";
  24. const postTextCSSPostThreadMain = "div.css-175oi2r.r-1awozwy.r-18u37iz.r-1w6e6rj.r-2yi16.r-1qfoi16.r-1mi0q7o.r-mk0yit > div:visible";
  25. const postTextCSSPostThreadOther = "div.css-175oi2r.r-1awozwy.r-18u37iz.r-1w6e6rj.r-2yi16.r-xd6kpl.r-1qfoi16:visible";
  26.  
  27. const postDropdownPopupBGCSS = "div.css-175oi2r.r-kemksi.r-1p0dtai.r-1d2f490.r-5m1il8.r-u8s1d.r-zchlnj.r-ipm5af:visible";
  28. const deeplURL = "https://www.deepl.com/ja/translator#en/ja/";
  29.  
  30. (function() {
  31. 'use strict';
  32.  
  33. let clickedPost = null;
  34. let parentBlockCSS = null;
  35. let postTextCSS = null;
  36.  
  37. let postDropdownBtnObserver = new MutationObserver(function (MutationRecords, MutationObserver) {
  38. $("div[data-testid='postDropdownBtn']").each(function(i, elem) {
  39. let events = $._data($(elem).get(0), "events");
  40. if (events != null) {
  41. return true;
  42. }
  43. $(elem).on("click", function(){
  44. clickedPost = null;
  45. parentBlockCSS = null;
  46. postTextCSS = null;
  47. let isRP = false;
  48. if (0 < $(elem).closest(parentBlockCSSFeed).length) {
  49. parentBlockCSS = parentBlockCSSFeed;
  50. postTextCSS = postTextCSSFeed;
  51. } else if (0 < $(elem).closest(parentBlockCSSSearch).length) {
  52. parentBlockCSS = parentBlockCSSSearch;
  53. postTextCSS = postTextCSSSearch;
  54. } else if (0 < $(elem).closest(parentBlockCSSPostThreadMain).length) {
  55. parentBlockCSS = parentBlockCSSPostThreadMain;
  56. postTextCSS = postTextCSSPostThreadMain;
  57. isRP = true;
  58. } else if (0 < $(elem).closest(parentBlockCSSPostThreadOther1).length) {
  59. parentBlockCSS = parentBlockCSSPostThreadOther1;
  60. postTextCSS = postTextCSSPostThreadOther;
  61. } else if (0 < $(elem).closest(parentBlockCSSPostThreadOther2).length) {
  62. parentBlockCSS = parentBlockCSSPostThreadOther2;
  63. postTextCSS = postTextCSSPostThreadOther;
  64. }
  65. let parentBlock = $(elem).closest(parentBlockCSS);
  66. let href = parentBlock.find(postUrlLinkCSS).attr("href");
  67. clickedPost = href;
  68. if (isRP && clickedPost != null) {
  69. clickedPost = null;
  70. }
  71. });
  72. });
  73. });
  74. postDropdownBtnObserver.observe($("#root").get(0), {
  75. childList: true,
  76. subtree: true,
  77. });
  78.  
  79. let postDropdownTranslateBtnObserver = new MutationObserver(function (MutationRecords, MutationObserver) {
  80. $("div[data-testid='postDropdownTranslateBtn']").each(function(i, elem) {
  81. $(elem).off("click");
  82. $(elem).on("click", function(){
  83. let parentBlock = null;
  84. if (clickedPost == null) {
  85. parentBlock = $(parentBlockCSS);
  86. } else {
  87. parentBlock = $(`a[href='${clickedPost}']:visible`).closest(parentBlockCSS);
  88. }
  89. let text = parentBlock.find(postTextCSS).text();
  90. window.open(deeplURL + encodeURI(text).replaceAll("/", "%5C%2F"));
  91. $(postDropdownPopupBGCSS).click();
  92. return false;
  93. });
  94. });
  95. });
  96. postDropdownTranslateBtnObserver.observe($("#root").get(0), {
  97. childList: true,
  98. subtree: true,
  99. });
  100. })();

QingJ © 2025

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