Trim Old Reddit

Trimmer for Old Reddit

目前為 2020-06-27 提交的版本,檢視 最新版本

// ==UserScript==
// @name           Trim Old Reddit
// @namespace      stgeorge
// @description    Trimmer for Old Reddit
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @match          *://old.reddit.com/*
// @grant          GM.xmlHttpRequest
// @version        0.2
// ==/UserScript==

(function() {
  let side = $('.side');

  function loadComment(u) {
    console.log('LINK', u);
    GM.xmlHttpRequest({
      method: "GET",
      url: u,
      onload: function(response) {
        side.html($.parseHTML(response.responseText));
        let c = side.find('.content[role="main"]').detach();
        side.empty();
        c.appendTo(side);
        c.css({margin:'10px'});
        side.find('.infobar').detach();
      }
    });
  }

  function trim() {
    let content = $('.content[role="main"]');
    content.css({
      width:'40%',
      height: '1000px',
      'overflow-y': 'auto',
      margin:'5px',
    });
    $('.infobar').remove();
    $('.footer-parent').remove();
    side.empty();
    side.css({
      width:'59%',
      margin:'5px',
      height: '1000px',
      'overflow-y': 'auto',
      'padding-top': 0,
    });
    content.wrap('<div id="body-wrapper" style="display:flex"></div>');
    side.appendTo('#body-wrapper');
    $('.thing').hover(
      function(e) {
        let t = $(this);
        if (!t.hasClass('clicked'))
          t.css({'background-color':'#eeeeee'});
      },
      function(e) {
        let t = $(this);
        if (!t.hasClass('clicked'))
          t.css({'background-color':'white'});
      }
    );
    $('.entry a').each(function(k,v) {
      var t = $(this).closest('.thing');
      $(this).on('click', function(e) {
        let href = $(this).attr('href');
        if (href.indexOf('/comments/') != -1) {
          t.css({'background-color':'#eeeeee'});
          t.addClass('clicked');
          t.siblings().css({'background-color':'white'});
          t.siblings().removeClass('clicked');
          e.preventDefault();
          e.stopPropagation();
          loadComment(href);
        }
      });
    });
  }
  if (document.URL.indexOf('/comments/') != -1)
    return;
  trim();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址