Advertisement
Guest User

Untitled

a guest
Jul 15th, 2023
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name             Lemmy Sort by Top
  3. // @description      Change default comment sorting behavior.
  4. // @match            https://sh.itjust.works/*
  5. // @match            https://burggit.moe/*
  6. // @match            https://vlemmy.net/*
  7. // @match            https://lemmy.world/*
  8. // @match            https://lemm.ee/*
  9. // @version          0.1
  10. // @grant            GM_xmlhttpRequest
  11. // @run-at           document-start
  12. // ==/UserScript==
  13.  
  14. const defaultSort = 'Top';
  15.  
  16. function addScript(text) {
  17.     text = text.replace(/commentSort:"Hot"/g, `commentSort:"${defaultSort}"`);
  18.     var newScript = document.createElement('script');
  19.     newScript.type = "text/javascript";
  20.     newScript.textContent = text;
  21.     var head = document.getElementsByTagName('head')[0];
  22.     head.appendChild(newScript);
  23. }
  24.  
  25. window.addEventListener('beforescriptexecute', function(e) {
  26.     const src = e.target.src;
  27.     if (src.endsWith('client.js')) {
  28.         e.preventDefault();
  29.         e.stopPropagation();
  30.         console.log(src);
  31.         GM_xmlhttpRequest({
  32.             method: "GET",
  33.             url: e.target.src,
  34.             onload: function(response) {
  35.                 addScript(response.responseText);
  36.             }
  37.         });
  38.     }
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement