Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Lemmy Sort by Top
- // @description Change default comment sorting behavior.
- // @match https://sh.itjust.works/*
- // @match https://burggit.moe/*
- // @match https://vlemmy.net/*
- // @match https://lemmy.world/*
- // @match https://lemm.ee/*
- // @version 0.1
- // @grant GM_xmlhttpRequest
- // @run-at document-start
- // ==/UserScript==
- const defaultSort = 'Top';
- function addScript(text) {
- text = text.replace(/commentSort:"Hot"/g, `commentSort:"${defaultSort}"`);
- var newScript = document.createElement('script');
- newScript.type = "text/javascript";
- newScript.textContent = text;
- var head = document.getElementsByTagName('head')[0];
- head.appendChild(newScript);
- }
- window.addEventListener('beforescriptexecute', function(e) {
- const src = e.target.src;
- if (src.endsWith('client.js')) {
- e.preventDefault();
- e.stopPropagation();
- console.log(src);
- GM_xmlhttpRequest({
- method: "GET",
- url: e.target.src,
- onload: function(response) {
- addScript(response.responseText);
- }
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement