Mastodon の長いトゥートを置換するやつ

長すぎてびっくりするトゥートを好きな文字に置換します。デフォルトでは https://mstdn.jp で動作しますが、@matchタグを追加して他のインスタンスで動作させることもできます。

Installer ce script?
Script suggéré par l'auteur

Vous pourriez également aimer Mastodon の閲覧注意を自動で表示するやつ.

Installer ce script
  1. // ==UserScript==
  2. // @name Mastodon の長いトゥートを置換するやつ
  3. // @name:ja Mastodon の長いトゥートを置換するやつ
  4. // @name:en Mastodon replace too long toot
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.11
  7. // @author Eskey Easy
  8. // @license MIT
  9. // @description 長すぎてびっくりするトゥートを好きな文字に置換します。デフォルトでは https://mstdn.jp で動作しますが、@matchタグを追加して他のインスタンスで動作させることもできます。
  10. // @description:ja 長すぎてびっくりするトゥートを好きな文字に置換します。デフォルトでは https://mstdn.jp で動作しますが、@matchタグを追加して他のインスタンスで動作させることもできます。
  11. // @description:en Replace too long toot on Mastodon web. By default this will work on https://mstdn.jp .
  12. // @match https://mstdn.jp/web/**
  13. // @icon https://www.google.com/s2/favicons?sz=64&domain=mstdn.jp
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. ////// SETTING START END ///////////////////////////////////////////////////
  21.  
  22. /**
  23. これより長いトゥートは REPLACED_HTML に置換される。リンクとハッシュタグは無視される。
  24. The toots that is longer than this number will be replaced into REPLACED_HTML.
  25. URLs and hashtags are not counted.
  26. */
  27. const TEXT_LENGTH_THRESHOLD = 200;
  28.  
  29. /**
  30. 置換テンプレート。"${textLen}"とすると文字数に置換される。
  31. The long toots will be replaced into this HTML. "${textLen}" represents the length of toot.
  32. example: `${length}文字` → "300文字"
  33. */
  34. const REPLACER = (original, length) => `<p>${original.substring(0, 20)}…(略)</p>`;
  35.  
  36. /**
  37. 更新間隔。ミリ秒
  38. Check interval(milliseconds)
  39. */
  40. const TOOT_CHECK_INTERVAL_MS = 60;
  41.  
  42. ////// SETTING END ///////////////////////////////////////////////////
  43.  
  44. replaceLoop(TEXT_LENGTH_THRESHOLD, TOOT_CHECK_INTERVAL_MS);
  45.  
  46. const selector = '#mastodon div.scrollable > div.item-list > article .status__content__text.status__content__text--visible:not([data-lengthCheck])';
  47. function replaceLoop(thresh, interval) {
  48. setInterval(function(){
  49. document.querySelectorAll(selector).forEach(e => {
  50. e.setAttribute('data-lengthCheck','1');
  51. const text = e.innerText.replace(/<a(?: .+?)?>.*?<\/a>/g, '');
  52. const textLen = text.length;
  53. if( textLen > thresh) {
  54. e.innerHTML = REPLACER(text, textLen);
  55. }
  56. })
  57. },interval);
  58. }
  59. })();