Mastoshare Replacer

Replace Mastoshare Links to Your Instance Share Form.

  1. // ==UserScript==
  2. // @name Mastoshare Replacer
  3. // @namespace https://mizle.net/
  4. // @version 1.0.1
  5. // @description Replace Mastoshare Links to Your Instance Share Form.
  6. // @author Eai
  7. // @include *
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. "use strict";
  13. const instance = "mstdn.maud.io";
  14. const regex = /https:\/\/mastoshare\.net\/post\.php\?text=(.*)/g;
  15.  
  16. let mastoshareLinks = document.querySelectorAll("a[href^=\"https://mastoshare.net/post.php?text=\"]");
  17.  
  18. mastoshareLinks.forEach(function (link) {
  19. let tootText = regex.exec(link.href)[1];
  20. if (tootText == "") {
  21. link.href = `https://${instance}/share?text=${encodeURIComponent(document.title)} ${encodeURIComponent(document.location)}`;
  22. } else {
  23. link.href = `https://${instance}/share?text=${tootText}${encodeURIComponent(document.location)}`;
  24. }
  25. });
  26. })();