Trim Old Reddit

Trimmer for Old Reddit

目前為 2020-08-12 提交的版本,檢視 最新版本

// ==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/*
// @match         *://www.reddit.com/*
// @grant         GM.xmlHttpRequest
// @version       1.2
// @run-at        document-start
// ==/UserScript==

(function() {
  let side = null;

  const SHOW_FIRST = false;

  function trim() {
    $('.infobar').remove();
    $('.footer-parent').remove();
    $('#sr-header-area').siblings().remove();
    let content = $('.content[role="main"]');
    $(`<style>
      #header {
        height: revert !important;
      }
      .link {
        margin-right: revert !important;
      }
      body div.content {
        margin: 5px !important;
      }
      .sitetable {
        border-bottom: 0 !important;
        border-left: 0 !important;
      }
      .listing-page #siteTable {
        margin-right: 0;
      }
      .side {
        background: url('') !important;
        background-color: transparent;
        box-shadow: revert;
        width:59%;
        margin:5px;
        height:1000px;
        overflow-y:auto;
        padding-top: 0;
      }
      .side:before {
        content: revert !important;
        background: revert !important;
      }
      .side:after {
        content: '';
      }
    </style>`).appendTo('head');
    content.css({
      width:'40%',
      height: '1000px',
      'overflow-y': 'auto',
      resize:'horizontal',
      margin: '0',
    });

    side = $('.side');
    side.empty();

    let w = $('<div id="body-wrapper" style="display:flex"></div>');
    $('#header').after(w);
    w.append(content);
    w.append(side);

    let curbg = null;
    $('.thing').hover(
      function(e) {
        let t = $(this);
        if (!t.hasClass('clicked')) {
          if (!curbg) curbg = t.css('background-color');
          t.css({'background-color':'#eeeeee'});
        }
      },
      function(e) {
        let t = $(this);
        if (!t.hasClass('clicked'))
          t.css({'background-color':curbg});
      }
    );
    let first = null;
    $('.entry a').add('.search-result a').add('a.title')
      .each(function(k,v) {
      let t = $(this).closest('.thing');
      if (t.length == 0)
          t = $(this).closest('.search-result');
      let a = $(this);
      let href = a.attr('href');
      if (href.indexOf('/comments/') != -1) {
        a.on('click', function(e) {
          e.preventDefault();
          e.stopPropagation();
          t.css({'background-color':'#eeeeff'});
          t.addClass('clicked');
          t.siblings().css({'background-color':curbg});
          t.siblings().removeClass('clicked');
          loadComment(href);
        });
        if (first === null)
          first = a;
      }
    });
    if (SHOW_FIRST && first)
      first.click();
  }

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

  setTimeout(function() {
    if (document.URL.indexOf('www.reddit.com') != -1) {
      $('#email-verification-tooltip-id').
        before($('<button title="Old Reddit" id="old-button" type="button">OLD</button>'));
      let old = $('#old-button');
      old.css({
        margin: '10px',
        border: 'solid 1px #0079d3',
        padding: '5px',
        'border-radius': '4px',
        color: '#0079d3',
        'font-weight': 'bold'
      });
      old.on('click', function() {
        top.location.hostname = 'old.reddit.com';
      });
      return;
    }

    if (document.URL.indexOf('/comments/') != -1)
      return;
    trim();
  }, 1000);

})();

QingJ © 2025

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