Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         TOUKON KOVA REDDITYLIS SKRIPTI
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       ANKKAMIES
  7. // @match        https://ylilauta.org/*
  8. // @run-at      document-idle
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     'use strict';
  14.  
  15.     function sortChildrenByScore(parent) {
  16.     var _posts = [];
  17.     $.each($(parent).children(".answer"), (key, value) => _posts.push(value));
  18.     _posts.sort((a, b) => {
  19.       var a_points = $(a).find(".backlink").length + $(a).find(".upvote_count").data("count");
  20.         var b_points = $(b).find(".backlink").length + $(b).find(".upvote_count").data("count");
  21.         if (a_points < b_points) return 1;
  22.         if (a_points > b_points) return -1;
  23.         return $(a).data("msgid") > $(b).data("msgid") ? 1 : -1;
  24.     }).forEach((ele) => {
  25.         if ($(ele).children(".answer").length > 0) {
  26.             sortChildrenByScore(ele);
  27.         }
  28.         $(ele).detach();
  29.         $(ele).appendTo($(parent));
  30.     });
  31. }
  32.  
  33. function reddifyAnswers(threadnumber) {
  34.     var _posts = [];
  35.     $.each($("#thread_" + threadnumber).find(".answer"), (key, value) => _posts.push(value));
  36.     _posts.forEach((ele) => {
  37.         $(ele).detach();
  38.         if ($(ele).find(".postcontent").find(".reflink").length > 0) {
  39.             $.each($(ele).find(".postcontent").find(".reflink"), (key, value) => {
  40.                 if ($(value).data("msgid") === threadnumber) {
  41.                     $(ele).appendTo($("#thread_" + threadnumber).find(".answers"));
  42.                 } else {
  43.                     $(ele).clone().css("margin-left", "20px").appendTo("#no" + $(value).data("msgid"));
  44.                 }
  45.             });
  46.         } else {
  47.             $(ele).appendTo($("#thread_" + threadnumber).find(".answers"));
  48.         }
  49.     });
  50. }
  51.  
  52. function removeRefs(threadnumber) {
  53.     $.each($("#thread_" + threadnumber).find(".reflink"), (key, value) => {
  54.         $(value).detach();
  55.     });
  56.  
  57.     $(".replies > span").detach();
  58. }
  59.  
  60. if ($('.style-replies').length > 0) {
  61.     $.each($(".op_post"), (key, value) => {
  62.         $('<button>Make reddit</button>').click(() => {
  63.             reddifyAnswers($(value).data("msgid"));
  64.             sortChildrenByScore($("#thread_" + $(value).data("msgid")).children(".answers"));
  65.             removeRefs($(value).data("msgid"));
  66.         }).appendTo($(value));
  67.     });
  68. }
  69. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement